From 0a5471217b9f562b92f32802de4260390f639880 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 23 Mar 2024 19:01:29 +0000 Subject: Initial import --- wiki.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 wiki.py (limited to 'wiki.py') diff --git a/wiki.py b/wiki.py new file mode 100644 index 0000000..617f841 --- /dev/null +++ b/wiki.py @@ -0,0 +1,89 @@ +import logging +from datetime import datetime +import logging.config +import json +from hashlib import md5 + +from bottle import Bottle, static_file, run, template, redirect, request +from bottle_sqlite import SQLitePlugin + +import model + +with open("logger.json", "rt") as fd: + logging.config.dictConfig(json.load(fd)) +log = logging.getLogger("wiki") + +app = Bottle() +app.config.load_config("wiki.conf") + +model.bootstrap_db(app.config["sqlite.db"]) + +app.install(SQLitePlugin(dbfile=app.config["sqlite.db"])) + +DEV = app.config["wiki.dev"] + +if DEV: + log.warning("Running in dev mode") + + @app.route("/static/") + def send_static(filename): + return static_file(filename, root="static/") + + +@app.route("/") +def index(): + redirect("/WikiHome") + + +@app.route("/") +def page(db, name): + return template( + "page", dict(page=model.get_page(db, name)) + ) + + +@app.get("/edit/") +def edit(db, name): + return template( + "edit", dict(page=model.get_page(db, name)) + ) + + +@app.get("/history/") +def history(db, name): + return template( + "history", + dict( + page=model.Page(name=name), + history=model.get_page_history(db, name), + ), + ) + + +@app.get("/history//") +def history_view(db, name, version): + return template( + "page", + dict( + page=model.get_page(db, name, version), + ), + ) + + +@app.post("/edit/") +def edit_save(db, name): + page = model.get_page(db, name) + + if page.version is not None: + page.updated_at = datetime.utcnow() + page.content = request.forms.get("content") + page.changelog = request.forms.get("changelog") + page.version = md5(str(page.updated_at).encode()).hexdigest() + + model.save_page(db, page) + + redirect(f"/{name}") + + +if __name__ == "__main__": + run(app, reloader=DEV, host="localhost", port=8080) -- cgit v1.2.3