diff --git a/Dockerfile b/Dockerfile index 96c10bd..20f3c37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM debian8_python3 -COPY app/requirements.txt /requirements.txt +COPY requirements.txt /requirements.txt RUN pip3 install -r /requirements.txt; \ mkdir /data ADD app /app +ADD main.py /main.py +ADD config.py /config.py VOLUME ["/data"] VOLUME ["/app/config] EXPOSE 5000 -ENTRYPOINT python3 /app/main.py +ENTRYPOINT python3 /main.py diff --git a/README.md b/README.md index 442cb08..afe2bdf 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,7 @@ reloaded automatically. The sqlite file will be stored in *tmp* so it can be inspected with tools like *sqlite3*. The switch *DEBUG* enables debugging during development. -`docker run --rm --name rollerverbrauch -ti -v $PWD/app:/app -v $PWD/../rollerverbrauch_config:/app/config -v /tmp/pitstops/:/data -e DEBUG=True -e config=../config/config.py --link pitstops_db:database -p 5000:5000 rollerverbrauch` - +`docker run --rm --name rollerverbrauch -ti -v $PWD/app:/app --link pitstops_db:database -p 5000:5000 -e SECURITY_PASSWORD_SALT=XXX -e SECRET_KEY=XXX -e MAIL_SERVER=XXX -e MAIL_USERNAME=XXX -e MAIL_PASSWORD=XXX rollerverbrauch` ## run in production `docker run --name pitstops -d -v /data/pitstops/:/data -v /configs/pitstops/:/app/config -p 80:5000 rollerverbrauch` diff --git a/app/rollerverbrauch/__init__.py b/app/__init__.py similarity index 96% rename from app/rollerverbrauch/__init__.py rename to app/__init__.py index 85b7afb..58a6b80 100644 --- a/app/rollerverbrauch/__init__.py +++ b/app/__init__.py @@ -1,31 +1,21 @@ from datetime import date + from flask import Flask from flask import redirect, g from flask import render_template from flask import url_for -from flask.ext.mail import Mail -from flask.ext.security import Security, SQLAlchemyUserDatastore, \ - UserMixin, RoleMixin, login_required, roles_required -from flask.ext.security import user_registered +from flask_mail import Mail +from flask_security import Security, SQLAlchemyUserDatastore, \ + login_required, roles_required, user_registered from flask_security.core import current_user +from flask_security.forms import LoginForm from flask_sqlalchemy import SQLAlchemy +import os +from config import config from sqlalchemy.exc import IntegrityError from flask.ext.security.forms import LoginForm -app = Flask(__name__) -app.config['SECURITY_PASSWORD_HASH'] = 'pbkdf2_sha512' -app.config['SECURITY_REGISTERABLE'] = True -app.config['SECURITY_CHANGEABLE'] = True -app.config['SECURITY_RECOVERABLE'] = True -app.config.from_envvar('config') -app.config.from_object(__name__) - -db = SQLAlchemy(app) -mail = Mail(app) - -import rollerverbrauch.tools as tools - -from rollerverbrauch.forms import \ +from .forms import \ CreatePitstopForm, \ EditVehicleForm, \ DeleteVehicleForm, \ @@ -38,7 +28,14 @@ from rollerverbrauch.forms import \ DeletConsumableForm, \ SelectConsumableForm -from rollerverbrauch.entities import \ + +app = Flask(__name__) +app.config.from_object(config[os.getenv('FLASK_CONFIG') or 'default']) + +db = SQLAlchemy(app) +mail = Mail(app) + +from .entities import \ User, \ Role, \ Pitstop, \ @@ -46,7 +43,8 @@ from rollerverbrauch.entities import \ Consumable # required to activate the filters -import rollerverbrauch.filters +from .filters import * +from .tools import * user_datastore = SQLAlchemyUserDatastore(db, User, Role) @@ -92,7 +90,7 @@ def index(): kilometers = 0 for vehicle in vehicles: stats = tools.VehicleStats(vehicle) - litres += stats.overall_litres + #litres += stats.overall_litres kilometers += stats.overall_distance vehicle_count = len(vehicles) pitstop_count = len(Pitstop.query.all()) diff --git a/app/rollerverbrauch/config/config.py.example b/app/config/config.py.example similarity index 100% rename from app/rollerverbrauch/config/config.py.example rename to app/config/config.py.example diff --git a/app/rollerverbrauch/entities.py b/app/entities.py similarity index 98% rename from app/rollerverbrauch/entities.py rename to app/entities.py index b59a917..5e06001 100644 --- a/app/rollerverbrauch/entities.py +++ b/app/entities.py @@ -1,5 +1,5 @@ -from rollerverbrauch import db -from flask.ext.security import UserMixin, RoleMixin +from app import db +from flask_security import UserMixin, RoleMixin roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), diff --git a/app/rollerverbrauch/filters.py b/app/filters.py similarity index 91% rename from app/rollerverbrauch/filters.py rename to app/filters.py index f3ce080..6aadde6 100644 --- a/app/rollerverbrauch/filters.py +++ b/app/filters.py @@ -1,4 +1,4 @@ -from rollerverbrauch import app +from app import app import hashlib diff --git a/app/rollerverbrauch/forms.py b/app/forms.py similarity index 100% rename from app/rollerverbrauch/forms.py rename to app/forms.py diff --git a/app/rollerverbrauch/static/android-icon-192x192.png b/app/static/android-icon-192x192.png similarity index 100% rename from app/rollerverbrauch/static/android-icon-192x192.png rename to app/static/android-icon-192x192.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-114.png b/app/static/apple-touch-icon-114.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-114.png rename to app/static/apple-touch-icon-114.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-120.png b/app/static/apple-touch-icon-120.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-120.png rename to app/static/apple-touch-icon-120.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-144.png b/app/static/apple-touch-icon-144.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-144.png rename to app/static/apple-touch-icon-144.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-152.png b/app/static/apple-touch-icon-152.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-152.png rename to app/static/apple-touch-icon-152.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-180.png b/app/static/apple-touch-icon-180.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-180.png rename to app/static/apple-touch-icon-180.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-57.png b/app/static/apple-touch-icon-57.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-57.png rename to app/static/apple-touch-icon-57.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-60.png b/app/static/apple-touch-icon-60.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-60.png rename to app/static/apple-touch-icon-60.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-72.png b/app/static/apple-touch-icon-72.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-72.png rename to app/static/apple-touch-icon-72.png diff --git a/app/rollerverbrauch/static/apple-touch-icon-76.png b/app/static/apple-touch-icon-76.png similarity index 100% rename from app/rollerverbrauch/static/apple-touch-icon-76.png rename to app/static/apple-touch-icon-76.png diff --git a/app/rollerverbrauch/static/favicon-16.png b/app/static/favicon-16.png similarity index 100% rename from app/rollerverbrauch/static/favicon-16.png rename to app/static/favicon-16.png diff --git a/app/rollerverbrauch/static/favicon-32.png b/app/static/favicon-32.png similarity index 100% rename from app/rollerverbrauch/static/favicon-32.png rename to app/static/favicon-32.png diff --git a/app/rollerverbrauch/static/favicon-96.png b/app/static/favicon-96.png similarity index 100% rename from app/rollerverbrauch/static/favicon-96.png rename to app/static/favicon-96.png diff --git a/app/rollerverbrauch/static/jquery-1.11.2.min.js b/app/static/jquery-1.11.2.min.js similarity index 100% rename from app/rollerverbrauch/static/jquery-1.11.2.min.js rename to app/static/jquery-1.11.2.min.js diff --git a/app/rollerverbrauch/static/main.css b/app/static/main.css similarity index 100% rename from app/rollerverbrauch/static/main.css rename to app/static/main.css diff --git a/app/rollerverbrauch/static/main.js b/app/static/main.js similarity index 100% rename from app/rollerverbrauch/static/main.js rename to app/static/main.js diff --git a/app/rollerverbrauch/static/modernizr-2.8.3-respond-1.4.2.min.js b/app/static/modernizr-2.8.3-respond-1.4.2.min.js similarity index 100% rename from app/rollerverbrauch/static/modernizr-2.8.3-respond-1.4.2.min.js rename to app/static/modernizr-2.8.3-respond-1.4.2.min.js diff --git a/app/rollerverbrauch/static/normalize.min.css b/app/static/normalize.min.css similarity index 100% rename from app/rollerverbrauch/static/normalize.min.css rename to app/static/normalize.min.css diff --git a/app/rollerverbrauch/templates/account.html b/app/templates/account.html similarity index 100% rename from app/rollerverbrauch/templates/account.html rename to app/templates/account.html diff --git a/app/rollerverbrauch/templates/admin.html b/app/templates/admin.html similarity index 100% rename from app/rollerverbrauch/templates/admin.html rename to app/templates/admin.html diff --git a/app/rollerverbrauch/templates/createConsumableForm.html b/app/templates/createConsumableForm.html similarity index 100% rename from app/rollerverbrauch/templates/createConsumableForm.html rename to app/templates/createConsumableForm.html diff --git a/app/rollerverbrauch/templates/createPitStopForm.html b/app/templates/createPitStopForm.html similarity index 100% rename from app/rollerverbrauch/templates/createPitStopForm.html rename to app/templates/createPitStopForm.html diff --git a/app/rollerverbrauch/templates/createVehicleForm.html b/app/templates/createVehicleForm.html similarity index 100% rename from app/rollerverbrauch/templates/createVehicleForm.html rename to app/templates/createVehicleForm.html diff --git a/app/rollerverbrauch/templates/deleteAccountForm.html b/app/templates/deleteAccountForm.html similarity index 100% rename from app/rollerverbrauch/templates/deleteAccountForm.html rename to app/templates/deleteAccountForm.html diff --git a/app/rollerverbrauch/templates/deleteConsumableForm.html b/app/templates/deleteConsumableForm.html similarity index 100% rename from app/rollerverbrauch/templates/deleteConsumableForm.html rename to app/templates/deleteConsumableForm.html diff --git a/app/rollerverbrauch/templates/deletePitstopForm.html b/app/templates/deletePitstopForm.html similarity index 100% rename from app/rollerverbrauch/templates/deletePitstopForm.html rename to app/templates/deletePitstopForm.html diff --git a/app/rollerverbrauch/templates/deleteVehicleForm.html b/app/templates/deleteVehicleForm.html similarity index 100% rename from app/rollerverbrauch/templates/deleteVehicleForm.html rename to app/templates/deleteVehicleForm.html diff --git a/app/rollerverbrauch/templates/editConsumableForm.html b/app/templates/editConsumableForm.html similarity index 100% rename from app/rollerverbrauch/templates/editConsumableForm.html rename to app/templates/editConsumableForm.html diff --git a/app/rollerverbrauch/templates/editPitStopForm.html b/app/templates/editPitStopForm.html similarity index 100% rename from app/rollerverbrauch/templates/editPitStopForm.html rename to app/templates/editPitStopForm.html diff --git a/app/rollerverbrauch/templates/editVehicleForm.html b/app/templates/editVehicleForm.html similarity index 100% rename from app/rollerverbrauch/templates/editVehicleForm.html rename to app/templates/editVehicleForm.html diff --git a/app/rollerverbrauch/templates/index.html b/app/templates/index.html similarity index 100% rename from app/rollerverbrauch/templates/index.html rename to app/templates/index.html diff --git a/app/rollerverbrauch/templates/layout.html b/app/templates/layout.html similarity index 100% rename from app/rollerverbrauch/templates/layout.html rename to app/templates/layout.html diff --git a/app/rollerverbrauch/templates/manual.html b/app/templates/manual.html similarity index 100% rename from app/rollerverbrauch/templates/manual.html rename to app/templates/manual.html diff --git a/app/rollerverbrauch/templates/pitstops.html b/app/templates/pitstops.html similarity index 100% rename from app/rollerverbrauch/templates/pitstops.html rename to app/templates/pitstops.html diff --git a/app/rollerverbrauch/templates/security/change_password.html b/app/templates/security/change_password.html similarity index 100% rename from app/rollerverbrauch/templates/security/change_password.html rename to app/templates/security/change_password.html diff --git a/app/rollerverbrauch/templates/security/forgot_password.html b/app/templates/security/forgot_password.html similarity index 100% rename from app/rollerverbrauch/templates/security/forgot_password.html rename to app/templates/security/forgot_password.html diff --git a/app/rollerverbrauch/templates/security/login_user.html b/app/templates/security/login_user.html similarity index 100% rename from app/rollerverbrauch/templates/security/login_user.html rename to app/templates/security/login_user.html diff --git a/app/rollerverbrauch/templates/security/register_user.html b/app/templates/security/register_user.html similarity index 100% rename from app/rollerverbrauch/templates/security/register_user.html rename to app/templates/security/register_user.html diff --git a/app/rollerverbrauch/templates/security/reset_password.html b/app/templates/security/reset_password.html similarity index 100% rename from app/rollerverbrauch/templates/security/reset_password.html rename to app/templates/security/reset_password.html diff --git a/app/rollerverbrauch/templates/selectConsumableForVehicle.html b/app/templates/selectConsumableForVehicle.html similarity index 100% rename from app/rollerverbrauch/templates/selectConsumableForVehicle.html rename to app/templates/selectConsumableForVehicle.html diff --git a/app/rollerverbrauch/templates/selectVehicle.html b/app/templates/selectVehicle.html similarity index 100% rename from app/rollerverbrauch/templates/selectVehicle.html rename to app/templates/selectVehicle.html diff --git a/app/rollerverbrauch/templates/statistics.html b/app/templates/statistics.html similarity index 100% rename from app/rollerverbrauch/templates/statistics.html rename to app/templates/statistics.html diff --git a/app/rollerverbrauch/tools.py b/app/tools.py similarity index 99% rename from app/rollerverbrauch/tools.py rename to app/tools.py index 00d2862..cd8108a 100644 --- a/app/rollerverbrauch/tools.py +++ b/app/tools.py @@ -1,8 +1,7 @@ import logging from datetime import date -from rollerverbrauch.entities import \ - Pitstop +from .entities import Pitstop class ConsumableStats: diff --git a/config.py b/config.py new file mode 100644 index 0000000..7952a33 --- /dev/null +++ b/config.py @@ -0,0 +1,46 @@ +import os +basedir = os.path.abspath(os.path.dirname(__file__)) + + +class Config: + SECURITY_PASSWORD_HASH = 'pbkdf2_sha512' + SECURITY_REGISTERABLE = True + SECURITY_CHANGEABLE = True + SECURITY_RECOVERABLE = True + SECURITY_PASSWORD_SALT = os.environ.get('SECURITY_PASSWORD_SALT') or 'SOME SECRET STRING' + SECRET_KEY = os.environ.get('SECRET_KEY') or 'SOME SECRET STRING' + SECURITY_EMAIL_SENDER = 'no-reply@lusiardi.de' + SQLALCHEMY_TRACK_MODIFICATIONS = False + MAIL_SERVER = 'mail.nerd2nerd.org' + MAIL_PORT = 25 + MAIL_USE_TLS = True + MAIL_USE_SSL = False + MAIL_USERNAME = os.environ.get('MAIL_USERNAME') + MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') + + @staticmethod + def init_app(app): + pass + + +class DevelopmentConfig(Config): + SECURITY_SEND_REGISTER_EMAIL = False + DEBUG = True + SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:%s@database/pitstops_old' % (os.environ['DATABASE_ENV_MYSQL_ROOT_PASSWORD']) + + +class TestingConfig(Config): + TESTING = True + SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data_testing.sqlite') + + +class ProductionConfig(Config): + SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data.sqlite') + + +config = { + 'development': DevelopmentConfig, + 'testing': TestingConfig, + 'production': ProductionConfig, + 'default': DevelopmentConfig +} \ No newline at end of file diff --git a/app/main.py b/main.py similarity index 90% rename from app/main.py rename to main.py index 3bce806..98c0490 100644 --- a/app/main.py +++ b/main.py @@ -1,5 +1,5 @@ import os -from rollerverbrauch import app +from app import app import logging diff --git a/app/requirements.txt b/requirements.txt similarity index 100% rename from app/requirements.txt rename to requirements.txt