Use Peewee for photos
Getty Ritter
3 years ago
159 | 159 | |
160 | 160 | @app.route("/edit/design/", methods=["POST"]) |
161 | 161 | def post_new_design(): |
162 | # id = db.new_design() | |
163 | 162 | id = model.Design.make_new() |
164 | 163 | return flask.redirect(f"/edit/design/{id:05}/") |
165 | 164 | |
192 | 191 | @main |
193 | 192 | def delete_design(id): |
194 | 193 | id = int(id) |
195 |
design = model.Design.get( |
|
194 | design = model.Design.get(visible_id=id) | |
196 | 195 | return ( |
197 | 196 | "delete design", |
198 |
Templates.delete_design({"title": design.title, "id_str": f"{design. |
|
197 | Templates.delete_design({"title": design.title, "id_str": f"{design.visible_id:05}",}), | |
199 | 198 | ) |
200 | 199 | |
201 | 200 | |
202 | 201 | @app.route("/edit/delete/<id>/", methods=["POST"]) |
203 | 202 | def do_delete_design(id): |
204 |
|
|
203 | model.Design.get(visible_id=id).delete_instance() | |
205 | 204 | return flask.redirect(f"/edit/design/") |
206 | 205 | |
207 | 206 | |
245 | 244 | @app.route("/edit/view-photo/") |
246 | 245 | @main |
247 | 246 | def view_all_photos(): |
248 | page = int(flask.request.args.get("page", 0)) | |
249 | p_min, p_max = db.max_photo_page_ranges() | |
250 |
|
|
247 | page = int(flask.request.args.get("page", 1)) | |
248 | photos, p_min, p_max = model.Photo.get_all(page=page) | |
251 | 249 | return ( |
252 | 250 | "Photos", |
253 | 251 | Templates.photo_list( |
254 | 252 | { |
255 |
"photos": ({"photo": Templates.photo_tile(p)} for p in |
|
253 | "photos": ({"photo": Templates.photo_tile(p)} for p in photos), | |
256 | 254 | "page": page, |
255 | "prev_page": page - 1, | |
256 | "next_page": page + 1, | |
257 | 257 | "show_left": page > p_min, |
258 | 258 | "show_right": page < p_max, |
259 | "last_page": p_max, | |
259 | 260 | } |
260 | 261 | ), |
261 | 262 | ) |
264 | 265 | @app.route("/edit/view-photo/<id>/") |
265 | 266 | @main |
266 | 267 | def view_photo(id): |
267 |
photo = |
|
268 | photo = model.Photo.get(filename=id) | |
268 | 269 | if photo: |
269 | 270 | return f"Viewing photo {id}", Templates.view_photo(photo) |
270 | 271 | else: |
84 | 84 | return new_visible_id |
85 | 85 | |
86 | 86 | @classmethod |
87 |
def get_all(klass, page= |
|
87 | def get_all(klass, page=1): | |
88 | 88 | designs = klass.select().paginate(page, PER_PAGE) |
89 | 89 | return Paginated.paginate(page, klass.select().count(), designs,) |
90 | 90 | |
106 | 106 | |
107 | 107 | def thumb(self): |
108 | 108 | return self.filename[:-4] + "_thumb" + self.filename[-4:] |
109 | ||
110 | @classmethod | |
111 | def get_all(klass, page=1): | |
112 | size = klass.select().count() | |
113 | photos = klass.select().paginate(page, PER_PAGE).order_by(klass.filename.desc()) | |
114 | return photos, 1, (size // PER_PAGE) + 1 | |
109 | 115 | |
110 | 116 | |
111 | 117 | class Page(Model): |
6 | 6 | </ul> |
7 | 7 | {{#page}} |
8 | 8 | <div class="lrnav"><ul> |
9 |
<a href="/edit/view-photo/?page= |
|
9 | <a href="/edit/view-photo/?page=1"><li class="navitem">Newest</li></a> | |
10 | 10 | {{#show_left}} |
11 |
<a href="/edit/view-photo/?page= |
|
11 | <a href="/edit/view-photo/?page={{prev_page}}"><li class="navitem">Newer</li></a> | |
12 | 12 | {{/show_left}} |
13 | 13 | {{^show_left}} |
14 | 14 | <li class="navitem greyed">Newer</li> |
15 | 15 | {{/show_left}} |
16 | 16 | |
17 | 17 | {{#show_right}} |
18 |
<a href="/edit/view-photo/?page= |
|
18 | <a href="/edit/view-photo/?page={{next_page}}"><li class="navitem">Older</li></a> | |
19 | 19 | {{/show_right}} |
20 |
{{ |
|
20 | {{^show_right}} | |
21 | 21 | <li class="navitem greyed">Older</li> |
22 | 22 | {{/show_right}} |
23 |
<a href="/edit/view-photo/?page= |
|
23 | <a href="/edit/view-photo/?page={{last_page}}"><li class="navitem">Oldest</li></a> | |
24 | 24 | <li class="break"></li> |
25 | 25 | </ul></div> |
26 | 26 | {{/page}} |
1 |
<a href="/edit/view-photo/{{ |
|
1 | <a href="/edit/view-photo/{{filename}}/"> | |
2 | 2 | <li class="design-tile"> |
3 | <img src="/static/photos/{{thumb}}" alt="{{image}} photo" /><br/> | |
4 | Photo {{image}} | |
3 | <img src="/static/photos/{{thumb}}" alt="{{filename}} photo" /><br/> | |
4 | Photo {{filename}} | |
5 | 5 | </li> |
6 | 6 | </a> |