Skip to content

Commit

Permalink
remove applicant ects, add attendance ects, change internal logic for…
Browse files Browse the repository at this point in the history
… ects handling (#28)
  • Loading branch information
urvdp authored Jul 6, 2024
1 parent 54539d2 commit d597038
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
11 changes: 6 additions & 5 deletions src/spz/administration/admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion src/spz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand Down
26 changes: 16 additions & 10 deletions src/spz/templates/internal/administration/edit_grade.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ <h3>Schritt 1:</h3>
<td>{{ applicant.first_name }}</td>
<td>{{ applicant.last_name }}</td>
<td>
{% if course.ects_points == 2 %}
<select name="ects_{{ applicant.id }}" class="ui dropdown">
<option value="2" {% if applicant.ects_points == 2 %}selected{% endif %}>
2 (normal)
</option>
<option value="3" {% if applicant.ects_points == 3 %}selected{% endif %}>
3 (mit Zusatzleistung)
</option>
</select>
{% if course.get_course_attendance(course.id, applicant.id) is none %}
Fehler: nicht in Liste
{% else %}
{{ applicant.ects_points }}
{% if course.ects_points == 2 %}
<select name="ects_{{ applicant.id }}" class="ui dropdown">
<option value="2"
{% if course.get_course_attendance(course.id, applicant.id).ects_points == 2 %}selected{% endif %}>
2 (normal)
</option>
<option value="3"
{% if course.get_course_attendance(course.id, applicant.id).ects_points == 3 %}selected{% endif %}>
3 (mit Zusatzleistung)
</option>
</select>
{% else %}
{{ course.get_course_attendance(course.id, applicant.id).ects_points }}
{% endif %}
{% endif %}
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h3>Schritt 2:</h3>
<td>{{ applicant.first_name }}</td>
<td>{{ applicant.last_name }}</td>
<td>
{{ applicant.ects_points }}
{{ course.get_course_attendance(course.id, applicant.id).ects_points }}
</td>
<td>
{% if applicant.grade is none %}
Expand Down
20 changes: 13 additions & 7 deletions src/spz/templates/internal/administration/grade.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

{% block internal_body %}
{% if current_user.is_teacher %}
<div>
<a href=" {{ url_for('teacher') }} ">
<button type="button" class="ui button">Zurück zu meinen Kursen</button>
</a>
</div>
<div>
<a href=" {{ url_for('teacher') }} ">
<button type="button" class="ui button">Zurück zu meinen Kursen</button>
</a>
</div>
{% endif %}

<div class="three column row">
Expand Down Expand Up @@ -41,10 +41,16 @@ <h2>Notenübersicht</h2>
<tbody>
{% for applicant in course.course_list %}
<tr class="{{ 'error' if applicant.full_grade == 'nicht bestanden' else '' }}">
<td>{% if applicant.tag %} {{applicant.tag }} {% endif %}</td>
<td>{% if applicant.tag %} {{ applicant.tag }} {% endif %}</td>
<td>{{ applicant.first_name }}</td>
<td>{{ applicant.last_name }}</td>
<td>{{ applicant.ects_points }}</td>
<td>
{% 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 %}
</td>
<td>
{% if applicant.grade is not none %}
{% if applicant.hide_grade %}
Expand Down
2 changes: 0 additions & 2 deletions src/spz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d597038

Please sign in to comment.