formatting

This commit is contained in:
Gardient
2021-09-22 19:24:48 +03:00
parent aeb8916744
commit 98a8747821
6 changed files with 19 additions and 9 deletions

View File

@@ -1,8 +1,9 @@
from flask import Flask, Blueprint from flask import Flask, Blueprint
from . import commands, login, target_exchange, target from . import commands, login, target_exchange, target
from .settings import ProdConfig, Config
from .extensions import db, migrate, jwt, apispec
from .exceptions import ApiException from .exceptions import ApiException
from .extensions import db, migrate, jwt, apispec
from .settings import ProdConfig, Config
def create_app(config: Config = ProdConfig) -> Flask: def create_app(config: Config = ProdConfig) -> Flask:
@@ -78,6 +79,7 @@ def register_errorhandlers(app: Flask):
def register_shellcontext(app: Flask): def register_shellcontext(app: Flask):
"""Register shell context objects.""" """Register shell context objects."""
def shell_context(): def shell_context():
"""Shell context objects.""" """Shell context objects."""
return { return {

View File

@@ -1,12 +1,13 @@
import os import os
import click
import click
from flask import current_app from flask import current_app
from flask.cli import with_appcontext from flask.cli import with_appcontext
from werkzeug.exceptions import MethodNotAllowed, NotFound from werkzeug.exceptions import MethodNotAllowed, NotFound
from .target_exchange.models import TargetExchange from .target_exchange.models import TargetExchange
@click.command() @click.command()
def clean(): def clean():
"""Remove *.pyc and *.pyo files recursively starting at current directory. """Remove *.pyc and *.pyo files recursively starting at current directory.
@@ -82,6 +83,7 @@ def urls(url, order):
for row in rows: for row in rows:
click.echo(str_template.format(*row[:column_length])) click.echo(str_template.format(*row[:column_length]))
@click.command() @click.command()
@with_appcontext @with_appcontext
def seed(): def seed():

View File

@@ -1,2 +1,2 @@
API_PASS='API_PASS' API_PASS = 'API_PASS'
API_USER='super' API_USER = 'super'

View File

@@ -9,6 +9,7 @@ Column = db.Column
relationship = relationship relationship = relationship
Model = db.Model Model = db.Model
# From Mike Bayer's "Building the app" talk # From Mike Bayer's "Building the app" talk
# https://speakerdeck.com/zzzeek/building-the-app # https://speakerdeck.com/zzzeek/building-the-app
class SurrogatePK(object): class SurrogatePK(object):

View File

@@ -1,5 +1,6 @@
from flask import jsonify from flask import jsonify
class ApiException(Exception): class ApiException(Exception):
status_code = 500 status_code = 500
@@ -13,10 +14,12 @@ class ApiException(Exception):
rv.status_code = self.status_code rv.status_code = self.status_code
return rv return rv
class NotFoundException(ApiException): class NotFoundException(ApiException):
def __init__(self, entity_name) -> None: def __init__(self, entity_name) -> None:
super().__init__(404, f'{entity_name} could not be found') super().__init__(404, f'{entity_name} could not be found')
class BadRequestException(ApiException): class BadRequestException(ApiException):
def __init__(self, message) -> None: def __init__(self, message) -> None:
super().__init__(400, message) super().__init__(400, message)

View File

@@ -1,7 +1,8 @@
from flask_apispec import FlaskApiSpec
from flask_jwt_extended import JWTManager from flask_jwt_extended import JWTManager
from flask_migrate import Migrate from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy, Model from flask_sqlalchemy import SQLAlchemy, Model
from flask_apispec import FlaskApiSpec
class CRUDMixin(Model): class CRUDMixin(Model):
"""Mixin that adds convenience methods for CRUD (create, read, update, delete) operations.""" """Mixin that adds convenience methods for CRUD (create, read, update, delete) operations."""
@@ -30,6 +31,7 @@ class CRUDMixin(Model):
db.session.delete(self) db.session.delete(self)
return commit and db.session.commit() return commit and db.session.commit()
db = SQLAlchemy(model_class=CRUDMixin) db = SQLAlchemy(model_class=CRUDMixin)
migrate = Migrate() migrate = Migrate()
jwt = JWTManager() jwt = JWTManager()