Skip to content

Commit

Permalink
small fix + rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelVch98 committed Oct 17, 2024
1 parent 29b43a3 commit 73dd5c5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
6 changes: 2 additions & 4 deletions course_preference.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
course_preference_bp = Blueprint('course_preference', __name__)


def delete_old_preferences(researcher_id, course_ids, current_year):
def delete_old_preferences(researcher_id, current_year):
try:
db.session.query(PreferenceAssignment).filter(
PreferenceAssignment.researcher_id == researcher_id,
PreferenceAssignment.course_year == current_year,
PreferenceAssignment.course_id.in_(course_ids)
).delete()
db.session.commit()
except Exception as e:
Expand All @@ -41,8 +40,7 @@ def save_preference():
if researcher is None:
flash("Researcher not found", "error")

new_course_ids = {preference['course_id'] for preference in preferences}
delete_old_preferences(researcher.id, new_course_ids, current_year)
delete_old_preferences(researcher.id, current_year)

rank = 0
for preference in preferences:
Expand Down
2 changes: 1 addition & 1 deletion db.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class PreferenceAssignment(db.Model):
)

course = db.relationship('Course', backref=db.backref('course_preference_assignment', lazy=True))
researcher = db.relationship('Researcher', backref=db.backref('researcher_preference_assignment', lazy=True))
researcher = db.relationship('Researcher', backref=db.backref('preferences', lazy=True))


class Configuration(db.Model):
Expand Down
17 changes: 10 additions & 7 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
href="{{ url_for('user.user_profile', user_id=session.user_id) }}">My
Profile</a>
</li>
<li>
<a class="nav-link"
href="{{ url_for('user.preferences', user_id=session.user_id, current_year=dynamic_year) }}">Preferences</a>
</li>
{% if is_researcher %}
<li>
<a class="nav-link"
href="{{ url_for('user.preferences', user_id=session.user_id, current_year=dynamic_year) }}">Preferences</a>
</li>
{% endif %}
<li>
<a class="nav-link"
href="{{ url_for('course.evaluations', user_id=session.user_id, current_year=dynamic_year) }}">Evaluations</a>
Expand Down Expand Up @@ -96,8 +98,8 @@
</ul>
</li>
<li>
<a class="nav-link"
href="{{ url_for('config.manage_years', configurations=configurations) }}">Configurations</a>
<a class="nav-link"
href="{{ url_for('config.manage_years', configurations=configurations) }}">Configurations</a>
</li>
{% endif %}
{% block additionalnav %}{% endblock %}
Expand All @@ -106,7 +108,8 @@
<div class="me-0">
<div class="navbar-text me-2">
<input type="text" class="form-control form-control-sm" id="dynamicYearInput"
value="{{ dynamic_year }} - {{ dynamic_year + 1 }}" style="width: 100px;" disabled>
value="{{ dynamic_year }} - {{ dynamic_year + 1 }}" style="width: 100px;"
disabled>
</div>
</div>

Expand Down
4 changes: 0 additions & 4 deletions templates/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ <h1>{{ requested_user.first_name }} {{ requested_user.name }}</h1>
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" data-bs-toggle="tab" href="#profile">My profile</a>
</li>
{% if is_researcher %}
<li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#preferences">My
preferences</a></li>
{% endif %}
</ul>
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def create_researcher(user_id, researcher_type, max_loads):
db.session.commit()
return new_researcher


def get_researchers():
return db.session.query(User).join(Researcher).filter(User.active == True).all()

Expand Down Expand Up @@ -80,7 +81,8 @@ def add_user():

if supervisor_ids:
supervisors = db.session.query(User).filter(User.id.in_(supervisor_ids)).all()
new_researcher.supervisors = [ResearcherSupervisor(researcher=new_researcher, supervisor=s) for s in supervisors]
new_researcher.supervisors = [ResearcherSupervisor(researcher=new_researcher, supervisor=s) for s in
supervisors]
db.session.commit()

flash("User added successfully.", "success")
Expand Down Expand Up @@ -139,7 +141,7 @@ def user_profile(user_id, ):
if researcher:
preferences = db.session.query(PreferenceAssignment).filter_by(researcher_id=researcher.id,
course_year=current_year).order_by(
PreferenceAssignment.id).all()
PreferenceAssignment.rank).all()
courses = []
if current_user and requested_user.organization:
courses = db.session.query(Course).filter(Course.year == current_year,
Expand Down Expand Up @@ -238,7 +240,8 @@ def update_user_profile(user_id):
if supervisor_ids:
db.session.query(ResearcherSupervisor).filter_by(researcher_id=researcher.id).delete()
supervisors = db.session.query(User).filter(User.id.in_(supervisor_ids)).all()
researcher.supervisors = [ResearcherSupervisor(researcher=researcher, supervisor=s) for s in supervisors]
researcher.supervisors = [ResearcherSupervisor(researcher=researcher, supervisor=s) for s in
supervisors]
else:
delete_researcher(user.id)
db.session.commit()
Expand Down

0 comments on commit 73dd5c5

Please sign in to comment.