gdritter repos frony-ritter-designs / 897c5b3
replace Pages with Peewee Getty Ritter 3 years ago
2 changed file(s) with 4 addition(s) and 28 deletion(s). Collapse all Expand all
154154 @app.route("/<name>/")
155155 @main
156156 def get_page(name):
157 page = db.get_page(name)
157 page = model.Page.get(name=name)
158158 return page.title, markdown.markdown(page.text)
159159
160160
280280 @app.route("/edit/pages/")
281281 @main
282282 def edit_page_list():
283 return "Edit Page List", Templates.edit_pages({"pages": db.get_page_list(),})
283 return "Edit Page List", Templates.edit_pages({"pages": model.Page.select()})
284284
285285
286286 @app.route("/edit/pages/<slug>/")
287287 @main
288288 def edit_page(slug):
289 page = db.get_page(slug)
289 page = model.Page.get(name=slug)
290290 return (
291291 f"Edit Page {slug}",
292292 Templates.edit_page({"name": slug, "title": page.title, "text": page.text,}),
297297 def do_edit_page(slug):
298298 text = flask.request.form.get("text", "")
299299 title = flask.request.form.get("title", slug.capitalize())
300 db.set_page(slug, title, text)
300 model.Page.update(title=title, text=text).where(model.Page.name==slug).execute()
301301 return flask.redirect(f"/edit/pages/{slug}")
302302
303303
418418 "select count(*) as n from tags where tag_name = $t", vars={"t": tag}
419419 )[0].n
420420
421 def get_about_text(self):
422 return self._db.where("pages", name="about")[0].text
423
424 def set_about_text(self, text):
425 self._db.update("pages", where="name = 'about'", text=text)
426
427 def get_page_list(self):
428 return list(self._db.query("select * from pages"))
429
430 def add_page(self, name, title):
431 self._db.insert("pages", name=name, title=title, text="")
432
433 def get_page(self, name):
434 pg = list(self._db.where("pages", name=name))
435 if pg:
436 return pg[0]
437 else:
438 raise Exception("No page named {0}".format(name))
439
440 def set_page(self, name, title, text):
441 self._db.update(
442 "pages", where="name = $name", title=title, text=text, vars={"name": name}
443 )
444
445421 def get_clacker(self, new_visitor=None):
446422 if new_visitor is not None:
447423 exists = self._db.query(