From dfa695bb83a5ba56dfc1e2d6307ea2a8965850bf Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 24 Dec 2016 05:44:47 -0500 Subject: [PATCH] Add structure and supporting code for modules; add Campaigns module. * Add config/modules/. * Add hook-aware post-login homepage. * Add flexible character module property database table, plus AuthManager interface. * Add Config.modules. * Modules are imported dynamically with a _provided pseudo-module that contains their Flask blueprint and a config reference. * Add stubs for Map, Members, and Intel modules. * Implement starting code for Campaigns module. * Update sample config. * Update database schema with foreign key constraints (unused for now). * Restructure header HTML and desktop CSS slightly to cleanly display large navigation bars. * Dynamically generate navigation bar. * Properly align character options popup with portrait. --- .gitignore | 5 ++- app.py | 20 ++++++----- calefaction/auth.py | 50 ++++++++++++++++++++++++++-- calefaction/config.py | 51 +++++++++++++++++++++++++++- calefaction/database.py | 14 ++++++++ calefaction/module.py | 53 +++++++++++++++++++++++++++++ calefaction/modules/campaigns.py | 35 ++++++++++++++++++++ calefaction/modules/intel.py | 6 ++++ calefaction/modules/map.py | 6 ++++ calefaction/modules/members.py | 6 ++++ config/config.yml.sample | 12 ++++--- config/modules/campaigns.yml.sample | 15 +++++++++ data/schema.sql | 36 ++++++++++++++------ static/main.css | 66 +++++++++++++++++++++++++++++-------- static/main.js | 4 +-- templates/_base.mako | 26 ++++++++------- templates/_default.mako | 41 ++++++++++++++--------- templates/campaigns/campaign.mako | 7 ++++ templates/campaigns/navitem.mako | 1 + templates/default_home.mako | 2 ++ templates/home.mako | 2 -- 21 files changed, 385 insertions(+), 73 deletions(-) create mode 100644 calefaction/module.py create mode 100644 calefaction/modules/intel.py create mode 100644 calefaction/modules/map.py create mode 100644 calefaction/modules/members.py create mode 100644 config/modules/campaigns.yml.sample create mode 100644 templates/campaigns/campaign.mako create mode 100644 templates/campaigns/navitem.mako create mode 100644 templates/default_home.mako delete mode 100644 templates/home.mako diff --git a/.gitignore b/.gitignore index f666b76..f9acdd1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,11 @@ __pycache__/ venv/ config/* +config/modules/* data/* logs/ -!config/config.yml.sample +!config/*.sample +!config/modules +!config/modules/*.sample !data/schema.sql diff --git a/app.py b/app.py index e505069..3b951ed 100755 --- a/app.py +++ b/app.py @@ -24,8 +24,8 @@ Database.path = str(basepath / "data" / "db.sqlite3") eve = EVE(config) auth = AuthManager(config, eve) -catch_exceptions = make_error_catcher(app, "error.mako") -route_restricted = make_route_restricter( +app.catch_exceptions = make_error_catcher(app, "error.mako") +app.route_restricted = make_route_restricter( auth, lambda: redirect(url_for("index"), 303)) MakoTemplates(app) @@ -38,21 +38,25 @@ def prepare_request(): g.auth = auth g.config = config g.eve = eve + g.modules = config.modules g.version = calefaction.__version__ app.before_request(Database.pre_hook) app.teardown_appcontext(Database.post_hook) @app.route("/") -@catch_exceptions +@app.catch_exceptions def index(): success, _ = try_func(auth.is_authenticated) if success: - return render_template("home.mako") + module = config.get("modules.home") + if module: + return config.modules[module].home() + return render_template("default_home.mako") return render_template("landing.mako") @app.route("/login", methods=["GET", "POST"]) -@catch_exceptions +@app.catch_exceptions def login(): code = request.args.get("code") state = request.args.get("state") @@ -65,7 +69,7 @@ def login(): return redirect(url_for("index"), 303) @app.route("/logout", methods=["GET", "POST"]) -@catch_exceptions +@app.catch_exceptions def logout(): if request.method == "GET": return render_template("logout.mako") @@ -75,8 +79,8 @@ def logout(): return redirect(url_for("index"), 303) @app.route("/settings/style/