mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Apply flake8
This commit is contained in:
parent
ae665add07
commit
ef29ac8963
12 changed files with 30 additions and 46 deletions
|
@ -3,7 +3,7 @@ from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from flask import flash, has_request_context, redirect, request, url_for
|
from flask import flash, has_request_context, redirect, url_for
|
||||||
from flask_admin import expose
|
from flask_admin import expose
|
||||||
from flask_admin.contrib.sqla.fields import QuerySelectField, QuerySelectMultipleField
|
from flask_admin.contrib.sqla.fields import QuerySelectField, QuerySelectMultipleField
|
||||||
from flask_admin.contrib.sqla.filters import BooleanEqualFilter, FilterEqual
|
from flask_admin.contrib.sqla.filters import BooleanEqualFilter, FilterEqual
|
||||||
|
@ -28,7 +28,7 @@ from wtforms.fields import (
|
||||||
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
|
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
|
||||||
from wtforms.widgets import NumberInput
|
from wtforms.widgets import NumberInput
|
||||||
|
|
||||||
from . import adminSpace, app, assistantSpace, db, user_datastore
|
from . import adminSpace, assistantSpace, db, user_datastore
|
||||||
from .admin_link_formatters import (
|
from .admin_link_formatters import (
|
||||||
admin_formatter,
|
admin_formatter,
|
||||||
appointment_date_formatter,
|
appointment_date_formatter,
|
||||||
|
@ -58,7 +58,7 @@ from .advlabdb_independent_funs import (
|
||||||
)
|
)
|
||||||
from .customClasses import SecureAdminBaseView, SecureAdminModelView
|
from .customClasses import SecureAdminBaseView, SecureAdminModelView
|
||||||
from .database_import import importFromFile
|
from .database_import import importFromFile
|
||||||
from .exceptions import DataBaseException, ModelViewException
|
from .exceptions import ModelViewException
|
||||||
from .model_dependent_funs import (
|
from .model_dependent_funs import (
|
||||||
generate_new_password_field,
|
generate_new_password_field,
|
||||||
initActiveSemesterMenuLinks,
|
initActiveSemesterMenuLinks,
|
||||||
|
@ -1337,7 +1337,7 @@ class AnalysisView(SecureAdminBaseView):
|
||||||
title += f"\nN = {N}"
|
title += f"\nN = {N}"
|
||||||
|
|
||||||
if N > 0:
|
if N > 0:
|
||||||
hist = ax.hist(
|
ax.hist(
|
||||||
data,
|
data,
|
||||||
bins=np.arange(MAX_MARK) - 0.5,
|
bins=np.arange(MAX_MARK) - 0.5,
|
||||||
)
|
)
|
||||||
|
@ -1423,7 +1423,6 @@ class AnalysisView(SecureAdminBaseView):
|
||||||
]
|
]
|
||||||
|
|
||||||
semesters = Semester.sortedSemestersStartingWithNewest()
|
semesters = Semester.sortedSemestersStartingWithNewest()
|
||||||
semesterLabels = [str(semester) for semester in semesters]
|
|
||||||
meanFinalPartMarks = np.flip(
|
meanFinalPartMarks = np.flip(
|
||||||
[
|
[
|
||||||
np.mean(
|
np.mean(
|
||||||
|
|
|
@ -27,14 +27,6 @@ def deep_getattr(object, composed_name):
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
|
|
||||||
def missing_formatter(view, context, model, name):
|
|
||||||
attr = deep_getattr(model, name)
|
|
||||||
if attr is None:
|
|
||||||
return Markup("<span style='color: red;'>MISSING</span>")
|
|
||||||
|
|
||||||
return attr
|
|
||||||
|
|
||||||
|
|
||||||
def str_without_semester_formatter(view, context, model, name):
|
def str_without_semester_formatter(view, context, model, name):
|
||||||
attr = deep_getattr(model, name)
|
attr = deep_getattr(model, name)
|
||||||
|
|
||||||
|
|
|
@ -3,40 +3,25 @@ from flask_admin import expose
|
||||||
from flask_admin.model.template import EndpointLinkRowAction
|
from flask_admin.model.template import EndpointLinkRowAction
|
||||||
from flask_security import admin_change_password, current_user
|
from flask_security import admin_change_password, current_user
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from markupsafe import Markup
|
|
||||||
from wtforms.fields import TextAreaField
|
|
||||||
from wtforms.validators import Optional
|
|
||||||
|
|
||||||
from . import assistantSpace, db
|
from . import assistantSpace, db
|
||||||
from .advlabdb_independent_funs import (
|
from .advlabdb_independent_funs import (
|
||||||
deep_getattr,
|
deep_getattr,
|
||||||
experiment_marks_missing_formatter,
|
experiment_marks_missing_formatter,
|
||||||
flashRandomPassword,
|
flashRandomPassword,
|
||||||
missing_formatter,
|
|
||||||
str_formatter,
|
str_formatter,
|
||||||
str_without_semester_formatter,
|
|
||||||
)
|
)
|
||||||
from .customClasses import SecureAssistantBaseView, SecureAssistantModelView
|
from .customClasses import SecureAssistantBaseView, SecureAssistantModelView
|
||||||
from .exceptions import DataBaseException, ModelViewException
|
from .exceptions import ModelViewException
|
||||||
from .forms import assistant_group_experiment_form_factory
|
from .forms import assistant_group_experiment_form_factory
|
||||||
from .model_dependent_funs import (
|
from .model_dependent_funs import (
|
||||||
generate_new_password_field,
|
generate_new_password_field,
|
||||||
initActiveSemesterMenuLinks,
|
initActiveSemesterMenuLinks,
|
||||||
mark_field,
|
|
||||||
parse_selection_mark_field,
|
parse_selection_mark_field,
|
||||||
user_info_fields,
|
user_info_fields,
|
||||||
)
|
)
|
||||||
from .model_independent_funs import randomPassword, reportBadAttempt
|
from .model_independent_funs import randomPassword, reportBadAttempt
|
||||||
from .models import (
|
from .models import Assistant, GroupExperiment, SemesterExperiment, User
|
||||||
MAX_MARK,
|
|
||||||
MIN_MARK,
|
|
||||||
Appointment,
|
|
||||||
Assistant,
|
|
||||||
ExperimentMark,
|
|
||||||
GroupExperiment,
|
|
||||||
SemesterExperiment,
|
|
||||||
User,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AssistantGroupExperimentView(SecureAssistantModelView):
|
class AssistantGroupExperimentView(SecureAssistantModelView):
|
||||||
|
@ -103,7 +88,7 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
group_experiment = db.session.get(GroupExperiment, int(group_experiment_id_str))
|
group_experiment = db.session.get(GroupExperiment, int(group_experiment_id_str))
|
||||||
except:
|
except Exception:
|
||||||
red = url_for("index") + "assistant/group_experiment"
|
red = url_for("index") + "assistant/group_experiment"
|
||||||
flash("No valid group experiment id")
|
flash("No valid group experiment id")
|
||||||
return redirect(red)
|
return redirect(red)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from flask_admin.contrib.sqla import ModelView
|
||||||
from flask_admin.helpers import get_form_data
|
from flask_admin.helpers import get_form_data
|
||||||
from flask_admin.model.helpers import get_mdict_item_or_list
|
from flask_admin.model.helpers import get_mdict_item_or_list
|
||||||
from flask_security import current_user
|
from flask_security import current_user
|
||||||
from sqlalchemy import and_, select
|
from sqlalchemy import select
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .exceptions import DataBaseException, ModelViewException
|
from .exceptions import DataBaseException, ModelViewException
|
||||||
|
|
|
@ -25,7 +25,7 @@ def initActiveSemesterMenuLinks(space):
|
||||||
category="Active semester",
|
category="Active semester",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
print(
|
print(
|
||||||
"ERROR: The Semester table does not exist yet! Therefore, menu links could not be generated. You can ignore this error if you are just initializing the database."
|
"ERROR: The Semester table does not exist yet! Therefore, menu links could not be generated. You can ignore this error if you are just initializing the database."
|
||||||
)
|
)
|
||||||
|
@ -33,10 +33,6 @@ def initActiveSemesterMenuLinks(space):
|
||||||
space.add_link(MenuLink(name="Logout", url=url_for("security.logout")))
|
space.add_link(MenuLink(name="Logout", url=url_for("security.logout")))
|
||||||
|
|
||||||
|
|
||||||
def get_count(table):
|
|
||||||
return db.session.scalar(select(func.count()).select_from(table))
|
|
||||||
|
|
||||||
|
|
||||||
def active_semester_str():
|
def active_semester_str():
|
||||||
active_semester = current_user.active_semester
|
active_semester = current_user.active_semester
|
||||||
active_semester_str = str(active_semester)
|
active_semester_str = str(active_semester)
|
||||||
|
@ -65,7 +61,7 @@ def selection_mark_field_choices():
|
||||||
def selection_mark_field(mark_type: str, default):
|
def selection_mark_field(mark_type: str, default):
|
||||||
choices = selection_mark_field_choices()
|
choices = selection_mark_field_choices()
|
||||||
|
|
||||||
if default == None:
|
if default is None:
|
||||||
default = -1
|
default = -1
|
||||||
|
|
||||||
return SelectField(
|
return SelectField(
|
||||||
|
|
|
@ -663,7 +663,7 @@ class User(db.Model, FsUserMixin):
|
||||||
|
|
||||||
def setActiveSemester(self, semester):
|
def setActiveSemester(self, semester):
|
||||||
if semester is None:
|
if semester is None:
|
||||||
flash(f"Can not change the active semester to None!", "error")
|
flash("Can not change the active semester to None!", "error")
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.active_semester != semester:
|
if self.active_semester != semester:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from flask import flash, redirect, render_template, request, url_for
|
from flask import flash, redirect, request, url_for
|
||||||
from flask_security import auth_required, current_user, roles_accepted, roles_required
|
from flask_security import auth_required, current_user
|
||||||
|
|
||||||
from . import app, db
|
from . import app, db
|
||||||
from .model_dependent_funs import active_semester_str
|
from .model_dependent_funs import active_semester_str
|
||||||
|
|
|
@ -4,7 +4,7 @@ from sqlalchemy import select
|
||||||
from ... import app, db
|
from ... import app, db
|
||||||
from ...model_independent_funs import randomPassword
|
from ...model_independent_funs import randomPassword
|
||||||
from ...models import Admin, User
|
from ...models import Admin, User
|
||||||
from ..terminal_utils import box, spaced_hl, validating_input
|
from ..terminal_utils import box, validating_input
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -40,7 +40,7 @@ def main():
|
||||||
db.session.add(semester)
|
db.session.add(semester)
|
||||||
|
|
||||||
adminRole = user_datastore.create_role(name="admin")
|
adminRole = user_datastore.create_role(name="admin")
|
||||||
assistantRole = user_datastore.create_role(name="assistant")
|
user_datastore.create_role(name="assistant")
|
||||||
|
|
||||||
box("The first admin account will now be created")
|
box("The first admin account will now be created")
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ def validating_input(
|
||||||
ans = input(prompt)
|
ans = input(prompt)
|
||||||
try:
|
try:
|
||||||
ans = format_function(ans)
|
ans = format_function(ans)
|
||||||
except Exception as ex:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
done_validation = True
|
done_validation = True
|
||||||
|
|
|
@ -31,7 +31,6 @@ If you want to clean up after testing with the container, run the following:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from getpass import getpass
|
|
||||||
|
|
||||||
|
|
||||||
def run(command, **kwargs):
|
def run(command, **kwargs):
|
||||||
|
|
|
@ -3,7 +3,20 @@ from datetime import date
|
||||||
from flask_security import hash_password
|
from flask_security import hash_password
|
||||||
|
|
||||||
from ... import app, db, user_datastore
|
from ... import app, db, user_datastore
|
||||||
from ...models import *
|
from ...models import (
|
||||||
|
Admin,
|
||||||
|
Appointment,
|
||||||
|
Assistant,
|
||||||
|
Experiment,
|
||||||
|
Group,
|
||||||
|
GroupExperiment,
|
||||||
|
Part,
|
||||||
|
PartStudent,
|
||||||
|
Program,
|
||||||
|
Semester,
|
||||||
|
SemesterExperiment,
|
||||||
|
Student,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue