diff --git a/src/spz/administration/admin_views.py b/src/spz/administration/admin_views.py index 62e085c..128913b 100644 --- a/src/spz/administration/admin_views.py +++ b/src/spz/administration/admin_views.py @@ -253,11 +253,12 @@ def edit_grade(course_id): exam_date = app.config['EXAM_DATE'] + # ToDo: assign course ects when applicant registers for course # temporary quickfix for applicant in course.course_list: - if applicant.ects_points == 0: - applicant.ects_points = course.ects_points + if course.get_course_attendance(course.id, applicant.id).ects_points == 0: + course.get_course_attendance(course.id, applicant.id).ects_points = course.ects_points db.session.commit() if request.method == 'POST' and form.validate(): @@ -272,8 +273,8 @@ def edit_grade(course_id): ects_field_name = f'ects_{applicant.id}' if ects_field_name in request.form: submitted_ects = int(request.form[ects_field_name]) - if submitted_ects != applicant.ects_points: - applicant.ects_points = submitted_ects + if submitted_ects != course.get_course_attendance(course.id, applicant.id).ects_points: + course.get_course_attendance(course.id, applicant.id).ects_points = submitted_ects changes = True if changes: @@ -316,7 +317,7 @@ def edit_grade_view(course_id): flash(_('Es ist ein Fehler beim Abspeichern der Bestanden-Attribute aufgetreten: %(error)s', error=e), 'negative') - return redirect(url_for('grade', id=id, course_id=course_id)) + return redirect(url_for('grade', course_id=course_id)) return dict(course=course, exam_date=exam_date) diff --git a/src/spz/models.py b/src/spz/models.py index 443bd8d..36568da 100644 --- a/src/spz/models.py +++ b/src/spz/models.py @@ -102,6 +102,8 @@ class Attendance(db.Model): graduation_id = db.Column(db.Integer, db.ForeignKey('graduation.id')) graduation = db.relationship("Graduation", backref="attendances", lazy="joined") + ects_points = db.Column(db.Integer, nullable=False, default=0) + waiting = db.Column(db.Boolean) # do not change, please use the set_waiting_status function discount = db.Column(db.Numeric(precision=3)) amountpaid = db.Column(db.Numeric(precision=5, scale=2), nullable=False) @@ -121,6 +123,7 @@ class Attendance(db.Model): def __init__(self, course, graduation, waiting, discount, informed_about_rejection=False): self.course = course self.graduation = graduation + self.ects_points = course.ects_points self.waiting = waiting self.discount = discount self.paidbycash = False @@ -211,7 +214,6 @@ class Applicant(db.Model): # internal representation of the grade is in % grade = db.Column(db.Integer, nullable=True) # TODO store grade encrypted - ects_points = db.Column(db.Integer, nullable=True, default=0) # if a student only wants 'bestanden' instead of the grade value, is set to true hide_grade = db.Column(db.Boolean, nullable=False, default=False) @@ -519,6 +521,11 @@ def get_waiting_attendances(self): def get_active_attendances(self): return [attendance for attendance in self.attendances if not attendance.waiting] + def get_course_attendance(self, course_id, applicant_id): + attendances = [attendance for attendance in self.attendances if + (attendance.course_id == course_id and attendance.applicant_id == applicant_id)] + return attendances[0] if attendances else None + @hybrid_method def count_attendances(self, *args, **kw): return len(self.filter_attendances(*args, **kw)) diff --git a/src/spz/templates/internal/administration/edit_grade.html b/src/spz/templates/internal/administration/edit_grade.html index 1564812..87787b8 100644 --- a/src/spz/templates/internal/administration/edit_grade.html +++ b/src/spz/templates/internal/administration/edit_grade.html @@ -40,17 +40,23 @@