1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Rename database exception

This commit is contained in:
Mo 2022-08-10 01:14:47 +02:00
parent 75a639d278
commit 2d045710ff
3 changed files with 15 additions and 15 deletions

View file

@ -6,7 +6,7 @@ from flask_admin.model.helpers import get_mdict_item_or_list
from flask_security import current_user
from sqlalchemy import select
from .exceptions import DataBaseException, ModelViewException
from .exceptions import DatabaseException, ModelViewException
from .model_independent_funs import reportBadAttempt
from .models import (
Assistant,
@ -134,7 +134,7 @@ class CustomModelView(ModelView):
return self.query_modifier(super().get_count_query())
def handle_view_exception(self, exc):
if type(exc) in (ModelViewException, DataBaseException):
if type(exc) in (ModelViewException, DatabaseException):
flash(str(exc), "error")
return True

View file

@ -2,7 +2,7 @@ class ModelViewException(Exception):
pass
class DataBaseException(Exception):
class DatabaseException(Exception):
pass

View file

@ -15,7 +15,7 @@ from flask_security.models.fsqla_v2 import FsRoleMixin, FsUserMixin
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import func, select
from .exceptions import DataBaseException
from .exceptions import DatabaseException
MIN_MARK = 0
MAX_MARK = 15
@ -99,7 +99,7 @@ class PartStudent(db.Model):
@staticmethod
def check(part, group):
if group is not None and group.program != part.program:
raise DataBaseException(
raise DatabaseException(
f"Group's program {group.program} and student part's program {part.program} do not match!"
)
@ -199,11 +199,11 @@ class Group(db.Model):
commonProgram = part_students[0].part.program
if program and program != commonProgram:
raise DataBaseException("Group's program and students' program mismatch!")
raise DatabaseException("Group's program and students' program mismatch!")
for partStudent in part_students[1:]:
if partStudent.part.program != commonProgram:
raise DataBaseException(f"Part Students {part_students} are not in the same program!")
raise DatabaseException(f"Part Students {part_students} are not in the same program!")
@staticmethod
def customInit(part_students):
@ -259,7 +259,7 @@ class GroupExperiment(db.Model):
for partStudent in student.part_students:
for experimentMark in partStudent.experiment_marks:
if experimentMark.group_experiment.semester_experiment.experiment == semester_experiment.experiment:
raise DataBaseException(
raise DatabaseException(
f"{student} has already done {semester_experiment.experiment} in {partStudent.part} and had {experimentMark}!"
)
@ -366,7 +366,7 @@ class SemesterExperiment(db.Model):
weightingSum = round(roundedOralWeighting + roundedProtocolWeighting, 2)
if weightingSum != 1:
raise DataBaseException(
raise DatabaseException(
f"Oral and protocol weightings (rounded to 2 decimal digits) sum to {weightingSum} and not 1.00!"
)
@ -441,16 +441,16 @@ class Appointment(db.Model):
semesterExperimentAssistants = semesterExperiment.assistants
if semesterExperimentAssistants is None:
raise DataBaseException(f"{semesterExperiment} does not have assistants yet!")
raise DatabaseException(f"{semesterExperiment} does not have assistants yet!")
if assistant is not None:
if assistant not in semesterExperimentAssistants:
raise DataBaseException(f"{assistant} is not responsible for {semesterExperiment}!")
raise DatabaseException(f"{assistant} is not responsible for {semesterExperiment}!")
else:
if len(semesterExperimentAssistants) == 1:
assistant = semesterExperimentAssistants[0]
else:
raise DataBaseException(
raise DatabaseException(
f"Experiment {semesterExperiment} has more than one assistant. You have to assign one of these assistants: {semesterExperimentAssistants}"
)
@ -520,7 +520,7 @@ class Semester(db.Model):
if last_semester is not None:
if year < last_semester.year or (year == last_semester.year and label == "SS"):
raise DataBaseException(f"You can only create semesters older than the last semester {last_semester}!")
raise DatabaseException(f"You can only create semesters older than the last semester {last_semester}!")
super().__init__(label=label, year=year)
@ -609,10 +609,10 @@ class ExperimentMark(db.Model):
@staticmethod
def check(part_student, group_experiment):
if not part_student.group:
raise DataBaseException("The part student does not have a group yet!")
raise DatabaseException("The part student does not have a group yet!")
else:
if group_experiment not in part_student.group.group_experiments:
raise DataBaseException("The group of the part student does not have the given group experiment!")
raise DatabaseException("The group of the part student does not have the given group experiment!")
def __init__(self, part_student, group_experiment):
ExperimentMark.check(part_student, group_experiment)