gdritter repos frony-ritter-designs / bdf5edc
Fix handling of templates and implement by-cat-and-tag Getty Ritter 4 years ago
5 changed file(s) with 39 addition(s) and 14 deletion(s). Collapse all Expand all
1 #!/usr/bin/python2
1 #!/usr/bin/env python
22
33 import flask
44 import markdown
1616 '''
1717 Local module to contain mustache templates
1818 '''
19 renderer = pystache.Renderer()
19 renderer = pystache.Renderer(search_dirs='templates')
2020
2121 def load_template(name):
2222 with open(f"templates/{name}.mustache") as f:
2626 main = load_template('main')
2727 design_page = load_template('design_page')
2828 design_tile = load_template('design_tile')
29 design_list = load_template('design_list')
2930
3031
3132 def slugify(string):
148149 def get_category_with_tag(cat, tag):
149150 page = int(flask.request.args.get('page') or 0)
150151 data = db.get_designs_by_category_and_tag(cat, tag, page)
151 min, max = db.max_page_range_for_category(cat)
152 return (cat.capitalize(),
153 render.by_category_list(
154 cat,
155 (render.design_tile(name, pics, 0, id)
156 for name, pics, desc, cat, id in data),
157 page,
158 page > min,
159 page < (max - 1)))
152
153 rs = Templates.design_list(data)
154 print(rs)
155 return (cat.capitalize(), rs)
160156
161157
162158 @app.route('/tag/')
3838 else:
3939 return self.source[:256] + '...'
4040
41
4142 class PageRef(typing.NamedTuple):
4243 page: int
4344
45
4446 class Rendered(typing.NamedTuple):
4547 rendered: str
48
4649
4750 class Design(typing.NamedTuple):
4851 title: str
6164 if self.images:
6265 return self.images[0].thumb()
6366
67
6468 class Paginated(typing.NamedTuple):
6569 next_page: typing.Optional[PageRef]
6670 prev_page: typing.Optional[PageRef]
6771 last_page: int
6872 contents: typing.List[Design]
6973
74
7075 class Tag(typing.NamedTuple):
7176 tag: str
7277 count: int
7378
7479 def pretty(self):
7580 return ' '.join(w.capitalize() for w in self.tag.split())
81
7682
7783 THUMB_SIZE = (100, 100)
7884
215221 offset=offset * self.per_page,
216222 per_page=self.per_page))
217223
218 last_page=0
224 last_page = 10
219225 return Paginated(
220226 next_page=None,
221227 prev_page=None,
1 <div class="all-designs">
2 {{#contents}}
3 {{>design_tile}}
4 {{/contents}}
5 </div>
6 <div class="lrnav"><ul>
7 <a href="?page=0"><li class="navitem">Newest</li></a>
8 {{#prev_page}}
9 <a href="?page={{page}}"><li class="navitem">Newer</li></a>
10 {{/prev_page}}
11 {{^prev_page}}
12 <li class="navitem greyed">Newer</li>
13 {{/prev_page}}
14
15 {{#next_page}}
16 <a href="?page={{page}}"><li class="navitem">Older</li></a>
17 {{/next_page}}
18 {{^next_page}}
19 <li class="navitem greyed">Older</li>
20 {{/next_page}}
21 <a href="?page={{last_page}}"><li class="navitem">Oldest</li></a>
22 <li class="break"></li>
23 </ul></div>
11 <a href="/design/{{id_str}}/{{slug}}/">
22 <li class="design-tile">
33 <div id="img">
4 <img src="/static/photos/{{thumbnail}}" alt="$title photo" />
4 <img src="/static/photos/{{thumbnail}}" alt="{{title}} photo" />
55 </div>
66 <span class="title">{{title}}</span>
77 </li>
1414 <meta http-equiv="Content-Type" contents="application/xhtml+xml; charset=utf-8;" />
1515 <meta name="description" content="Cross-Stitch Patterns and Other Crafts from Frony Ritter Designs" />
1616 <link rel="stylesheet" type="text/css" href="/static/standard.css" />
17 <title>Frony Ritter Designs &ndash; $title</title>
17 <title>Frony Ritter Designs &ndash; {{title}}</title>
1818 </head>
1919 <body>
2020 <div id="page">