gdritter repos frony-ritter-designs / 5593814
Switch tags to use new-style templates Getty Ritter 4 years ago
2 changed file(s) with 16 addition(s) and 31 deletion(s). Collapse all Expand all
158158 @app.route("/tag/<tag>/")
159159 @main
160160 def get_tag(tag):
161 pg_num = int(flask.request.args.get("page") or 0)
162 data = db.get_designs_by_tag(tag, pg_num)
163 pg_min, pg_max = db.max_page_range_for_tag(tag)
161 page = int(flask.request.args.get("page") or 0)
162 data = db.get_designs_by_tag(tag, page)
164163 pretty_tag = " ".join(w.capitalize() for w in tag.split("_"))
165 return (
166 pretty_tag,
167 render.by_tag_list(
168 tag,
169 (
170 render.design_tile(name, pics, 0, id)
171 for name, pics, desc, cat, id in data
172 ),
173 pg_num,
174 pg_num > pg_min,
175 pg_num < pg_max,
176 ),
177 )
164 return (pretty_tag, Templates.design_list(data))
178165
179166
180167 @app.route("/<name>/")
336336
337337 def get_designs_by_tag(self, tag, offset=0):
338338 ds = self._db.query(
339 """select * from designs, tags
340 where tags.tag_name = $tag
341 and designs.id = tags.design_id
342 order by designs.id desc
339 """select d.title, d.description, d.id, c.name as cat_name,
340 (select filename from photos where photos.design_id = d.id limit 1) as image
341 from designs d, tags t, categories c
342 where t.tag_name = $tag
343 and d.id = t.design_id
344 and d.category = c.id
345 order by d.id desc
343346 limit $per_page offset $offset""",
344347 vars=dict(tag=tag, offset=offset * self.per_page, per_page=self.per_page),
345348 )
346
347 return (
348 (
349 d.title,
350 self.get_picture(d.design_id),
351 d.description,
352 self.get_category_name(d.category),
353 d.design_id,
354 )
355 for d in ds
356 )
349 total = self._db.query(
350 """select count(*) as c from designs d, tags t
351 where t.tag_name = $tag and d.id = t.design_id""",
352 vars={"tag": tag},
353 )
354 return Paginated.paginate(offset, total[0].c, Design.list(ds))
357355
358356 def get_tags_for_design(self, design_id):
359357 return [