This commit is contained in:
Emily 2019-02-12 16:59:43 +01:00
parent cabab9bbd0
commit 85b7aa60a3
8 changed files with 72 additions and 2 deletions

View File

@ -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
## 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

0
__init__.py Normal file
View File

10
config.json Normal file
View File

@ -0,0 +1,10 @@
{
"web": {
"debug": true,
"use_reloader": true,
"threaded": true,
"host": "127.0.0.1",
"port": 80
},
"disable-static-cache": true
}

29
main.py Normal file
View File

@ -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"])

0
objects/__init__.py Normal file
View File

12
objects/glob.py Normal file
View File

@ -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)

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
Flask>=1.0.2
Flask-WTF>=0.14.2

3
routes.py Normal file
View File

@ -0,0 +1,3 @@
from flask import render_template, url_for
from objects import glob # Global sharing of python objects in a manageable way