Swap out get_all as well
Getty Ritter
4 years ago
113 | 113 | @main |
114 | 114 | def get_all_designs(): |
115 | 115 | 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 |
|
|
116 | data = db.get_all(page) | |
117 | return ('Designs', Templates.design_list(data)) | |
125 | 118 | |
126 | 119 | |
127 | 120 | @app.route('/category/') |
137 | 130 | page = int(flask.request.args.get('page') or 0) |
138 | 131 | data = db.get_designs_by_category(cat, page) |
139 | 132 | 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))) | |
149 | 133 | |
150 | 134 | |
151 | 135 | @app.route('/category/<cat>/tag/<tag>/') |
195 | 195 | return list(Image(d.filename) for d in self._db.where('photos', |
196 | 196 | design_id=id)) |
197 | 197 | |
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)) | |
210 | 210 | |
211 | 211 | def get_designs_by_category(self, cat, offset=0): |
212 | 212 | ds = self._db.query( |