gdritter repos frony-ritter-designs / 0dd132a
Use Peewee for photos Getty Ritter 3 years ago
5 changed file(s) with 27 addition(s) and 20 deletion(s). Collapse all Expand all
159159
160160 @app.route("/edit/design/", methods=["POST"])
161161 def post_new_design():
162 # id = db.new_design()
163162 id = model.Design.make_new()
164163 return flask.redirect(f"/edit/design/{id:05}/")
165164
192191 @main
193192 def delete_design(id):
194193 id = int(id)
195 design = model.Design.get(id=id)
194 design = model.Design.get(visible_id=id)
196195 return (
197196 "delete design",
198 Templates.delete_design({"title": design.title, "id_str": f"{design.id:05}",}),
197 Templates.delete_design({"title": design.title, "id_str": f"{design.visible_id:05}",}),
199198 )
200199
201200
202201 @app.route("/edit/delete/<id>/", methods=["POST"])
203202 def do_delete_design(id):
204 db.delete_design(int(id))
203 model.Design.get(visible_id=id).delete_instance()
205204 return flask.redirect(f"/edit/design/")
206205
207206
245244 @app.route("/edit/view-photo/")
246245 @main
247246 def view_all_photos():
248 page = int(flask.request.args.get("page", 0))
249 p_min, p_max = db.max_photo_page_ranges()
250 data = db.get_all_photos(offset=page)
247 page = int(flask.request.args.get("page", 1))
248 photos, p_min, p_max = model.Photo.get_all(page=page)
251249 return (
252250 "Photos",
253251 Templates.photo_list(
254252 {
255 "photos": ({"photo": Templates.photo_tile(p)} for p in data),
253 "photos": ({"photo": Templates.photo_tile(p)} for p in photos),
256254 "page": page,
255 "prev_page": page - 1,
256 "next_page": page + 1,
257257 "show_left": page > p_min,
258258 "show_right": page < p_max,
259 "last_page": p_max,
259260 }
260261 ),
261262 )
264265 @app.route("/edit/view-photo/<id>/")
265266 @main
266267 def view_photo(id):
267 photo = db.get_photo_by_id(id)
268 photo = model.Photo.get(filename=id)
268269 if photo:
269270 return f"Viewing photo {id}", Templates.view_photo(photo)
270271 else:
8484 return new_visible_id
8585
8686 @classmethod
87 def get_all(klass, page=0):
87 def get_all(klass, page=1):
8888 designs = klass.select().paginate(page, PER_PAGE)
8989 return Paginated.paginate(page, klass.select().count(), designs,)
9090
106106
107107 def thumb(self):
108108 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
109115
110116
111117 class Page(Model):
66 </ul>
77 {{#page}}
88 <div class="lrnav"><ul>
9 <a href="/edit/view-photo/?page=0"><li class="navitem">Newest</li></a>
9 <a href="/edit/view-photo/?page=1"><li class="navitem">Newest</li></a>
1010 {{#show_left}}
11 <a href="/edit/view-photo/?page=$(page - 1)"><li class="navitem">Newer</li></a>
11 <a href="/edit/view-photo/?page={{prev_page}}"><li class="navitem">Newer</li></a>
1212 {{/show_left}}
1313 {{^show_left}}
1414 <li class="navitem greyed">Newer</li>
1515 {{/show_left}}
1616
1717 {{#show_right}}
18 <a href="/edit/view-photo/?page=$(page + 1)"><li class="navitem">Older</li></a>
18 <a href="/edit/view-photo/?page={{next_page}}"><li class="navitem">Older</li></a>
1919 {{/show_right}}
20 {{#show_right}}
20 {{^show_right}}
2121 <li class="navitem greyed">Older</li>
2222 {{/show_right}}
23 <a href="/edit/view-photo/?page=$last_page"><li class="navitem">Oldest</li></a>
23 <a href="/edit/view-photo/?page={{last_page}}"><li class="navitem">Oldest</li></a>
2424 <li class="break"></li>
2525 </ul></div>
2626 {{/page}}
1 <a href="/edit/view-photo/{{image}}/">
1 <a href="/edit/view-photo/{{filename}}/">
22 <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}}
55 </li>
66 </a>
11 <p>
2 <img src="/static/photos/{{image}}"/>
3 <input readonly="true" value="/static/photos/{{image}}" />
2 <img src="/static/photos/{{filename}}"/>
3 <input readonly="true" value="/static/photos/{{filename}}" />
44 </p>