commit
165b828889
@ -3,6 +3,7 @@
|
||||
# Application
|
||||
export FLASK_ENV=development
|
||||
export FLASK_APP=fittrackee/__main__.py
|
||||
export FLASK_SKIP_DOTENV=1
|
||||
export APP_SETTINGS=fittrackee.config.DevelopmentConfig
|
||||
export APP_SECRET_KEY='just for test'
|
||||
# export APP_WORKERS=
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
# Application
|
||||
# export FLASK_APP=fittrackee
|
||||
export FLASK_SKIP_DOTENV=1
|
||||
# export HOST=
|
||||
# export PORT=
|
||||
# export APP_SETTINGS=fittrackee.config.ProductionConfig
|
||||
|
2
Makefile
2
Makefile
@ -162,7 +162,7 @@ serve-python-dev:
|
||||
$(FLASK) run --with-threads -h $(HOST) -p $(PORT) --cert=adhoc
|
||||
|
||||
set-admin:
|
||||
$(FLASK) set-admin $(USERNAME)
|
||||
$(FLASK) users set-admin $(USERNAME)
|
||||
|
||||
test-e2e: init-db
|
||||
$(PYTEST) e2e --driver firefox $(PYTEST_ARGS)
|
||||
|
@ -4,4 +4,4 @@ cd /usr/src/app
|
||||
|
||||
source .env.docker
|
||||
|
||||
flask set-admin $1
|
||||
flask users set-admin $1
|
||||
|
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from importlib import import_module, reload
|
||||
from typing import Any
|
||||
|
||||
@ -128,4 +129,17 @@ def create_app() -> Flask:
|
||||
else:
|
||||
return render_template('index.html')
|
||||
|
||||
@app.cli.command('drop-db')
|
||||
def drop_db() -> None:
|
||||
"""Empty database and delete uploaded files for dev environments."""
|
||||
if app_settings == 'fittrackee.config.ProductionConfig':
|
||||
print('This is a production server, aborting!')
|
||||
return
|
||||
db.engine.execute("DROP TABLE IF EXISTS alembic_version;")
|
||||
db.drop_all()
|
||||
db.session.commit()
|
||||
print('Database dropped.')
|
||||
shutil.rmtree(app.config['UPLOAD_FOLDER'], ignore_errors=True)
|
||||
print('Uploaded files deleted.')
|
||||
|
||||
return app
|
||||
|
@ -1,25 +1,19 @@
|
||||
# source for StandaloneApplication class:
|
||||
# http://docs.gunicorn.org/en/stable/custom.html
|
||||
import os
|
||||
import shutil
|
||||
from typing import Dict, Optional
|
||||
|
||||
import click
|
||||
import gunicorn.app.base
|
||||
from flask import Flask
|
||||
from flask_dramatiq import worker
|
||||
from flask_migrate import upgrade
|
||||
|
||||
from fittrackee import create_app, db
|
||||
from fittrackee.users.exceptions import UserNotFoundException
|
||||
from fittrackee.users.utils import set_admin_rights
|
||||
from fittrackee import create_app
|
||||
|
||||
HOST = os.getenv('HOST', '0.0.0.0')
|
||||
PORT = os.getenv('PORT', '5000')
|
||||
WORKERS = os.getenv('APP_WORKERS', 1)
|
||||
BASEDIR = os.path.abspath(os.path.dirname(__file__))
|
||||
app = create_app()
|
||||
dramatiq_worker = worker
|
||||
|
||||
|
||||
class StandaloneApplication(gunicorn.app.base.BaseApplication):
|
||||
@ -48,28 +42,6 @@ def upgrade_db() -> None:
|
||||
upgrade(directory=BASEDIR + '/migrations')
|
||||
|
||||
|
||||
@app.cli.command('drop-db')
|
||||
def drop_db() -> None:
|
||||
"""Empty database and delete uploaded files for dev environments."""
|
||||
db.engine.execute("DROP TABLE IF EXISTS alembic_version;")
|
||||
db.drop_all()
|
||||
db.session.commit()
|
||||
print('Database dropped.')
|
||||
shutil.rmtree(app.config['UPLOAD_FOLDER'], ignore_errors=True)
|
||||
print('Uploaded files deleted.')
|
||||
|
||||
|
||||
@app.cli.command('set-admin')
|
||||
@click.argument('username')
|
||||
def set_admin(username: str) -> None:
|
||||
"""Set admin rights for given user"""
|
||||
try:
|
||||
set_admin_rights(username)
|
||||
print(f"User '{username}' updated.")
|
||||
except UserNotFoundException:
|
||||
print(f"User '{username}' not found.")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
options = {'bind': f'{HOST}:{PORT}', 'workers': WORKERS}
|
||||
StandaloneApplication(app, options).run()
|
||||
|
@ -6,7 +6,7 @@ from email.mime.text import MIMEText
|
||||
from typing import Dict, Optional, Type, Union
|
||||
|
||||
from flask import Flask
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
|
||||
from .utils_email import parse_email_url
|
||||
|
||||
@ -38,7 +38,10 @@ class EmailMessage:
|
||||
|
||||
class EmailTemplate:
|
||||
def __init__(self, template_directory: str) -> None:
|
||||
self._env = Environment(loader=FileSystemLoader(template_directory))
|
||||
self._env = Environment(
|
||||
autoescape=select_autoescape(['html', 'htm', 'xml']),
|
||||
loader=FileSystemLoader(template_directory),
|
||||
)
|
||||
|
||||
def get_content(
|
||||
self, template_name: str, lang: str, part: str, data: Dict
|
||||
|
@ -2,6 +2,7 @@ import os
|
||||
import shutil
|
||||
from typing import Any, Dict, Tuple, Union
|
||||
|
||||
import click
|
||||
from flask import Blueprint, request, send_file
|
||||
from sqlalchemy import exc
|
||||
|
||||
@ -18,13 +19,26 @@ from fittrackee.workouts.models import Record, Workout, WorkoutSegment
|
||||
from fittrackee.workouts.utils_files import get_absolute_file_path
|
||||
|
||||
from .decorators import authenticate, authenticate_as_admin
|
||||
from .exceptions import UserNotFoundException
|
||||
from .models import User, UserSportPreference
|
||||
from .utils import set_admin_rights
|
||||
|
||||
users_blueprint = Blueprint('users', __name__)
|
||||
|
||||
USER_PER_PAGE = 10
|
||||
|
||||
|
||||
@users_blueprint.cli.command('set-admin')
|
||||
@click.argument('username')
|
||||
def set_admin(username: str) -> None:
|
||||
"""Set admin rights for given user"""
|
||||
try:
|
||||
set_admin_rights(username)
|
||||
print(f"User '{username}' updated.")
|
||||
except UserNotFoundException:
|
||||
print(f"User '{username}' not found.")
|
||||
|
||||
|
||||
@users_blueprint.route('/users', methods=['GET'])
|
||||
@authenticate
|
||||
def get_users(auth_user: User) -> Dict:
|
||||
|
@ -62,9 +62,9 @@ Sphinx = "^4.4.0"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
fittrackee = 'fittrackee.__main__:main'
|
||||
fittrackee_set_admin = 'fittrackee.__main__:set_admin'
|
||||
fittrackee_set_admin = 'fittrackee.users.users:set_admin'
|
||||
fittrackee_upgrade_db = 'fittrackee.__main__:upgrade_db'
|
||||
fittrackee_worker = 'fittrackee.__main__:dramatiq_worker'
|
||||
fittrackee_worker = 'flask_dramatiq:worker'
|
||||
|
||||
[tool.black]
|
||||
line-length = 79
|
||||
|
Loading…
Reference in New Issue
Block a user