From fcd783ef26f2dc48b957f3dc169d70960d62baa9 Mon Sep 17 00:00:00 2001 From: Finn Christiansen Date: Sun, 30 Dec 2018 09:24:29 +0100 Subject: [PATCH] some cleanup and refactoring --- apache_sample_config.conf | 2 ++ app/__init__.py | 13 +++++++++++++ app/__init__.pyc | Bin 0 -> 2730 bytes index.py => app/index.py | 14 ++++++-------- {templates => app/templates}/base.html | 2 +- {templates => app/templates}/index.html | 1 + reminder.wsgi | 9 +++++++++ 7 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 app/__init__.py create mode 100644 app/__init__.pyc rename index.py => app/index.py (80%) rename {templates => app/templates}/base.html (83%) rename {templates => app/templates}/index.html (97%) create mode 100644 reminder.wsgi diff --git a/apache_sample_config.conf b/apache_sample_config.conf index 9a275dc..51888a2 100644 --- a/apache_sample_config.conf +++ b/apache_sample_config.conf @@ -21,6 +21,8 @@ ErrorLog ${APACHE_LOG_DIR}/reminder.pimux.de_error.log CustomLog ${APACHE_LOG_DIR}/reminder.pimux.de_access.log combined + SetEnv SECRET_KEY secret + WSGIDaemonProcess reminder user=www-data group=www-data threads=5 WSGIScriptAlias / /var/www/vhosts/reminder.pimux.de/index.py WSGIScriptReloading On diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..3e130fc --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,13 @@ +from flask import Flask +from flask_wtf.csrf import CSRFProtect +from app.index import index + +cp = CSRFProtect() + + +def create_app(): + app = Flask(__name__) + app.config['SECRET_KEY'] = 'SECRET_KEY' + app.register_blueprint(index) + cp.init_app(app) + return app diff --git a/app/__init__.pyc b/app/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9b21c07292c3f167d22c803a8452e32940fa51e8 GIT binary patch literal 2730 zcmZ`*-EJFI5T3Jk{FB&m{+cwEr~;y@K{SO6grF_Lb)D3raig`Hl2xnK)_a_+vuiuM z$4w&HS4CX%3Vi^$M!n&hN8tf@0QhD$O`xLI?%6YQ=FB-W^UaJif0b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})$*PtYz1f-Vnrsat}-sArn>ERqEn{AUMl}zKZ zlO`VrGp!u#V%g=Mn4Zm-m1=Xr+LRo=h>OG+l3e=J@JKwaVBa}+GsR0Hed0@r-a8uE zVDW|h86U^-g;gPLX95%twj&;*YTEZOli=Ac%r1TO-bf3!?xtw^mK~6+VE9O_B5_w` NTu`OV$2V4s{{R#L9#;SW literal 0 HcmV?d00001 diff --git a/index.py b/app/index.py similarity index 80% rename from index.py rename to app/index.py index b1d2883..6f66ec2 100644 --- a/index.py +++ b/app/index.py @@ -1,17 +1,15 @@ -from flask import Flask, render_template, request, send_file +from flask import Blueprint, render_template, send_file from icalendar import Calendar, Alarm from flask_wtf import FlaskForm -#from flask_wtf.file import FileField, FileRequired -from wtforms import FileField, IntegerField, SubmitField -from wtforms.validators import InputRequired +from flask_wtf.file import FileField, FileRequired +from wtforms import IntegerField, SubmitField from wtforms.widgets.html5 import NumberInput import tempfile -application = Flask(__name__) -application.config['SECRET_KEY'] = 'secret' +index = Blueprint('index', __name__, template_folder='templates') -@application.route("/", methods=['GET', 'POST']) +@index.route("/", methods=['GET', 'POST']) def addreminder(): form = IcsForm() content = render_template('index.html', form=form) @@ -49,7 +47,7 @@ def addreminder(): class IcsForm(FlaskForm): - icsfile = FileField('ICS File', validators=[InputRequired()]) + icsfile = FileField('ICS File', validators=[FileRequired()]) hours = IntegerField('Hours', default=0, widget=NumberInput(step=1, min=0, max=24)) minutes = IntegerField('Minutes', default=0, diff --git a/templates/base.html b/app/templates/base.html similarity index 83% rename from templates/base.html rename to app/templates/base.html index 037e7d2..372c8ad 100644 --- a/templates/base.html +++ b/app/templates/base.html @@ -14,7 +14,7 @@ {% endblock %} diff --git a/templates/index.html b/app/templates/index.html similarity index 97% rename from templates/index.html rename to app/templates/index.html index 722c408..8596a36 100644 --- a/templates/index.html +++ b/app/templates/index.html @@ -3,6 +3,7 @@

Add reminders to ICS files

+ {{ form.csrf_token }}
  1. Select ICS file
  2. Set reminder time
  3. diff --git a/reminder.wsgi b/reminder.wsgi new file mode 100644 index 0000000..1fc0521 --- /dev/null +++ b/reminder.wsgi @@ -0,0 +1,9 @@ +import os +import sys +sys.path.insert(1, os.path.dirname(__file__)) +from app import create_app + +def application(environ, start_response): + os.environ['SECRET_KEY'] = environ.get('SECRET_KEY') + app = create_app() + return app(environ, start_response)