gdritter repos frony-ritter-designs / 4a74d39
Start fixing tags Getty Ritter 4 years ago
2 changed file(s) with 14 addition(s) and 9 deletion(s). Collapse all Expand all
163163 @app.route('/tag/')
164164 @main
165165 def get_all_tags():
166 def pretty(t):
167 return ' '.join(w.capitalize()
168 for w in t.split('_'))
169166 tags = (
170 (t, pretty(t), db.num_for_tag(t))
167 (t.tag, t.pretty(), t.count)
171168 for t in sorted(db.get_all_tags()))
172169 return 'All Tags', render.select_tag(tags)
173170
5555 if self.images:
5656 return self.images[0].thumb()
5757
58 class Tag(typing.NamedTuple):
59 tag: str
60 count: int
61
62 def pretty(self):
63 return ' '.join(w.capitalize() for w in self.tag.split())
5864
5965 THUMB_SIZE = (100, 100)
6066
279285 return (0, 1 + (num_designs // self.per_page))
280286
281287 def get_all_tags(self):
282 all_tags = [
283 t.tag_name for t in
284 self._db.query(
285 'select distinct tag_name from tags')]
286 return all_tags
288 return [
289 Tag(t.tag_name, t.n) for t in
290 self._db.query('select t.tag_name, count(*) as n '
291 'from designs d, tags t '
292 'where d.id = t.design_id '
293 'group by t.tag_name')
294 ]
287295
288296 def get_designs_by_tag(self, tag, offset=0):
289297 ds = self._db.query(