From 85b7aa60a3a105d5177bb9c55acaae82f3ecbbf5 Mon Sep 17 00:00:00 2001 From: Sunpy Date: Tue, 12 Feb 2019 16:59:43 +0100 Subject: [PATCH] Startup --- README.md | 18 ++++++++++++++++-- __init__.py | 0 config.json | 10 ++++++++++ main.py | 29 +++++++++++++++++++++++++++++ objects/__init__.py | 0 objects/glob.py | 12 ++++++++++++ requirements.txt | 2 ++ routes.py | 3 +++ 8 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 __init__.py create mode 100644 config.json create mode 100644 main.py create mode 100644 objects/__init__.py create mode 100644 objects/glob.py create mode 100644 requirements.txt create mode 100644 routes.py diff --git a/README.md b/README.md index a856c21..753028a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ -# husstanden +# Husstanden +Husstanden is a service that aims towards organizing your day to day life -Husstanden is a service that aims towards organizing your day to day life \ No newline at end of file +## Requirements +- Python 3.5+ + +## How to set up husstanden +Install the required dependencies with pip +``` +$ pip install -r requirements.txt +``` +then, run the web server +``` +$ python3 main.py +``` + +Configuration can be edited in config.json \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config.json b/config.json new file mode 100644 index 0000000..9af352d --- /dev/null +++ b/config.json @@ -0,0 +1,10 @@ +{ + "web": { + "debug": true, + "use_reloader": true, + "threaded": true, + "host": "127.0.0.1", + "port": 80 + }, + "disable-static-cache": true +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..819b780 --- /dev/null +++ b/main.py @@ -0,0 +1,29 @@ +from flask import Flask, url_for +from objects import glob # Global sharing of python objects in a manageable way + +glob.app = Flask(__name__) + +import routes # All flask app routes + +if glob.config["disable-static-cache"]: + import os + + @glob.app.context_processor + def override_url_for(): + """ + Generate a new token on every request to prevent the browser from + caching static files. + """ + return dict(url_for=dated_url_for) + + def dated_url_for(endpoint, **values): + if endpoint == 'static': + filename = values.get('filename', None) + if filename: + file_path = os.path.join(glob.app.root_path, + endpoint, filename) + values['q'] = int(os.stat(file_path).st_mtime) + return url_for(endpoint, **values) + +if __name__ == "__main__": + glob.app.run(**glob.config["web"]) diff --git a/objects/__init__.py b/objects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/objects/glob.py b/objects/glob.py new file mode 100644 index 0000000..6dabef1 --- /dev/null +++ b/objects/glob.py @@ -0,0 +1,12 @@ +import json + +# ------------------------------------------------------------------------------ +# Global variables that is None by default and gets overwritten in other modules + +app = None # main.py -> Flask App + +# ------------------------------------------------------------------------------ +# Global variables that initializes on first load of module + +with open("config.json", "r") as f: + config = json.load(f) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..44e7a67 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask>=1.0.2 +Flask-WTF>=0.14.2 diff --git a/routes.py b/routes.py new file mode 100644 index 0000000..976e3ef --- /dev/null +++ b/routes.py @@ -0,0 +1,3 @@ +from flask import render_template, url_for +from objects import glob # Global sharing of python objects in a manageable way +