| 76 | 76 |
def get_design(id, _slug=None):
|
| 77 | 77 |
design = model.Design.get(visible_id=id)
|
| 78 | 78 |
return "Designs", Templates.design_page(design)
|
| 79 |
|
| 79 | 80 |
|
| 80 | 81 |
@app.route("/api/design/<int:id>/")
|
| 81 | 82 |
def api_get_design(id: int):
|
|
| 163 | 164 |
page = int(flask.request.args.get("page") or 0)
|
| 164 | 165 |
min, max = db.max_page_ranges()
|
| 165 | 166 |
data = db.get_all(offset=page)
|
| 166 | |
return 'Edit Mode', Templates.edit_design_list(data)
|
| 167 |
return "Edit Mode", Templates.edit_design_list(data)
|
| 168 |
|
| 167 | 169 |
|
| 168 | 170 |
@app.route("/edit/design", methods=["POST"])
|
| 169 | 171 |
def post_new_design():
|
| 170 | 172 |
id = db.new_design()
|
| 171 | 173 |
return flask.redirect(f"/edit/design/{id:05}/")
|
| 172 | 174 |
|
| 175 |
|
| 173 | 176 |
@app.route("/edit/design/<id>/")
|
| 174 | 177 |
@main
|
| 175 | 178 |
def edit_design(id):
|
| 176 | 179 |
id = int(id)
|
| 177 | 180 |
design = db.get_design(id)
|
| 178 | |
return 'design', Templates.edit_design({
|
| 179 | |
"id": design.id,
|
| 180 | |
"title": design.title,
|
| 181 | |
"tags": ' '.join(design.tags(db)),
|
| 182 | |
"categories": design.category_list(db),
|
| 183 | |
"description": design.description.source,
|
| 184 | |
"photos": design.images,
|
| 185 | |
"id_str": f"{design.id:05}",
|
| 186 | |
})
|
| 181 |
return (
|
| 182 |
"design",
|
| 183 |
Templates.edit_design(
|
| 184 |
{
|
| 185 |
"id": design.id,
|
| 186 |
"title": design.title,
|
| 187 |
"tags": " ".join(design.tags(db)),
|
| 188 |
"categories": design.category_list(db),
|
| 189 |
"description": design.description.source,
|
| 190 |
"photos": design.images,
|
| 191 |
"id_str": f"{design.id:05}",
|
| 192 |
}
|
| 193 |
),
|
| 194 |
)
|
| 195 |
|
| 187 | 196 |
|
| 188 | 197 |
@app.route("/edit/delete/<id>/")
|
| 189 | 198 |
@main
|
| 190 | 199 |
def delete_design(id):
|
| 191 | 200 |
id = int(id)
|
| 192 | 201 |
design = db.get_design(id)
|
| 193 | |
return 'delete design', Templates.delete_design({
|
| 194 | |
"title": design.title,
|
| 195 | |
"id_str": f"{design.id:05}",
|
| 196 | |
})
|
| 202 |
return (
|
| 203 |
"delete design",
|
| 204 |
Templates.delete_design({"title": design.title, "id_str": f"{design.id:05}",}),
|
| 205 |
)
|
| 206 |
|
| 197 | 207 |
|
| 198 | 208 |
@app.route("/edit/delete/<id>/", methods=["POST"])
|
| 199 | 209 |
def do_delete_design(id):
|
| 200 | 210 |
db.delete_design(int(id))
|
| 201 | 211 |
return flask.redirect(f"/edit/design/")
|
| 202 | 212 |
|
| 213 |
|
| 203 | 214 |
@app.route("/edit/photo/")
|
| 204 | 215 |
@main
|
| 205 | 216 |
def add_photo():
|
| 206 | |
if 'id' in flask.request.args:
|
| 207 | |
id = flask.request.args.get('id')
|
| 217 |
if "id" in flask.request.args:
|
| 218 |
id = flask.request.args.get("id")
|
| 208 | 219 |
return f"Add photo for design {id}", Templates.photo_upload({"id": id})
|
| 209 | 220 |
else:
|
| 210 | 221 |
return "Add generic photo", Templates.photo_upload({"id": -1})
|
| 211 | 222 |
|
| 223 |
|
| 212 | 224 |
@app.route("/edit/photo/", methods=["POST"])
|
| 213 | 225 |
def do_add_photo():
|
| 214 | |
if 'file' not in flask.request.files or 'id' not in flask.request.form:
|
| 215 | |
return flask.redirect('/edit/photo')
|
| 216 | |
id = int(flask.request.form['id'])
|
| 217 | |
file = flask.request.files['file']
|
| 226 |
if "file" not in flask.request.files or "id" not in flask.request.form:
|
| 227 |
return flask.redirect("/edit/photo")
|
| 228 |
id = int(flask.request.form["id"])
|
| 229 |
file = flask.request.files["file"]
|
| 218 | 230 |
photo_id = db.add_photo(file, id)
|
| 219 | 231 |
if id == -1:
|
| 220 | |
return flask.redirect(f'/edit/view-photo/{photo_id:09}')
|
| 232 |
return flask.redirect(f"/edit/view-photo/{photo_id:09}")
|
| 221 | 233 |
else:
|
| 222 | |
return flask.redirect(f'/edit/design/{id:09}')
|
| 234 |
return flask.redirect(f"/edit/design/{id:09}")
|
| 235 |
|
| 223 | 236 |
|
| 224 | 237 |
@app.route("/edit/photo/<id>/")
|
| 225 | 238 |
@main
|
| 226 | 239 |
def modify_photo(id):
|
| 227 | |
design_id = flask.requests.args['design_id']
|
| 228 | |
return 'Delete Photo', Templates.photo_delete(id, design_id)
|
| 240 |
design_id = flask.requests.args["design_id"]
|
| 241 |
return "Delete Photo", Templates.photo_delete(id, design_id)
|
| 242 |
|
| 229 | 243 |
|
| 230 | 244 |
@app.route("/edit/photo/<id>/", methods=["POST"])
|
| 231 | 245 |
def do_modify_photo(id):
|
| 232 | |
design_id = int(flask.request.form['design_id'])
|
| 246 |
design_id = int(flask.request.form["design_id"])
|
| 233 | 247 |
db.delete_photo(id)
|
| 234 | |
return flask.redirect(f'/edit/design/{design_id}/')
|
| 248 |
return flask.redirect(f"/edit/design/{design_id}/")
|
| 249 |
|
| 235 | 250 |
|
| 236 | 251 |
@app.route("/edit/view-photo/")
|
| 237 | 252 |
@main
|
| 238 | 253 |
def view_all_photos():
|
| 239 | |
page = int(flask.request.args.get('page', 0))
|
| 254 |
page = int(flask.request.args.get("page", 0))
|
| 240 | 255 |
p_min, p_max = db.max_photo_page_ranges()
|
| 241 | 256 |
data = db.get_all_photos(offset=page)
|
| 242 | |
return 'Photos', Templates.photo_list({
|
| 243 | |
'photos': (
|
| 244 | |
{"photo": Templates.photo_tile(p)} for p in data),
|
| 245 | |
'page': page,
|
| 246 | |
'show_left': page > p_min,
|
| 247 | |
'show_right': page < p_max,
|
| 248 | |
})
|
| 257 |
return (
|
| 258 |
"Photos",
|
| 259 |
Templates.photo_list(
|
| 260 |
{
|
| 261 |
"photos": ({"photo": Templates.photo_tile(p)} for p in data),
|
| 262 |
"page": page,
|
| 263 |
"show_left": page > p_min,
|
| 264 |
"show_right": page < p_max,
|
| 265 |
}
|
| 266 |
),
|
| 267 |
)
|
| 268 |
|
| 249 | 269 |
|
| 250 | 270 |
@app.route("/edit/view-photo/<id>/")
|
| 251 | 271 |
@main
|
|
| 256 | 276 |
else:
|
| 257 | 277 |
raise Exception(f"Unable to find photo {id}")
|
| 258 | 278 |
|
| 279 |
|
| 259 | 280 |
@app.route("/edit/pages/")
|
| 260 | 281 |
@main
|
| 261 | 282 |
def edit_page_list():
|
| 262 | |
return 'Edit Page List', Templates.edit_pages({
|
| 263 | |
"pages": db.get_page_list(),
|
| 264 | |
})
|
| 283 |
return "Edit Page List", Templates.edit_pages({"pages": db.get_page_list(),})
|
| 284 |
|
| 265 | 285 |
|
| 266 | 286 |
@app.route("/edit/pages/<slug>/")
|
| 267 | 287 |
@main
|
| 268 | 288 |
def edit_page(slug):
|
| 269 | 289 |
page = db.get_page(slug)
|
| 270 | |
return f"Edit Page {slug}", Templates.edit_page({
|
| 271 | |
"name": slug,
|
| 272 | |
"title": page.title,
|
| 273 | |
"text": page.text,
|
| 274 | |
})
|
| 290 |
return (
|
| 291 |
f"Edit Page {slug}",
|
| 292 |
Templates.edit_page({"name": slug, "title": page.title, "text": page.text,}),
|
| 293 |
)
|
| 275 | 294 |
|
| 276 | 295 |
|
| 277 | 296 |
@app.route("/edit/pages/<slug>/", methods=["POST"])
|
| 278 | 297 |
def do_edit_page(slug):
|
| 279 | |
text = flask.request.form.get('text', '')
|
| 280 | |
title = flask.request.form.get('title', slug.capitalize())
|
| 298 |
text = flask.request.form.get("text", "")
|
| 299 |
title = flask.request.form.get("title", slug.capitalize())
|
| 281 | 300 |
db.set_page(slug, title, text)
|
| 282 | |
return flask.redirect(f'/edit/pages/{slug}')
|
| 301 |
return flask.redirect(f"/edit/pages/{slug}")
|
| 283 | 302 |
|
| 284 | 303 |
|
| 285 | 304 |
# urls = (
|