From 64fe85272bd1a6f41f144e4157a5bfffeb3cbaa8 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Mon, 17 May 2021 22:36:24 +0200 Subject: [PATCH] Cleaned up with flake8 --- advlabdb/__init__.py | 11 +++++------ advlabdb/customClasses.py | 3 --- advlabdb/forms.py | 0 advlabdb/modelViews.py | 4 ++-- advlabdb/routes.py | 12 ++++++------ advlabdb/utils.py | 1 + copy_admin_templates.py | 2 ++ 7 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 advlabdb/forms.py diff --git a/advlabdb/__init__.py b/advlabdb/__init__.py index 956d044..13b7af5 100644 --- a/advlabdb/__init__.py +++ b/advlabdb/__init__.py @@ -3,13 +3,13 @@ from flask_sqlalchemy import SQLAlchemy from flask_security import Security, SQLAlchemyUserDatastore from flask_security.models import fsqla_v2 as fsqla from flask_admin import Admin -#DEBUG +# DEBUG from flask_debugtoolbar import DebugToolbarExtension app = Flask(__name__) -app.debug = True #DEBUG +app.debug = True # DEBUG -app.config["SERVER_NAME"] = "127.0.0.1:5000" #DEBUG +app.config["SERVER_NAME"] = "127.0.0.1:5000" # DEBUG app.config["SECRET_KEY"] = "dev" app.config["SECURITY_PASSWORD_SALT"] = "devSalt" # os.environ.get("SECURITY_PASSWORD_SALT", "") @@ -19,8 +19,8 @@ db = SQLAlchemy(app) fsqla.FsModels.set_db_info(db) -app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False #DEBUG -DebugToolbarExtension(app) #DEBUG +# app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False # DEBUG +# DebugToolbarExtension(app) # DEBUG from advlabdb import customClasses admin = Admin(app, @@ -35,5 +35,4 @@ user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role) Security(app, user_datastore) from advlabdb import routes -from advlabdb import forms from advlabdb import modelViews diff --git a/advlabdb/customClasses.py b/advlabdb/customClasses.py index 72f4812..b11f3e3 100644 --- a/advlabdb/customClasses.py +++ b/advlabdb/customClasses.py @@ -1,10 +1,7 @@ from flask_admin import AdminIndexView from flask_security import current_user -from flask import flash from flask_admin.contrib.sqla import ModelView -from advlabdb.utils import userActiveSemester - def adminViewIsAccessible(): return current_user.has_role("admin") diff --git a/advlabdb/forms.py b/advlabdb/forms.py deleted file mode 100644 index e69de29..0000000 diff --git a/advlabdb/modelViews.py b/advlabdb/modelViews.py index b99fc1f..b9cd7ee 100644 --- a/advlabdb/modelViews.py +++ b/advlabdb/modelViews.py @@ -1,4 +1,4 @@ -from flask import url_for, render_template, flash, request +from flask import url_for, flash, request from flask_admin.menu import MenuLink from flask_admin.contrib.sqla.filters import BaseSQLAFilter from flask_security import hash_password @@ -6,9 +6,9 @@ from wtforms import BooleanField, SelectField, TextField from wtforms.validators import DataRequired, Email from advlabdb import admin, app, user_datastore, db -from advlabdb.models import * from advlabdb.utils import randomPassword, userActiveSemester, partFromLabelInUserActiveSemester from advlabdb.customClasses import SecureModelView +from advlabdb.models import User, Role, Semester, Part, Student, PartStudent, Group, GroupExperiment, Experiment, Assistant, Appointment, PartExperiment, ExperimentMark partsLabels = ["A/1", "A/2", "A/m", "B/1", "B/2"] diff --git a/advlabdb/routes.py b/advlabdb/routes.py index 8863c6c..965ae40 100644 --- a/advlabdb/routes.py +++ b/advlabdb/routes.py @@ -1,11 +1,9 @@ -import json -from advlabdb import app, user_datastore +from advlabdb import app, db from flask import render_template, request, url_for, flash, redirect -from flask_security import auth_required, roles_required, hash_password, current_user +from flask_security import auth_required, current_user -from advlabdb.utils import * -from advlabdb.models import * -from advlabdb.forms import * +from advlabdb.utils import titleToTemplate, userActiveSemester +from advlabdb.models import Semester @app.context_processor @@ -63,6 +61,7 @@ def index(): else: return render_template("index.html") + """ @app.route("/assistants") @roles_required("admin") @@ -163,6 +162,7 @@ def deactivate_users(): return redirect(url_for("users")) """ + @app.route("/set_semester", methods=["GET"]) @auth_required() def set_semester(): diff --git a/advlabdb/utils.py b/advlabdb/utils.py index b3a348a..e4fa335 100644 --- a/advlabdb/utils.py +++ b/advlabdb/utils.py @@ -6,6 +6,7 @@ from flask import flash from advlabdb.models import Semester from advlabdb import db + def makeTable(headerAndDataList, rows, tableId="table"): def cellString(cell): cell = str(cell) diff --git a/copy_admin_templates.py b/copy_admin_templates.py index 0fd3aa7..9239e4d 100644 --- a/copy_admin_templates.py +++ b/copy_admin_templates.py @@ -2,6 +2,7 @@ from os.path import exists from shutil import copytree, rmtree from flask_admin import __file__ as flaskAdminPath + def copyAdminTemplates(): src = flaskAdminPath.removesuffix("__init__.py") + "templates/bootstrap3/admin" if not exists(src): @@ -25,6 +26,7 @@ def copyAdminTemplates(): print("Copied", src, "->", dist) return True + if __name__ == "__main__": if copyAdminTemplates(): print("Done!")