replace Pages with Peewee
Getty Ritter
4 years ago
| 154 | 154 |
@app.route("/<name>/")
|
| 155 | 155 |
@main
|
| 156 | 156 |
def get_page(name):
|
| 157 | |
page = db.get_page(name)
|
| 157 |
page = model.Page.get(name=name)
|
| 158 | 158 |
return page.title, markdown.markdown(page.text)
|
| 159 | 159 |
|
| 160 | 160 |
|
|
| 280 | 280 |
@app.route("/edit/pages/")
|
| 281 | 281 |
@main
|
| 282 | 282 |
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()})
|
| 284 | 284 |
|
| 285 | 285 |
|
| 286 | 286 |
@app.route("/edit/pages/<slug>/")
|
| 287 | 287 |
@main
|
| 288 | 288 |
def edit_page(slug):
|
| 289 | |
page = db.get_page(slug)
|
| 289 |
page = model.Page.get(name=slug)
|
| 290 | 290 |
return (
|
| 291 | 291 |
f"Edit Page {slug}",
|
| 292 | 292 |
Templates.edit_page({"name": slug, "title": page.title, "text": page.text,}),
|
|
| 297 | 297 |
def do_edit_page(slug):
|
| 298 | 298 |
text = flask.request.form.get("text", "")
|
| 299 | 299 |
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()
|
| 301 | 301 |
return flask.redirect(f"/edit/pages/{slug}")
|
| 302 | 302 |
|
| 303 | 303 |
|
| 418 | 418 |
"select count(*) as n from tags where tag_name = $t", vars={"t": tag}
|
| 419 | 419 |
)[0].n
|
| 420 | 420 |
|
| 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 | |
|
| 445 | 421 |
def get_clacker(self, new_visitor=None):
|
| 446 | 422 |
if new_visitor is not None:
|
| 447 | 423 |
exists = self._db.query(
|