linted code
This commit is contained in:
parent
67e13ffacd
commit
33dc5e14b5
@ -1,9 +1,11 @@
|
||||
from flask import Flask
|
||||
from the_works.database import init_db
|
||||
|
||||
# this import is not strictly necessary but it forces pipreqs-to include dotenv when generating `requirements.txt`
|
||||
import dotenv
|
||||
|
||||
from the_works.database import init_db
|
||||
from the_works.views import home, text, werk, verlag, sprache, textform, werksform, genre, pseudonym, reihe, herausgeber, veroeffentlichung, titelbild
|
||||
|
||||
#from flask_debugtoolbar import DebugToolbarExtension
|
||||
|
||||
def create_app(config=None):
|
||||
@ -28,7 +30,6 @@ def create_app(config=None):
|
||||
init_db(app)
|
||||
|
||||
# register blueprints
|
||||
from the_works.views import home, text, werk, verlag, sprache, textform, werksform, genre, pseudonym, reihe, herausgeber, veroeffentlichung, titelbild
|
||||
app.register_blueprint(genre.bp)
|
||||
app.register_blueprint(herausgeber.bp)
|
||||
app.register_blueprint(home.bp)
|
||||
@ -51,7 +52,7 @@ def create_app(config=None):
|
||||
|
||||
# helper function to print formatted file size; [source](https://stackoverflow.com/a/1094933)
|
||||
def sizeof_fmt(num: int | str, suffix: str = "B") -> str:
|
||||
if type(num) == str:
|
||||
if isinstance(num, str):
|
||||
num = int(num)
|
||||
for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"):
|
||||
if abs(num) < 1024.0:
|
||||
|
||||
@ -1,34 +1,13 @@
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from the_works.models import Base
|
||||
|
||||
# Instantiate the SQLAlchemy around the database schema's declarative mapping
|
||||
# Instantiate the SQLAlchemy around the database schema's declarative mapping
|
||||
db = SQLAlchemy(model_class=Base)
|
||||
|
||||
def init_db(app):
|
||||
# initialize the Flask app with the flask_sqlalchemy extension
|
||||
# initialize the Flask app with the flask_sqlalchemy extension
|
||||
db.init_app(app)
|
||||
|
||||
# create nonexistent tables in DB
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
"""
|
||||
# check if database is empty and if so, populate it with fresh tables
|
||||
#TODO: does it make sense to try and create all tables by default? Existing tables wouldn't be overwritten but what about DB constraints ?
|
||||
if not len(db.metadata.tables):
|
||||
# import table classes from code that was generated via `sqlacodegen --generator tables sqlite:///the_works.sqlite > ./the_works/tables.py` in project root
|
||||
import the_works.tables
|
||||
|
||||
# filter the objects just imported for those of type sqlalchemy.Table
|
||||
from sqlalchemy import Table
|
||||
table_list = list(filter(lambda t: type(t) == Table, vars(the_works.tables).values()))
|
||||
|
||||
# Table objects imported from sqlacodegen code are associated with a random MetaData() object, so we have to re-associate them with the DB's metadata
|
||||
table_list = list(map(lambda t: t.to_metadata(db.metadata), table_list))
|
||||
|
||||
# create tables in DB )
|
||||
db.metadata.create_all(db.engine)
|
||||
|
||||
# generate declarative table objects by reflecting the DB
|
||||
db.reflect()
|
||||
"""
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Genre
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Herausgeber
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Pseudonym
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Reihe, Verlag
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Sprache
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Textform
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Verlag
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Veroeffentlichung, Text, Werk, Werksform, Pseudonym
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, render_template, request, redirect, flash, url_for
|
||||
from sqlalchemy import select, insert, update, delete
|
||||
from sqlalchemy import select
|
||||
from the_works.database import db
|
||||
from the_works.models import Werksform
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user