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 0000000..9b21c07 Binary files /dev/null and b/app/__init__.pyc differ 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)