diff --git a/files/__init__.py b/files/__init__.py index a98b04d..95a98af 100644 --- a/files/__init__.py +++ b/files/__init__.py @@ -7,8 +7,9 @@ from werkzeug.wsgi import SharedDataMiddleware def create_app(): app = Flask(__name__, instance_relative_config=True) app.config.from_mapping( - SQLALCHEMY_DATABASE_URI=os.environ.get("SQLALCHEMY_DATABASE_URI"), - SQLALCHEMY_TRACK_MODIFICATIONS=os.environ.get("SQLALCHEMY_TRACK_MODIFICATIONS"), + SQLALCHEMY_DATABASE_URI=os.environ.get("DATABASE_URI"), + SQLALCHEMY_TRACK_MODIFICATIONS=os.environ.get("TRACK_MODIFICATIONS"), + SQLALCHEMY_POOL_RECYCLE=os.environ.get("POOL_RECYCLE"), USERNAME=os.environ.get("USERNAME"), PASSWORD=os.environ.get("PASSWORD"), SECRET_KEY=os.environ.get("SECRET_KEY"), @@ -18,11 +19,6 @@ def create_app(): app.wsgi_app = SharedDataMiddleware( app.wsgi_app, {'/uploads': app.config['UPLOAD_FOLDER']}) - try: - os.makedirs(app.instance_path) - except OSError: - pass - from files.models import db db.init_app(app) diff --git a/files/admin.py b/files/admin.py index 9b15366..46fa308 100644 --- a/files/admin.py +++ b/files/admin.py @@ -1,6 +1,6 @@ -from flask import Blueprint, flash, request, redirect, url_for, render_template +from flask import Blueprint, render_template from files.auth import admin_required -from files.models import Category, FileType +from files.models import Category, FileType bp = Blueprint('admin', __name__, url_prefix='/admin') diff --git a/files/commands.py b/files/commands.py index 426f256..b14cd4b 100644 --- a/files/commands.py +++ b/files/commands.py @@ -71,6 +71,15 @@ def init_db_command(): add_defaults() add_files() +@click.command('generate-admin') +@with_appcontext +def generate_admin_command(): + """ + Generates an account + """ + generate_admin() + def init_app(app): + app.cli.add_command(generate_admin_command) app.cli.add_command(init_db_command) diff --git a/files/files.py b/files/files.py index 1e60cfd..bcb6453 100644 --- a/files/files.py +++ b/files/files.py @@ -150,18 +150,19 @@ def preview_file(file_id): categories=categories, file_types=file_types, content=content) - elif file.type.name == 'Image': + + if file.type.name == 'Image': return render_template( 'files/preview/image.html', file=file, categories=categories, file_types=file_types) - else: - return render_template( - 'files/preview/default.html', - file=file, - categories=categories, - file_types=file_types) + + return render_template( + 'files/preview/default.html', + file=file, + categories=categories, + file_types=file_types) return abort(404) diff --git a/files/models.py b/files/models.py index 3fd642d..7b5ed91 100644 --- a/files/models.py +++ b/files/models.py @@ -25,7 +25,7 @@ class Message(db.Model): name = db.Column(db.String(255), nullable=False) email = db.Column(db.String(255), nullable=False) message = db.Column(db.Text, nullable=False) - sended = db.Column(db.DateTime, default=datetime.utcnow()) + sended = db.Column(db.DateTime, default=datetime.utcnow) def __init__(self, name=None, email=None, message=None): self.name = name