convert more
Getty Ritter
3 years ago
34 | 34 | |
35 | 35 | edit_design_list = load_template("edit_design_list") |
36 | 36 | edit_design = load_template("edit_design") |
37 | delete_design = load_template("delete_design") | |
38 | ||
39 | photo_upload = load_template("photo_upload") | |
40 | photo_list = load_template("photo_list") | |
41 | photo_tile = load_template("photo_tile") | |
42 | view_photo = load_template("view_photo") | |
43 | ||
44 | edit_pages = load_template("edit_pages") | |
45 | edit_page = load_template("edit_page") | |
37 | 46 | |
38 | 47 | |
39 | 48 | db = storage.DB() |
177 | 186 | "id_str": f"{design.id:05}", |
178 | 187 | }) |
179 | 188 | |
180 | # class delete_design: | |
181 | ||
182 | ||
183 | # @main | |
184 | # def GET(self, id): | |
185 | # try: | |
186 | # id = int(id) | |
187 | # except: | |
188 | # raise web.notfound() | |
189 | # design = db.get_design(id) | |
190 | # return ('Delete', | |
191 | # render.delete_design(*design)) | |
192 | ||
193 | ||
194 | # def POST(self, id): | |
195 | # try: | |
196 | # id = int(id) | |
197 | # except: | |
198 | # raise web.notfound() | |
199 | # db.delete_design(id) | |
200 | # raise web.redirect('/edit/design/') | |
201 | ||
202 | # class add_photo: | |
203 | ||
204 | ||
205 | # @main | |
206 | # def GET(self): | |
207 | # input = web.input() | |
208 | # if 'id' in input: | |
209 | # return ('Add Photo For Design {0}'.format(input.id), | |
210 | # render.photo_upload(input.id)) | |
211 | # else: | |
212 | # return ('Add Generic Photo', render.photo_upload(-1)) | |
213 | ||
189 | @app.route("/edit/delete/<id>/") | |
190 | @main | |
191 | def delete_design(id): | |
192 | id = int(id) | |
193 | design = db.get_design(id) | |
194 | return 'delete design', Templates.delete_design({ | |
195 | "title": design.title, | |
196 | "id_str": f"{design.id:05}", | |
197 | }) | |
198 | ||
199 | @app.route("/edit/delete/<id>/", methods=["POST"]) | |
200 | def do_delete_design(id): | |
201 | db.delete_design(int(id)) | |
202 | return flask.redirect(f"/edit/design/") | |
203 | ||
204 | @app.route("/edit/photo/") | |
205 | @main | |
206 | def add_photo(): | |
207 | if 'id' in flask.request.args: | |
208 | id = flask.request.args.get('id') | |
209 | return f"Add photo for design {id}", Templates.photo_upload({"id": id}) | |
210 | else: | |
211 | return "Add generic photo", Templates.photo_upload({"id": -1}) | |
212 | ||
213 | @app.route("/edit/photo/", methods=["POST"]) | |
214 | def do_add_photo(): | |
215 | pass | |
214 | 216 | |
215 | 217 | # def POST(self): |
216 | 218 | # input = web.input(file={}) |
225 | 227 | # else: |
226 | 228 | # raise web.redirect('/edit/design/{0:05}/'.format(id)) |
227 | 229 | |
228 | # class modify_photo: | |
229 | ||
230 | ||
231 | # @main | |
232 | # def GET(self, id): | |
233 | # design_id = web.input().design_id | |
234 | # return ('Delete Photo', | |
235 | # render.photo_delete(id, design_id)) | |
236 | ||
230 | @app.route("/edit/photo/<id>/") | |
231 | @main | |
232 | def modify_photo(id): | |
233 | design_id = flask.requests.args['design_id'] | |
234 | return 'Delete Photo', Templates.photo_delete(id, design_id) | |
235 | ||
236 | @app.route("/edit/photo/<id>/", methods=["POST"]) | |
237 | def do_modify_photo(): | |
238 | pass | |
237 | 239 | |
238 | 240 | # def POST(self, id): |
239 | 241 | # input = web.input() |
242 | 244 | # raise web.redirect('/edit/design/{0:05}/'.format( |
243 | 245 | # design_id)) |
244 | 246 | |
245 | # class view_all_photos: | |
246 | ||
247 | ||
248 | # @main | |
249 | # def GET(self): | |
250 | # winput = web.input(page=0) | |
251 | # page = int(winput['page']) | |
252 | # min, max = db.max_photo_page_ranges() | |
253 | # data = db.get_all_photos(offset=page) | |
254 | # return ('Photos', | |
255 | # render.photo_list((render.photo_tile(p) for p in data), | |
256 | # page, max, page > min, page < max)) | |
257 | ||
258 | # class view_photo: | |
259 | ||
260 | ||
261 | # @main | |
262 | # def GET(self, id): | |
263 | # photo = db.get_photo_by_id(id) | |
264 | # if photo: | |
265 | # return ('Viewing Photo {0}'.format(id), | |
266 | # render.view_photo(id, photo)) | |
267 | # else: | |
268 | # raise web.notfound() | |
269 | ||
270 | # class edit_page_list: | |
271 | ||
272 | ||
273 | # @main | |
274 | # def GET(self): | |
275 | # return ('Edit Page List', | |
276 | # render.edit_pages(db.get_page_list())) | |
277 | ||
278 | # class edit_page: | |
279 | ||
280 | ||
281 | # @main | |
282 | # def GET(self, name): | |
283 | # return ( | |
284 | # 'Edit Page {0}'.format(name), | |
285 | # render.edit_page(name, db.get_page(name))) | |
286 | ||
247 | @app.route("/edit/view-photo/") | |
248 | @main | |
249 | def view_all_photos(): | |
250 | page = int(flask.request.args.get('page', 0)) | |
251 | p_min, p_max = db.max_photo_page_ranges() | |
252 | data = db.get_all_photos(offset=page) | |
253 | return 'Photos', Templates.photo_list({ | |
254 | 'photos': ( | |
255 | {"photo": Templates.photo_tile(p)} for p in data), | |
256 | 'page': page, | |
257 | 'show_left': page > p_min, | |
258 | 'show_right': page < p_max, | |
259 | }) | |
260 | ||
261 | @app.route("/edit/view-photo/<id>/") | |
262 | @main | |
263 | def view_photo(id): | |
264 | photo = db.get_photo_by_filename(id) | |
265 | if photo: | |
266 | return f"Viewing photo {id}", Templates.view_photo(photo) | |
267 | else: | |
268 | raise Exception(f"Unable to find photo {id}") | |
269 | ||
270 | @app.route("/edit/pages/") | |
271 | @main | |
272 | def edit_page_list(): | |
273 | return 'Edit Page List', Templates.edit_pages({ | |
274 | "pages": db.get_page_list(), | |
275 | }) | |
276 | ||
277 | @app.route("/edit/pages/<slug>/") | |
278 | @main | |
279 | def edit_page(slug): | |
280 | page = db.get_page(slug) | |
281 | return f"Edit Page {slug}", Templates.edit_page({ | |
282 | "name": slug, | |
283 | "title": page.title, | |
284 | "text": page.text, | |
285 | }) | |
286 | ||
287 | ||
288 | @app.route("/edit/pages/<slug>/", methods=["POST"]) | |
289 | def do_edit_page(slug): | |
290 | text = flask.request.form.get('text', '') | |
291 | title = flask.request.form.get('title', slug.capitalize()) | |
292 | db.set_page(slug, title, text) | |
293 | return flask.redirect(f'/edit/pages/{slug}') | |
287 | 294 | |
288 | 295 | # def POST(self, name): |
289 | 296 | # input = web.input() |
6 | 6 | "author": "Getty Ritter <gettylefou@gmail.com>", |
7 | 7 | "license": "MIT", |
8 | 8 | "dependencies": { |
9 | "cash-dom": "^8.1.0", | |
9 | 10 | "easymde": "^2.12.1", |
10 | 11 | "megamark": "^3.3.0", |
11 | 12 | "tagify": "^0.1.1", |
259 | 259 | |
260 | 260 | .editarea { |
261 | 261 | border: 1px solid black; |
262 | padding: 1em; | |
262 | 263 | } |
263 | 264 | |
264 | 265 | #editor { |
265 | 266 | width: 90%; |
266 | 267 | display: none; |
267 | 268 | } |
269 | ||
270 | .edittiles { | |
271 | display: flex; | |
272 | flex-direction: row; | |
273 | } | |
274 | ||
275 | .edittile label { | |
276 | font-family: sacramento, sans-serif; | |
277 | font-size: 18pt; | |
278 | } | |
279 | ||
280 | .edittile { | |
281 | border: 1px solid black; | |
282 | padding: 1em; | |
283 | margin: 1em; | |
284 | } | |
285 | ||
286 | .taglist { | |
287 | flex-grow: 2; | |
288 | } | |
289 | ||
290 | label ~ div { | |
291 | padding-left: 2em; | |
292 | } |
223 | 223 | except: |
224 | 224 | return None |
225 | 225 | |
226 | def get_photo_by_filename(self, filename): | |
227 | try: | |
228 | return Image(self._db.where("photos", filename=filename)[0].filename) | |
229 | except: | |
230 | return None | |
231 | ||
226 | 232 | def get_picture(self, id): |
227 | 233 | try: |
228 | 234 | return Image((self._db.where("photos", design_id=id, limit=1))[0].filename) |
233 | 239 | if not pp: |
234 | 240 | pp = self.per_page |
235 | 241 | return [ |
236 |
Image(l |
|
242 | Image(l.filename) | |
237 | 243 | for l in self._db.select( |
238 | 244 | "photos", offset=offset * pp, limit=pp, order="id DESC" |
239 | 245 | ) |
409 | 415 | self._db.update("pages", where="name = 'about'", text=text) |
410 | 416 | |
411 | 417 | def get_page_list(self): |
412 |
return |
|
418 | return list(self._db.query("select * from pages")) | |
413 | 419 | |
414 | 420 | def add_page(self, name, title): |
415 | 421 | self._db.insert("pages", name=name, title=title, text="") |
1 | <div class="textbox"> | |
2 | Do you <strong>really</strong> want to delete the design "{{title}}"? Remember: | |
3 | if you delete this design, <strong>you will not be able to retrieve | |
4 | the text saved here</strong> unless your son was nice enough to | |
5 | make a backup recently! | |
6 | <a href="/edit/design/{{id_str}}/">No</a> | |
7 | <form name="delete" action="/edit/delete/{{id_str}}/" method="post"> | |
8 | <input type="submit" value="Yes" /> | |
9 | </form> | |
10 | </div> |
3 | 3 | <div class="editarea"> |
4 | 4 | <textarea id="editor" rows="8" cols="90"></textarea> |
5 | 5 | </div> |
6 | <select name="category"> | |
7 | {{#categories}} | |
8 | <option value="{{id}}" ${{selected}}>{{name}}</option> | |
9 | {{/categories}} | |
10 |
< |
|
6 | <div class="edittiles"> | |
7 | <div class="edittile"> | |
8 | <label>Category</label><br> | |
9 | <div> | |
10 | <select name="category"> | |
11 | {{#categories}} | |
12 | <option value="{{id}}" ${{selected}}>{{name}}</option> | |
13 | {{/categories}} | |
14 | </select> | |
15 | </div> | |
16 | </div> | |
17 | <div class="edittile taglist"> | |
18 | <label>Tags</label><br> | |
19 | <div class="tags"> | |
20 | <input type="text" name="tags"/> | |
21 | </div> | |
22 | </div> | |
23 | <div class="edittile"> | |
24 | <label>Delete</label><br> | |
25 | <div> | |
26 | <a href="/edit/delete/{{id_str}}/">Delete This Design</a> | |
27 | </div> | |
28 | </div> | |
29 | </div> | |
11 | 30 | <!-- |
12 | 31 | <div id="design"> |
13 | 32 | <p> |
1 | <form name="edit-form" method="post" action="/edit/pages/{{name}}/"> | |
2 | Title: <input name="title" type="text" value="{{title}}"/><br/> | |
3 | <textarea name="text" rows="25" cols="65">{{text}}</textarea><br/> | |
4 | <input type="submit" value="Change {{title}} Text" /> | |
5 | </form> |
1 | The following pages currently exist: | |
2 | <ul> | |
3 | {{#pages}} | |
4 | <li><a href="/edit/pages/{{name}}/">{{title}}</a></li> | |
5 | {{/pages}} | |
6 | </ul> |
1 | <ul class="all-designs"> | |
2 | {{#photos}} | |
3 | {{{photo}}} | |
4 | {{/photos}} | |
5 | <li class="break"></li> | |
6 | </ul> | |
7 | {{#page}} | |
8 | <div class="lrnav"><ul> | |
9 | <a href="/edit/view-photo/?page=0"><li class="navitem">Newest</li></a> | |
10 | {{#show_left}} | |
11 | <a href="/edit/view-photo/?page=$(page - 1)"><li class="navitem">Newer</li></a> | |
12 | {{/show_left}} | |
13 | {{^show_left}} | |
14 | <li class="navitem greyed">Newer</li> | |
15 | {{/show_left}} | |
16 | ||
17 | {{#show_right}} | |
18 | <a href="/edit/view-photo/?page=$(page + 1)"><li class="navitem">Older</li></a> | |
19 | {{/show_right}} | |
20 | {{#show_right}} | |
21 | <li class="navitem greyed">Older</li> | |
22 | {{/show_right}} | |
23 | <a href="/edit/view-photo/?page=$last_page"><li class="navitem">Oldest</li></a> | |
24 | <li class="break"></li> | |
25 | </ul></div> | |
26 | {{/page}} |
1 | <a href="/edit/view-photo/{{image}}/"> | |
2 | <li class="design-tile"> | |
3 | <img src="/static/photos/{{thumb}}" alt="{{image}} photo" /><br/> | |
4 | Photo {{image}} | |
5 | </li> | |
6 | </a> |
1 | <form name="photo-form" enctype="multipart/form-data" method="post" action="/edit/photo/"> | |
2 | <input type="hidden" name="id" value="{{id}}" /> | |
3 | <input type="file" name="file" /> | |
4 | <input type="submit" value="Upload Photo" /> | |
5 | </form> |
1 | <p> | |
2 | <img src="/static/photos/{{image}}"/> | |
3 | <input readonly="true" value="/static/photos/{{image}}" /> | |
4 | </p> |
1365 | 1365 | resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001052.tgz#33a5ddd13783cfe2c8a6a846ab983387d4edff75" |
1366 | 1366 | integrity sha512-b2/oWZwkpWzEB1+Azr2Z4FcpdDkH+9R4dn+bkwk/6eH9mRSrnZjhA6v32+zsV+TSqC0pp2Rxush2yUVTJ0dJTQ== |
1367 | 1367 | |
1368 | cash-dom@^8.1.0: | |
1369 | version "8.1.0" | |
1370 | resolved "https://registry.yarnpkg.com/cash-dom/-/cash-dom-8.1.0.tgz#ed8e278231c071b6596618131bd4320c57d32a31" | |
1371 | integrity sha512-QTa50rFuPaX8klEDEbwLr+jVutwpvZEBQ0NpMMyng+je7gNe9Bz/JsOLHIG24tvNSSSIN/Q1QD0bnF6PQzWKHA== | |
1372 | ||
1368 | 1373 | chalk@2.4.2, chalk@^2.0.0: |
1369 | 1374 | version "2.4.2" |
1370 | 1375 | resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" |