main #12

Merged
crunk merged 49 commits from Toolsheds/distribusi-verse:main into main 2024-07-03 13:48:57 +02:00
38 changed files with 1387 additions and 1349 deletions
Showing only changes of commit 23ac3e7699 - Show all commits

View File

@ -1,25 +1,49 @@
[tool.black] [tool.ruff]
line-length = 79 line-length = 79
target-version = ['py311'] target-version = "py311"
include = '\.pyi?$' #include = '\.pyi?$'
exclude = ''' exclude = [
/( ".bzr",
\.eggs ".direnv",
| \.git ".eggs",
| \.hg ".git",
| \.mypy_cache ".git-rewrite",
| \.tox ".hg",
| \.venv ".ipynb_checkpoints",
| _build ".mypy_cache",
| buck-out ".nox",
| build ".pants.d",
| dist ".pyenv",
".pytest_cache",
# The following are specific to Black, you probably don't want those. ".pytype",
| blib2to3 ".ruff_cache",
| tests/data ".svn",
| profiling ".tox",
)/ ".venv",
''' ".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F"]
ignore = []
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.format]
quote-style = "double"
indent-style = "tab"
docstring-code-format = true
line-ending = "auto"
skip-magic-trailing-comma = false

View File

@ -2,6 +2,7 @@ from flask import Blueprint, render_template, redirect, url_for
from flask_login import current_user from flask_login import current_user
from models.distribusi_model import Distribusis from models.distribusi_model import Distribusis
from models.distribusi_file_model import DistribusiFiles from models.distribusi_file_model import DistribusiFiles
from describer.forms.describe_file_form import DescribeFileForm
describer = Blueprint( describer = Blueprint(
"describer", "describer",
@ -21,4 +22,11 @@ def describe_distribusi_files(distribusiname):
distribusi_files = DistribusiFiles.query.filter_by( distribusi_files = DistribusiFiles.query.filter_by(
distribusi=distribusi.id distribusi=distribusi.id
).all() ).all()
return render_template("describe.html", distribusi_files=distribusi_files) # distribusi_file_forms = {}
# for distribusi_file in distribusi_files:
describe_form = DescribeFileForm()
return render_template(
"describe.html",
distribusi_files=distribusi_files,
describe_form=describe_form,
)

View File

@ -4,6 +4,7 @@ from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, validators from wtforms import StringField, SubmitField, validators
from wtforms.validators import Length from wtforms.validators import Length
class DescribeFileForm(FlaskForm): class DescribeFileForm(FlaskForm):
"""DescribeFileForm selection form.""" """DescribeFileForm selection form."""

View File

@ -22,10 +22,12 @@ def _distribusi_file_with_type(distribusi, full_path):
if type_ in FILE_TYPES: if type_ in FILE_TYPES:
_add_distribusi_file_to_db(distribusi, full_path, type_) _add_distribusi_file_to_db(distribusi, full_path, type_)
def _get_distribusi_from_path(path): def _get_distribusi_from_path(path):
distribusi = Distribusis.query.filter_by(distribusiname=path).first() distribusi = Distribusis.query.filter_by(distribusiname=path).first()
return distribusi return distribusi
def _add_distribusi_file_to_db(distribusi, full_path, type): def _add_distribusi_file_to_db(distribusi, full_path, type):
app = get_app() app = get_app()
print(f"adding file to database: {full_path} type: {type}") print(f"adding file to database: {full_path} type: {type}")
@ -49,14 +51,10 @@ def _add_distribusi_file_to_db(distribusi, full_path, type):
app.logger.error("%s Invalid Entry", full_path) app.logger.error("%s Invalid Entry", full_path)
except InterfaceError: except InterfaceError:
db.session.rollback() db.session.rollback()
app.logger.error( app.logger.error("Error connecting to the database")
"Error connecting to the database"
)
except DatabaseError: except DatabaseError:
db.session.rollback() db.session.rollback()
app.logger.error( app.logger.error("Error connecting to the database")
"Error connecting to the database"
)
def add_distribusi_files(path): def add_distribusi_files(path):

View File

@ -14,17 +14,19 @@ config = context.config
# Interpret the config file for Python logging. # Interpret the config file for Python logging.
# This line sets up loggers basically. # This line sets up loggers basically.
fileConfig(config.config_file_name) fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env') logger = logging.getLogger("alembic.env")
# add your model's MetaData object here # add your model's MetaData object here
# for 'autogenerate' support # for 'autogenerate' support
# from myapp import mymodel # from myapp import mymodel
# target_metadata = mymodel.Base.metadata # target_metadata = mymodel.Base.metadata
config.set_main_option( config.set_main_option(
'sqlalchemy.url', "sqlalchemy.url",
str(current_app.extensions['migrate'].db.get_engine().url).replace( str(current_app.extensions["migrate"].db.get_engine().url).replace(
'%', '%%')) "%", "%%"
target_metadata = current_app.extensions['migrate'].db.metadata ),
)
target_metadata = current_app.extensions["migrate"].db.metadata
# other values from the config, defined by the needs of env.py, # other values from the config, defined by the needs of env.py,
# can be acquired: # can be acquired:
@ -65,20 +67,20 @@ def run_migrations_online():
# when there are no changes to the schema # when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives): def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False): if getattr(config.cmd_opts, "autogenerate", False):
script = directives[0] script = directives[0]
if script.upgrade_ops.is_empty(): if script.upgrade_ops.is_empty():
directives[:] = [] directives[:] = []
logger.info('No changes in schema detected.') logger.info("No changes in schema detected.")
connectable = current_app.extensions['migrate'].db.get_engine() connectable = current_app.extensions["migrate"].db.get_engine()
with connectable.connect() as connection: with connectable.connect() as connection:
context.configure( context.configure(
connection=connection, connection=connection,
target_metadata=target_metadata, target_metadata=target_metadata,
process_revision_directives=process_revision_directives, process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args **current_app.extensions["migrate"].configure_args,
) )
with context.begin_transaction(): with context.begin_transaction():

View File

@ -2,8 +2,14 @@
from datetime import timedelta from datetime import timedelta
from flask import (Blueprint, redirect, render_template, send_from_directory, from flask import (
session, url_for) Blueprint,
redirect,
render_template,
send_from_directory,
session,
url_for,
)
from flask_login import current_user, login_required, logout_user from flask_login import current_user, login_required, logout_user
from flask_wtf.csrf import CSRFError from flask_wtf.csrf import CSRFError
@ -31,7 +37,6 @@ APP.register_blueprint(forgot_password, url_prefix="/login/forgotpassword")
APP.register_blueprint(distribusikan) APP.register_blueprint(distribusikan)
@APP.before_request @APP.before_request
def session_handler(): def session_handler():
session.permanent = True session.permanent = True
@ -56,7 +61,7 @@ def index():
distribusisindex[distribusi.distribusiname] = singledistribusi distribusisindex[distribusi.distribusiname] = singledistribusi
years = uploadform.year.choices years = uploadform.year.choices
categories = uploadform.category.choices categories = uploadform.category.choices
adminuser = isadminuser() adminuser = is_adminuser()
template = render_template( template = render_template(
"base/index.html", "base/index.html",
distribusisindex=distribusisindex, distribusisindex=distribusisindex,
@ -88,7 +93,7 @@ def shortstashurl():
@APP.route("/admin", methods=["GET", "POST"]) @APP.route("/admin", methods=["GET", "POST"])
@login_required @login_required
def admin(): def admin():
if not isadminuser(): if not is_adminuser():
return redirect(url_for("index")) return redirect(url_for("index"))
return AdminPage() return AdminPage()
@ -110,7 +115,7 @@ def load_user(user_id):
return User.query.get(int(user_id)) return User.query.get(int(user_id))
def isadminuser(): def is_adminuser():
if not current_user.is_authenticated: if not current_user.is_authenticated:
return False return False
user = User.query.filter_by(email=current_user.email).first() user = User.query.filter_by(email=current_user.email).first()