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 @@

Schritt 1:

{{ applicant.first_name }} {{ applicant.last_name }} - {% if course.ects_points == 2 %} - + {% if course.get_course_attendance(course.id, applicant.id) is none %} + Fehler: nicht in Liste {% else %} - {{ applicant.ects_points }} + {% if course.ects_points == 2 %} + + {% else %} + {{ course.get_course_attendance(course.id, applicant.id).ects_points }} + {% endif %} {% endif %} diff --git a/src/spz/templates/internal/administration/edit_grade_view.html b/src/spz/templates/internal/administration/edit_grade_view.html index d62db6b..0bc5565 100644 --- a/src/spz/templates/internal/administration/edit_grade_view.html +++ b/src/spz/templates/internal/administration/edit_grade_view.html @@ -40,7 +40,7 @@

Schritt 2:

{{ applicant.first_name }} {{ applicant.last_name }} - {{ applicant.ects_points }} + {{ course.get_course_attendance(course.id, applicant.id).ects_points }} {% if applicant.grade is none %} diff --git a/src/spz/templates/internal/administration/grade.html b/src/spz/templates/internal/administration/grade.html index a41b412..40f5074 100644 --- a/src/spz/templates/internal/administration/grade.html +++ b/src/spz/templates/internal/administration/grade.html @@ -9,11 +9,11 @@ {% block internal_body %} {% if current_user.is_teacher %} -
- - - -
+
+ + + +
{% endif %}
@@ -41,10 +41,16 @@

Notenübersicht

{% for applicant in course.course_list %} - {% if applicant.tag %} {{applicant.tag }} {% endif %} + {% if applicant.tag %} {{ applicant.tag }} {% endif %} {{ applicant.first_name }} {{ applicant.last_name }} - {{ applicant.ects_points }} + + {% if course.get_course_attendance(course.id, applicant.id) is none %} + Fehler: nicht in Liste + {% else %} + {{ course.get_course_attendance(course.id, applicant.id).ects_points }} + {% endif %} + {% if applicant.grade is not none %} {% if applicant.hide_grade %} diff --git a/src/spz/views.py b/src/spz/views.py index 7fb36bf..4b19e62 100644 --- a/src/spz/views.py +++ b/src/spz/views.py @@ -320,7 +320,6 @@ def signupinternal(course_id): informed_about_rejection=informed_about_rejection ) # set course ects to applicant - applicant.ects_points = course.ects_points db.session.add(applicant) db.session.delete(o_auth_token) db.session.commit() @@ -436,7 +435,6 @@ def signupexternal(course_id): informed_about_rejection=informed_about_rejection ) # add course ects to applicant - applicant.ects_points = course.ects_points db.session.add(applicant) db.session.commit() except Exception as e: