Skip to content

Commit

Permalink
Fixed the bug that did not display the assessments for each different…
Browse files Browse the repository at this point in the history
… year of the courses
  • Loading branch information
SamuelVch98 committed Oct 4, 2024
1 parent ca74ecd commit eb5a130
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 41 deletions.
32 changes: 5 additions & 27 deletions course.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ def course_info(course_id, year):
all_years = db.session.query(Course).filter_by(id=course.id).distinct(Course.year).order_by(
Course.year.desc()).all()

evaluations = db.session.query(Evaluation).filter(
Evaluation.course_id == course_id,
Evaluation.course_year < course.year
).all()
evaluations = db.session.query(Evaluation).filter(Evaluation.course_id == course_id).order_by(
Evaluation.course_year.desc()).all()

return render_template('course_info.html', course=course, all_years=all_years, current_year=year,
evaluations=evaluations)
Expand Down Expand Up @@ -267,33 +265,13 @@ def add_duplicate_course():

return redirect(url_for('course.course_info', course_id=course_id, year=year))

'''
@course_bp.route('/evaluations/<int:user_id>/<int:current_year>')
@login_required
def evaluations(user_id, current_year):
courses = db.session.query(Course).filter_by(year=current_year).all()
return render_template('evaluations.html', courses=courses, current_year=current_year, user_id=user_id)
@course_bp.route('/evaluation/<int:evaluation_id>')
@login_required
def evaluation(evaluation_id):
evaluation = db.session.query(Evaluation).get(evaluation_id)
if not evaluation:
return flash("Evaluation not found", "danger")
return render_template('evaluations.html', evaluation=evaluation, current_year=evaluation.course_year)
'''


@course_bp.route('/evaluations/<int:user_id>/<int:current_year>', defaults={'evaluation_id': None})
@course_bp.route('/evaluation/<int:evaluation_id>', defaults={'user_id': None, 'current_year': None})
@login_required
def evaluations(user_id=None, current_year=None, evaluation_id=None):

evaluation = db.session.query(Evaluation).get(evaluation_id) \
if evaluation_id else None
if evaluation_id else None
year = evaluation.course_year if evaluation else current_year
courses = db.session.query(Course).filter_by(year=year).all()
if evaluation:
Expand All @@ -307,7 +285,7 @@ def evaluations(user_id=None, current_year=None, evaluation_id=None):

@course_bp.route('/create_evaluations/<int:user_id>/<int:current_year>', methods=['POST'])
@login_required
#@check_access_level(Role.RESEARCHER)
# @check_access_level(Role.RESEARCHER)
def create_evaluation(user_id, current_year):
form = request.form
if not form:
Expand All @@ -334,7 +312,7 @@ def create_evaluation(user_id, current_year):
flash('Evaluation created successfully!', 'success')

new_evaluation = Evaluation(course_id=course_id, course_year=current_year, user_id=user_id, task=tasks,
other_task=other_task ,nbr_hours=evaluation_hour, workload=workload,
other_task=other_task, nbr_hours=evaluation_hour, workload=workload,
comment=comment)
db.session.add(new_evaluation)
db.session.commit()
Expand Down
34 changes: 20 additions & 14 deletions templates/course_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ <h2 class="sub-header">History</h2>
<hr>

<!-- Nav tabs -->
<ul class="nav nav-tabs" id="historyTabs" role="tablist">
<ul class="nav nav-tabs" id="historyTabs{{ course.year }}" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="assistants-tab" data-bs-toggle="tab" href="#assistants"
<a class="nav-link active" id="assistants-tab-{{ course.year }}" data-bs-toggle="tab" href="#assistants-{{ course.year }}"
role="tab"
aria-controls="assistants" aria-selected="true">Assistants</a>
</li>
<li class="nav-item">
<a class="nav-link" id="evaluations-tab" data-bs-toggle="tab" href="#evaluations"
<a class="nav-link" id="evaluations-tab-{{ course.year }}" data-bs-toggle="tab" href="#evaluations-{{ course.year }}"
role="tab"
aria-controls="evaluations" aria-selected="false">Evaluations</a>
</li>
Expand All @@ -65,8 +65,8 @@ <h2 class="sub-header">History</h2>
<!-- Tab panes -->
<div class="tab-content">
<!-- Assistants Pane -->
<div class="tab-pane fade show active" id="assistants" role="tabpanel"
aria-labelledby="assistants-tab">
<div class="tab-pane fade show active" id="assistants-{{ course.year }}" role="tabpanel"
aria-labelledby="assistants-tab-{{ course.year }}">
<table class="table table-hover mt-3">
<thead>
<tr>
Expand All @@ -79,8 +79,8 @@ <h2 class="sub-header">History</h2>
</table>
</div>
<!-- Evaluations Pane -->
<div class="tab-pane fade show" id="evaluations" role="tabpanel"
aria-labelledby="evaluations-tab">
<div class="tab-pane fade show" id="evaluations-{{ course.year }}" role="tabpanel"
aria-labelledby="evaluations-tab-{{ course.year }}">
<!-- Content for Evaluations -->
<table class="table table-hover" id="evaluationTable">
<thead>
Expand All @@ -91,20 +91,26 @@ <h2 class="sub-header">History</h2>
</tr>
</thead>
<tbody>
{% for evaluation in evaluations %}
{% if evaluations is none %}
<tr>
<td><a href="{{ url_for('course.evaluations', evaluation_id=evaluation.id) }}">
{{ evaluation.course.code }} - {{ evaluation.course.title }}</a>
</td>
<td>{{ evaluation.course.year }}</td>
<td>{{ evaluation.user.name }} {{ evaluation.user.first_name }}</td>
<td colspan="3">No evaluations for this year.</td>
</tr>
{% endif %}
{% for evaluation in evaluations %}
{% if evaluation.course_year < course.year %}
<tr>
<td><a href="{{ url_for('course.evaluations', evaluation_id=evaluation.id) }}">
{{ evaluation.course.code }} - {{ evaluation.course.title }}</a>
</td>
<td>{{ evaluation.course.year }}</td>
<td>{{ evaluation.user.name }} {{ evaluation.user.first_name }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>

</div>
</div>
</div>
Expand Down

0 comments on commit eb5a130

Please sign in to comment.