Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#30 no way to read evaluations #41

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
16bec2f
Resolving issues filtering with no organizations
SamuelVch98 Jul 27, 2024
585ace3
use toast to display errors
SamuelVch98 Jul 29, 2024
0da87f0
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Jul 29, 2024
eada3ca
Fix small issues
SamuelVch98 Jul 30, 2024
7cae218
create unique file for toast and use it
SamuelVch98 Jul 30, 2024
4a633f6
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Jul 30, 2024
99f16d6
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Aug 20, 2024
cf3938d
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Sep 12, 2024
ad8658c
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Oct 1, 2024
1177b11
indicate the type of user to be displayed
SamuelVch98 Oct 9, 2024
9f8b4cc
Fix the bug that prevents you from changing organisation if none was …
SamuelVch98 Oct 9, 2024
ec2bdc1
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Oct 13, 2024
97023c8
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Oct 15, 2024
af8da85
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Oct 15, 2024
4db087a
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Oct 16, 2024
d40c27b
Merge branch 'UCL-INGI:main' into main
SamuelVch98 Oct 17, 2024
6793917
Allow researchers to post their past evaluations
SamuelVch98 Oct 3, 2024
bfc03bf
Define the current year statically
SamuelVch98 Sep 25, 2024
20b921e
Fixed the bug that did not display the assessments for each different…
SamuelVch98 Oct 4, 2024
7c85c50
fix small bug
SamuelVch98 Oct 15, 2024
33b063f
apply requested changes
SamuelVch98 Oct 17, 2024
c912e97
fix requested changes
SamuelVch98 Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from course import course_bp
from config import config_bp
from course_preference import course_preference_bp
from db import db, Configuration, Organization, User, Course, Teacher, Researcher
from db import db, Configuration, Organization, User, Course, Teacher, Researcher, Evaluation
from decorators import *
from flask import Flask, render_template, session, request
from enums import *
Expand Down Expand Up @@ -55,7 +55,7 @@ def index(): # put application's code here
current_year = get_current_year()
user = db.session.query(User).filter_by(email=session['email']).first()
courses_teacher = db.session.query(Course).filter_by(year=current_year).join(Teacher).filter(Teacher.user_id == user.id).all()
return render_template("home.html", user=user, courses=courses_teacher)
return render_template("home.html", user=user, courses=courses_teacher, evaluations=user.evaluations)


if __name__ == '__main__':
Expand Down
44 changes: 34 additions & 10 deletions course.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def add_course():

db.session.add(new_course)
db.session.commit()
return redirect(url_for("course.courses", current_year=year))
return redirect(url_for("course.courses", year=year))
except Exception as e:
db.session.rollback()
raise e
Expand All @@ -125,7 +125,8 @@ def search_teachers():
if not validate_string_pattern(search_term):
return make_response("Invalid search term", 400)

teachers = db.session.query(User).join(Teacher).filter(
teachers = db.session.query(User).filter(
User.is_teacher,
User.active == True,
User.name.ilike(f'%{search_term}%')
).all()
Expand All @@ -144,7 +145,10 @@ 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()

return render_template('course_info.html', course=course, all_years=all_years, current_year=year)
evaluations = course.evaluations

return render_template('course_info.html', course=course, all_years=all_years, current_year=year,
evaluations=evaluations)


@course_bp.route('/update_course_info', methods=['POST'])
Expand Down Expand Up @@ -262,16 +266,38 @@ def add_duplicate_course():
return redirect(url_for('course.course_info', course_id=course_id, year=year))


@course_bp.route('/evaluation/<int:evaluation_id>')
@login_required
SamuelVch98 marked this conversation as resolved.
Show resolved Hide resolved
def course_evaluation(evaluation_id):
evaluation = db.session.query(Evaluation).get(evaluation_id)
courses = db.session.query(Course).filter_by(year=evaluation.course_year).all()

course = evaluation.course
user = db.session.query(User).filter_by(id=session['user_id']).first()
teachers = course.course_teacher

# Accessible only to the admin, the evaluation creator and the course teachers
if (not user.is_admin) and (user.id != evaluation.user_id) and (user.id not in [teacher.user_id for teacher in teachers]):
flash("You are not allowed to access this page", "danger")
return redirect(url_for('course.courses', course_id=course.id, year=course.year))

return render_template('evaluations.html', evaluation=evaluation, current_year=evaluation.course_year,
courses=courses)


@course_bp.route('/evaluations/<int:user_id>/<int:current_year>')
@login_required
def evaluations(user_id, current_year):
@check_access_level(Role.RESEARCHER)
def user_evaluation(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)
return render_template('evaluations.html', courses=courses, current_year=current_year, user_id=user_id,
evaluation=None)


@course_bp.route('/create_evaluations/<int:user_id>/<int:current_year>', methods=['POST'])
@login_required
@check_access_level(Role.RESEARCHER)
def create_evaluation(user_id, current_year):
form = request.form
if not form:
Expand All @@ -287,9 +313,6 @@ def create_evaluation(user_id, current_year):
if not all([course_id, evaluation_hour, workload, comment is not None]):
return make_response("Missing required fields", 400)

if other_task:
tasks.append(other_task)

try:
existing_evaluation = db.session.query(Evaluation).filter_by(course_id=course_id, course_year=current_year,
user_id=user_id).first()
Expand All @@ -301,11 +324,12 @@ 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,
nbr_hours=evaluation_hour, workload=workload, comment=comment)
other_task=other_task, nbr_hours=evaluation_hour, workload=workload,
comment=comment)
db.session.add(new_evaluation)
db.session.commit()
except Exception as e:
db.session.rollback()
flash(f'An error occurred: {str(e)}', 'danger')

return redirect(url_for('course.evaluations', user_id=user_id, current_year=current_year))
return redirect(url_for('course.user_evaluation', user_id=user_id, current_year=current_year))
13 changes: 10 additions & 3 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,24 @@ class CourseOrganization(db.Model):
class Evaluation(db.Model):
__tablename__ = 'evaluation'

course_id = db.Column(db.Integer, primary_key=True)
course_year = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
id = db.Column(db.Integer, primary_key=True)
course_id = db.Column(db.Integer, nullable=False)
course_year = db.Column(db.Integer, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
task = db.Column(db.JSON, nullable=False)
other_task = db.Column(db.String(200))
nbr_hours = db.Column(db.String(10), nullable=False)
anthonygego marked this conversation as resolved.
Show resolved Hide resolved
workload = db.Column(db.String(10), nullable=False)
comment = db.Column(db.String(500))

__table_args__ = (
db.UniqueConstraint('course_id', 'course_year', 'user_id', name='unique_course_year_user'),
db.ForeignKeyConstraint(
['course_id', 'course_year'],
['course.id', 'course.year']
),
)

course = db.relationship('Course', backref=db.backref('evaluations', lazy=True))
user = db.relationship('User',
backref=db.backref('evaluations', lazy=True, order_by='desc(Evaluation.course_year)'))
96 changes: 62 additions & 34 deletions templates/course_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,70 @@ <h2 class="sub-header">Assistant(s) for this year ({{ course.year }} - {{ course
</tbody>
</table>
<div class="container-fluid">
<h2 class="sub-header">History</h2>
<hr>
<div class="card">
<div class="card-body">
<h2 class="sub-header">History</h2>
<hr>

<!-- Nav tabs -->
<ul class="nav nav-tabs" id="historyTabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="assistants-tab" data-bs-toggle="tab" href="#assistants" 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" role="tab"
aria-controls="evaluations" aria-selected="false">Evaluations</a>
</li>
</ul>
<!-- Nav tabs -->
<ul class="nav nav-tabs" id="historyTabs{{ course.year }}" role="tablist">
<li class="nav-item">
<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-{{ course.year }}" data-bs-toggle="tab" href="#evaluations-{{ course.year }}"
role="tab"
aria-controls="evaluations" aria-selected="false">Evaluations</a>
</li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
<!-- Assistants Pane -->
<div class="tab-pane fade show active" id="assistants" role="tabpanel"
aria-labelledby="assistants-tab">
<table class="table table-hover mt-3">
<thead>
<tr>
<th>Last name</th>
<th>First name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<!-- Evaluations Pane -->
<div class="tab-pane fade show" id="evaluations" role="tabpanel" aria-labelledby="evaluations-tab">
<!-- Content for Evaluations -->
<br>
<p>Content for evaluations will go here.</p>
<!-- Tab panes -->
<div class="tab-content">
<!-- Assistants Pane -->
<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>
<th>Last name</th>
<th>First name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<!-- Evaluations Pane -->
<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>
<tr>
<th>Course name</th>
<th>Year</th>
</tr>
</thead>
<tbody>
{% if evaluations is none %}
<tr>
<td colspan="3">No evaluations for this year.</td>
</tr>
{% endif %}
{% for evaluation in evaluations %}
<tr>
<td><a href="{{ url_for('course.course_evaluation', evaluation_id=evaluation.id) }}">
{{ evaluation.course.code }} - {{ evaluation.course.title }}</a>
</td>
<td>{{ evaluation.course.year }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions templates/course_info_template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{% block additionalpageheader %}
<style>
a {
text-decoration: none;
color: black;
}
</style>
{% endblock %}
<input type="hidden" name="course_id" value="{{ course.id }}">
<div class="row">
<div class="col-lg-4 col-md-6">
Expand Down
5 changes: 0 additions & 5 deletions templates/course_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
{% block pagetitle %}Course informations{% endblock %}
{% block additionalpageheader %}
<style>
.badge a {
color: black;
text-decoration: none;
}

.badge a:hover {
color: red;
}
Expand Down
37 changes: 25 additions & 12 deletions templates/evaluations.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ <h2>Evaluation form</h2>
<p>Please note that your answers are confidential and that if there are any problems or changes we have to
report, we'll do so anonymously.</p>
<hr>
<form action="{{ url_for("course.create_evaluation", current_year=current_year, user_id=user_id) }}"
<form action="{{ url_for("course.create_evaluation", current_year=current_year, user_id=session["user_id"]) }}"
SamuelVch98 marked this conversation as resolved.
Show resolved Hide resolved
method="POST">
<strong>If you gave two courses during this semester, choose one of them and create a new evaluation for the
second one </strong>
<div class="form-group">
<br>
<label for="course1">1. What is the course you gave this semester?</label>
<select class="form-control" id="course" name="course_id" required>
<label for="course">1. What is the course you gave this semester?</label>
<select class="form-control" id="course" name="course_id" required
{% if evaluation %} disabled {% endif %}>
{% for course in courses %}
<option value="{{ course.id }}">{{ course.code }} - {{ course.title }}</option>
<option value="{{ course.id }}"
{% if evaluation and evaluation.course_id == course.id %} selected {% endif %}>
{{ course.code }} - {{ course.title }}
</option>
{% endfor %}
</select>
</div>
Expand All @@ -28,32 +32,37 @@ <h2>Evaluation form</h2>
{% for task in tasks %}
<div class="form-check">
<input class="form-check-input" type="checkbox" name="tasks[]" id="{{ task }}"
value="{{ task }}">
value="{{ task }}"
{% if evaluation and task in evaluation.task %} checked disabled {% endif %}>
<label class="form-check-label" for="{{ task }}">{{ task }}</label>
</div>
{% endfor %}
<div class="form-check">
<input class="form-check-input" type="checkbox" name="tasks[]" id="other" value="Other">
<input class="form-check-input" type="checkbox" name="tasks[]" id="other" value="Other"
{% if evaluation and "Other" in evaluation.task %} checked disabled{% endif %}>
<input class="form-control" type="text" name="other_task" id="other_task" placeholder="Other"
value="">
value="{{ evaluation.other_task if evaluation else '' }}" {% if evaluation %} disabled {% endif %}>
</div>
</div>
<br>
<div class="form-group">
<label>3. On average, how many hours a week were devoted to this course (preparation, time in exercise
sessions, projects, etc., all included)?</label><br>
<select class="form-control" name="evaluation_hour" required>
<select class="form-control" name="evaluation_hour" required {% if evaluation %} disabled {% endif %}>
{% for hour in evaluation_hour %}
<option value="{{ hour }}">{{ hour }}</option>
<option value="{{ hour }}" {% if evaluation and evaluation.nbr_hours == hour %}
selected {% endif %}>{{ hour }}</option>
{% endfor %}
</select>
</div>
<br>
<div class="form-group">
<label>4. How would you rate your workload for this course?</label><br>
<select class="form-control" name="workload" required>
<select class="form-control" name="workload" required {% if evaluation %} disabled {% endif %}>
{% for workload in workloads %}
<option value="{{ workload }}">{{ workload }}</option>
<option value="{{ workload }}"
{% if evaluation and evaluation.workload == workload %} selected {% endif %}>
{{ workload }}</option>
{% endfor %}
</select>
</div>
Expand All @@ -62,10 +71,14 @@ <h2>Evaluation form</h2>
<label for="comments">5. Do you have any comments to make about the course load? (For example: if you
know that the course will change a lot less next year, or will be strongly
reorganized,...)</label><br>
<textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
<textarea class="form-control" id="comment" name="comment"
rows="3" {% if evaluation %} disabled {% endif %}>{{ evaluation.comment if evaluation else '' }}</textarea>
</div>

{% if not evaluation %}
<br>
<button type="submit" class="btn btn-primary">Submit</button>
{% endif %}
</form>
</div>
{% endblock %}
Expand Down
Loading