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/") # check two words pascal case app.router.add_filter("pc", lambda conf: (r"[A-Z][a-z]+[A-Z][a-z]*", None, None)) @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 = model.Page.now() 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)