From 738bcb9f8985c262de851ae788370f5e8f643791 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Sun, 3 Jul 2016 19:29:30 +0200 Subject: [PATCH] Fixed project structure for pycharm --- Dockerfile | 6 ++- app/{rollerverbrauch => }/__init__.py | 40 +++++++--------- .../config/config.py.example | 0 app/{rollerverbrauch => }/entities.py | 4 +- app/{rollerverbrauch => }/filters.py | 2 +- app/{rollerverbrauch => }/forms.py | 1 + .../static/android-icon-192x192.png | Bin .../static/apple-touch-icon-114.png | Bin .../static/apple-touch-icon-120.png | Bin .../static/apple-touch-icon-144.png | Bin .../static/apple-touch-icon-152.png | Bin .../static/apple-touch-icon-180.png | Bin .../static/apple-touch-icon-57.png | Bin .../static/apple-touch-icon-60.png | Bin .../static/apple-touch-icon-72.png | Bin .../static/apple-touch-icon-76.png | Bin .../static/favicon-16.png | Bin .../static/favicon-32.png | Bin .../static/favicon-96.png | Bin .../static/jquery-1.11.2.min.js | 0 app/{rollerverbrauch => }/static/main.css | 0 app/{rollerverbrauch => }/static/main.js | 0 .../modernizr-2.8.3-respond-1.4.2.min.js | 0 .../static/normalize.min.css | 0 .../templates/account.html | 0 .../templates/admin.html | 0 .../templates/createVehicleForm.html | 0 .../templates/deleteAccountForm.html | 0 .../templates/deletePitstopForm.html | 0 .../templates/deleteVehicleForm.html | 0 .../templates/editPitStopForm.html | 0 .../templates/editVehicleForm.html | 0 .../templates/index.html | 0 .../templates/layout.html | 0 .../templates/manual.html | 0 .../templates/newPitStopForm.html | 0 .../templates/pitstops.html | 0 .../templates/security/change_password.html | 0 .../templates/security/forgot_password.html | 0 .../templates/security/login_user.html | 0 .../templates/security/register_user.html | 0 .../templates/security/reset_password.html | 0 .../templates/selectVehice.html | 0 .../templates/statistics.html | 0 app/{rollerverbrauch => }/tools.py | 0 config.py | 44 ++++++++++++++++++ app/main.py => main.py | 2 +- app/requirements.txt => requirements.txt | 0 48 files changed, 71 insertions(+), 28 deletions(-) rename app/{rollerverbrauch => }/__init__.py (93%) rename app/{rollerverbrauch => }/config/config.py.example (100%) rename app/{rollerverbrauch => }/entities.py (95%) rename app/{rollerverbrauch => }/filters.py (91%) rename app/{rollerverbrauch => }/forms.py (99%) rename app/{rollerverbrauch => }/static/android-icon-192x192.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-114.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-120.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-144.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-152.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-180.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-57.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-60.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-72.png (100%) rename app/{rollerverbrauch => }/static/apple-touch-icon-76.png (100%) rename app/{rollerverbrauch => }/static/favicon-16.png (100%) rename app/{rollerverbrauch => }/static/favicon-32.png (100%) rename app/{rollerverbrauch => }/static/favicon-96.png (100%) rename app/{rollerverbrauch => }/static/jquery-1.11.2.min.js (100%) rename app/{rollerverbrauch => }/static/main.css (100%) rename app/{rollerverbrauch => }/static/main.js (100%) rename app/{rollerverbrauch => }/static/modernizr-2.8.3-respond-1.4.2.min.js (100%) rename app/{rollerverbrauch => }/static/normalize.min.css (100%) rename app/{rollerverbrauch => }/templates/account.html (100%) rename app/{rollerverbrauch => }/templates/admin.html (100%) rename app/{rollerverbrauch => }/templates/createVehicleForm.html (100%) rename app/{rollerverbrauch => }/templates/deleteAccountForm.html (100%) rename app/{rollerverbrauch => }/templates/deletePitstopForm.html (100%) rename app/{rollerverbrauch => }/templates/deleteVehicleForm.html (100%) rename app/{rollerverbrauch => }/templates/editPitStopForm.html (100%) rename app/{rollerverbrauch => }/templates/editVehicleForm.html (100%) rename app/{rollerverbrauch => }/templates/index.html (100%) rename app/{rollerverbrauch => }/templates/layout.html (100%) rename app/{rollerverbrauch => }/templates/manual.html (100%) rename app/{rollerverbrauch => }/templates/newPitStopForm.html (100%) rename app/{rollerverbrauch => }/templates/pitstops.html (100%) rename app/{rollerverbrauch => }/templates/security/change_password.html (100%) rename app/{rollerverbrauch => }/templates/security/forgot_password.html (100%) rename app/{rollerverbrauch => }/templates/security/login_user.html (100%) rename app/{rollerverbrauch => }/templates/security/register_user.html (100%) rename app/{rollerverbrauch => }/templates/security/reset_password.html (100%) rename app/{rollerverbrauch => }/templates/selectVehice.html (100%) rename app/{rollerverbrauch => }/templates/statistics.html (100%) rename app/{rollerverbrauch => }/tools.py (100%) create mode 100644 config.py rename app/main.py => main.py (90%) rename app/requirements.txt => requirements.txt (100%) 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/app/rollerverbrauch/__init__.py b/app/__init__.py similarity index 93% rename from app/rollerverbrauch/__init__.py rename to app/__init__.py index 6738202..d34f7ac 100644 --- a/app/rollerverbrauch/__init__.py +++ b/app/__init__.py @@ -1,30 +1,19 @@ 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 -from flask.ext.security.forms import LoginForm +import os +from config import config -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, \ @@ -32,15 +21,22 @@ from rollerverbrauch.forms import \ DeleteAccountForm, \ DeletePitStopForm, \ EditPitstopForm +from .tools import * -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, \ Vehicle - +from .filters import * +#import rollerverbrauch.tools as tools # required to activate the filters -import rollerverbrauch.filters user_datastore = SQLAlchemyUserDatastore(db, User, Role) 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 95% rename from app/rollerverbrauch/entities.py rename to app/entities.py index 0a72a29..508513b 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 99% rename from app/rollerverbrauch/forms.py rename to app/forms.py index c6bb7c2..5fb1801 100644 --- a/app/rollerverbrauch/forms.py +++ b/app/forms.py @@ -31,6 +31,7 @@ def edit_costs_check(form, field): if costs_check_required and field.data is not None and field.data <= 0: raise ValidationError('Costs must be above 0.01 €.') + class SelectVehicleForm(Form): vehicle = SelectField('Vehicle', coerce=int) submit = SubmitField(label='Do it!') 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/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/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/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/newPitStopForm.html b/app/templates/newPitStopForm.html similarity index 100% rename from app/rollerverbrauch/templates/newPitStopForm.html rename to app/templates/newPitStopForm.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/selectVehice.html b/app/templates/selectVehice.html similarity index 100% rename from app/rollerverbrauch/templates/selectVehice.html rename to app/templates/selectVehice.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 100% rename from app/rollerverbrauch/tools.py rename to app/tools.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..a4e23b9 --- /dev/null +++ b/config.py @@ -0,0 +1,44 @@ +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' + SQLALCHEMY_TRACK_MODIFICATIONS = False + MAIL_SERVER = 'smtp.googlemail.com' + MAIL_PORT = 587 + MAIL_USE_TLS = True + 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 = 'sqlite:///' + os.path.join(basedir, 'data_dev.sqlite') + + +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