From bbf2fcf047c074c019022be44695f7c9f2f0b4e9 Mon Sep 17 00:00:00 2001 From: crunk Date: Sun, 19 May 2024 11:29:40 +0200 Subject: [PATCH] ruff refactoring --- verse/app.py | 1 - verse/describer/describe_files.py | 6 ++++-- verse/describer/forms/describe_file_form.py | 4 ++-- verse/describer/templates/describe_files/describe.html | 2 +- verse/distribusikan/distribusikan.py | 1 - verse/distribusikan/distribusiselector.py | 4 +--- verse/file_crawler.py | 2 +- verse/forms/registerform.py | 2 +- verse/forms/uploadform.py | 2 -- verse/start.py | 1 - verse/statuspengguna/loginuser.py | 2 -- verse/statuspengguna/resetpassword.py | 3 +-- 12 files changed, 11 insertions(+), 19 deletions(-) diff --git a/verse/app.py b/verse/app.py index eb49b8e..529db20 100644 --- a/verse/app.py +++ b/verse/app.py @@ -64,7 +64,6 @@ def get_app(): def settings_from_file(): - settings = {} if os.path.isfile("settings_development.toml"): with open("settings_development.toml", "rb") as settings_file: return tomllib.load(settings_file) diff --git a/verse/describer/describe_files.py b/verse/describer/describe_files.py index ac41c4d..28154f1 100644 --- a/verse/describer/describe_files.py +++ b/verse/describer/describe_files.py @@ -1,4 +1,5 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, redirect, url_for +from flask_login import current_user from models.distribusi_model import Distribusis from models.distribusi_file_model import DistribusiFiles @@ -12,11 +13,12 @@ describer = Blueprint( @describer.route("/") def describe_distribusi_files(distribusiname): + if not current_user.is_authenticated: + return redirect(url_for("index")) distribusi = Distribusis.query.filter_by( distribusiname=distribusiname ).first() distribusi_files = DistribusiFiles.query.filter_by( distribusi=distribusi.id ).all() - print(distribusi_files) return render_template("describe.html", distribusi_files=distribusi_files) diff --git a/verse/describer/forms/describe_file_form.py b/verse/describer/forms/describe_file_form.py index a61ab4c..286c448 100644 --- a/verse/describer/forms/describe_file_form.py +++ b/verse/describer/forms/describe_file_form.py @@ -1,8 +1,8 @@ """Describe File Form to describe files in the distribusi archive""" from flask_wtf import FlaskForm -from wtforms import StringField, SubmitField - +from wtforms import StringField, SubmitField, validators +from wtforms.validators import Length class DescribeFileForm(FlaskForm): """DescribeFileForm selection form.""" diff --git a/verse/describer/templates/describe_files/describe.html b/verse/describer/templates/describe_files/describe.html index 700d154..22b486d 100644 --- a/verse/describer/templates/describe_files/describe.html +++ b/verse/describer/templates/describe_files/describe.html @@ -28,7 +28,7 @@
{% for file in distribusi_files %} -

{{file}}

+

{{file.path}}

{% endfor%}
{% endblock %} diff --git a/verse/distribusikan/distribusikan.py b/verse/distribusikan/distribusikan.py index 4ba50ae..444cb96 100644 --- a/verse/distribusikan/distribusikan.py +++ b/verse/distribusikan/distribusikan.py @@ -4,7 +4,6 @@ from flask_login import login_required from distribusikan.distribusiselector import DistribusiSelector # Distribusi Information -from distribusikan.distribusisinfo import DistribusisInfo from distribusikan.distribusiworkflow import DistribusiWorkflow from distribusikan.editor import Editor from distribusikan.themeselector import ThemeSelector diff --git a/verse/distribusikan/distribusiselector.py b/verse/distribusikan/distribusiselector.py index 2ceb8fc..ea55d43 100644 --- a/verse/distribusikan/distribusiselector.py +++ b/verse/distribusikan/distribusiselector.py @@ -10,9 +10,8 @@ from sqlalchemy.exc import ( InvalidRequestError, ) -from app import db, get_app +from app import db from distribusikan.distribusisinfo import DistribusisInfo -from describer.describe_files import describe_distribusi_files from forms.distribusiform import DistribusiForm from forms.publicthemeform import PublicThemeForm from forms.selectorform import SelectorForm @@ -68,7 +67,6 @@ def SelectNewDistribusi(): def SelectDescribeDistribusi(distribusiname): - app = get_app return redirect( url_for( "describer.describe_distribusi_files", diff --git a/verse/file_crawler.py b/verse/file_crawler.py index 0a38280..b395138 100644 --- a/verse/file_crawler.py +++ b/verse/file_crawler.py @@ -1,7 +1,7 @@ import os import magic -from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES +from distribusi.mappings import FILE_TYPES from models.distribusi_model import Distribusis from models.distribusi_file_model import DistribusiFiles from app import create_app, get_app, db diff --git a/verse/forms/registerform.py b/verse/forms/registerform.py index cca23ab..89c42d6 100644 --- a/verse/forms/registerform.py +++ b/verse/forms/registerform.py @@ -2,7 +2,7 @@ from flask_wtf import FlaskForm from wtforms import PasswordField, StringField, SubmitField, validators -from wtforms.validators import Email, EqualTo, Length, ValidationError +from wtforms.validators import Email, EqualTo, Length class RegisterForm(FlaskForm): diff --git a/verse/forms/uploadform.py b/verse/forms/uploadform.py index 261d1cd..90dcd70 100644 --- a/verse/forms/uploadform.py +++ b/verse/forms/uploadform.py @@ -1,7 +1,6 @@ from flask_wtf import FlaskForm from flask_wtf.file import FileAllowed, FileField, FileRequired, FileSize from wtforms import ( - IntegerField, SelectField, StringField, SubmitField, @@ -10,7 +9,6 @@ from wtforms import ( from wtforms.validators import ( DataRequired, Length, - NumberRange, ValidationError, ) diff --git a/verse/start.py b/verse/start.py index 33be140..91a7c8e 100644 --- a/verse/start.py +++ b/verse/start.py @@ -5,7 +5,6 @@ from datetime import timedelta from flask import (Blueprint, redirect, render_template, send_from_directory, session, url_for) from flask_login import current_user, login_required, logout_user -from flask_mail import Mail from flask_wtf.csrf import CSRFError from adminpage import AdminPage diff --git a/verse/statuspengguna/loginuser.py b/verse/statuspengguna/loginuser.py index 5d72063..6f18cde 100644 --- a/verse/statuspengguna/loginuser.py +++ b/verse/statuspengguna/loginuser.py @@ -5,8 +5,6 @@ from flask import ( redirect, render_template, request, - send_from_directory, - session, url_for, ) from flask_bcrypt import check_password_hash diff --git a/verse/statuspengguna/resetpassword.py b/verse/statuspengguna/resetpassword.py index a75f86e..c0288ae 100644 --- a/verse/statuspengguna/resetpassword.py +++ b/verse/statuspengguna/resetpassword.py @@ -1,6 +1,6 @@ from datetime import datetime -from flask import flash, redirect, render_template, url_for +from flask import Blueprint, flash, redirect, render_template, url_for from flask_bcrypt import generate_password_hash from flask_login import login_user from sqlalchemy.exc import ( @@ -15,7 +15,6 @@ from werkzeug.routing import BuildError from app import db from forms.resetpasswordform import ResetPasswordForm from models.user_model import User -from statuspengguna import statuspengguna reset_password = Blueprint( "reset_password",