gdritter repos frony-ritter-designs / 6da9066
Swap out get_all as well Getty Ritter 4 years ago
2 changed file(s) with 14 addition(s) and 30 deletion(s). Collapse all Expand all
113113 @main
114114 def get_all_designs():
115115 page = int(flask.request.args.get('page') or 0)
116 min, max = db.max_page_ranges()
117 data = db.get_all(offset=page)
118 return ('Designs',
119 render.design_list(
120 (Templates.design_tile(d) for d in data),
121 page,
122 max,
123 page > min,
124 page < max))
116 data = db.get_all(page)
117 return ('Designs', Templates.design_list(data))
125118
126119
127120 @app.route('/category/')
137130 page = int(flask.request.args.get('page') or 0)
138131 data = db.get_designs_by_category(cat, page)
139132 return (cat.capitalize(), Templates.design_list(data))
140 # min, max = db.max_page_range_for_category(cat)
141 # return (cat.capitalize(),
142 # render.by_category_list(
143 # cat,
144 # (render.design_tile(name, pics, 0, id)
145 # for name, pics, desc, cat, id in data),
146 # page,
147 # page > min,
148 # page < (max - 1)))
149133
150134
151135 @app.route('/category/<cat>/tag/<tag>/')
195195 return list(Image(d.filename) for d in self._db.where('photos',
196196 design_id=id))
197197
198 def get_all(self, offset=0, pp=None):
199 if not pp:
200 pp = self.per_page
201 ds = list(self._db.select('designs',
202 offset=offset * self.per_page,
203 limit=pp,
204 order='id DESC'))
205 return (Design(title=d.title,
206 images=[self.get_picture(d.id)],
207 description=PageContent(d.description),
208 category=self.get_category_name(d.category),
209 id=d.id) for d in ds)
198 def get_all(self, offset=0):
199 ds = self._db.query(
200 '''select d.title, d.description, d.id, c.name as cat_name,
201 (select filename from photos where photos.design_id = d.id limit 1) as image
202 from designs d, categories c
203 where d.category = c.id
204 order by d.id desc
205 limit $per_page offset $offset''',
206 vars={"per_page": PER_PAGE, "offset": offset},
207 )
208 total = self._db.query('select count(*) as c from designs')
209 return Paginated.paginate(offset, total[0].c, Design.list(ds))
210210
211211 def get_designs_by_category(self, cat, offset=0):
212212 ds = self._db.query(