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

Integrate the course assignment table according to researchers' preferences #10

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 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
8efbfd2
Add handsontable to the app
SamuelVch98 Jul 16, 2024
4f35393
Finish integrating the handsontable panel
SamuelVch98 Jul 16, 2024
5d66fe5
update README
SamuelVch98 Jul 16, 2024
7fbef2e
Fix PR request
SamuelVch98 Jul 26, 2024
c67c38a
Check semicolon and fix small issues
SamuelVch98 Jul 29, 2024
f5b545a
Modify the conditions when changing the value of a cell to ensure the…
SamuelVch98 Sep 30, 2024
173b1c0
use more constants and place them in a separate file if possible to m…
SamuelVch98 Sep 30, 2024
5c36f64
rabse + modifying the code to display several promoters
SamuelVch98 Oct 21, 2024
79c0ebb
disable cells that contains user's preferences
SamuelVch98 Oct 21, 2024
0c7d480
fix small issue
SamuelVch98 Oct 21, 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
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from course import course_bp
from config import config_bp
from course_preference import course_preference_bp
from assignment import assignment_bp
from db import db, Configuration, Organization, User, Course, Teacher, Researcher
from decorators import *
from flask import Flask, render_template, session, request
Expand All @@ -27,6 +28,7 @@
app.register_blueprint(course_bp, url_prefix="/course")
app.register_blueprint(config_bp, url_prefix="/config")
app.register_blueprint(course_preference_bp, url_prefix="/course_preference")
app.register_blueprint(assignment_bp, url_prefix="/assignment")


def get_configurations():
Expand Down
74 changes: 74 additions & 0 deletions assignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from decorators import login_required
from db import db, User, Course, PreferenceAssignment, Teacher, Researcher, Organization, PublishAssignment, \
ResearcherSupervisor
from flask import Blueprint, render_template, flash, current_app, url_for, request, make_response, redirect, session, \
Flask, jsonify
from util import get_current_year

assignment_bp = Blueprint('assignment', __name__)


@assignment_bp.route('/assignments', methods=['GET'])
@login_required
def assignments():
return render_template('assignment.html')


def serialize_model(model):
"""Converts a SQLAlchemy model object into a dictionary."""
return {column.name: getattr(model, column.name) for column in model.__table__.columns}


@assignment_bp.route('/load_data', methods=['GET'])
@login_required
def load_data():
current_year = get_current_year()
SamuelVch98 marked this conversation as resolved.
Show resolved Hide resolved
courses = (db.session.query(Course).filter_by(year=current_year).order_by(Course.quadri).all())
users = db.session.query(User).filter_by(active=True).all()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware: if you save assignments and then de-activate a user, their data won't be found when reloading the assignment table. You should check for this.

supervisors = db.session.query(ResearcherSupervisor).all()
teachers = db.session.query(Teacher).filter_by(course_year=current_year).all()
researchers = db.session.query(Researcher).all()
preferences = db.session.query(PreferenceAssignment).filter_by(course_year=current_year).all()
organizations = db.session.query(Organization).all()

data = {
'courses': [serialize_model(course) for course in courses],
'users': {user.id: serialize_model(user) for user in users},
'supervisors': [serialize_model(supervisor) for supervisor in supervisors],
'teachers': {teacher.id: serialize_model(teacher) for teacher in teachers},
'researchers': {researcher.id: serialize_model(researcher) for researcher in researchers},
'preferences': {preference.id: serialize_model(preference) for preference in preferences},
'organizations': {organization.id: serialize_model(organization) for organization in organizations},
'current_year': current_year
}

return jsonify(data)


@assignment_bp.route('/publish_assignments', methods=['POST'])
@login_required
def publish_assignments():
data = request.get_json()
if not data:
return jsonify({"error": "No data provided"}), 400

current_year = get_current_year()

for item in data:
user_data = item.get('userData')
course_data = item.get('courseData')

if course_data and user_data:
for id, pos in course_data.items():
try:
assignment = PublishAssignment(course_id=id, course_year=current_year,
user_id=user_data.get('user_id'),
load_q1=user_data.get('load_q1'), load_q2=user_data.get('load_q2'),
position=pos)
db.session.add(assignment)
except Exception as e:
return jsonify({"error": str(e)}), 400

db.session.commit()

return jsonify({"message": "Assignments published successfully"}), 200
10 changes: 5 additions & 5 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,14 +40,15 @@ def save_preference():
if researcher is None:
return make_response("User is not a researcher", 500)

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this piece of code comes from #42. We'll wait for it to be merged before proceeding further with this one.

for preference in preferences:
try:
rank += 1
course_id = preference['course_id']
course_year = preference['course_year']
new_preference = PreferenceAssignment(course_id=course_id, course_year=course_year,
new_preference = PreferenceAssignment(rank=rank, course_id=course_id, course_year=course_year,
researcher_id=researcher.id)
db.session.add(new_preference)
db.session.commit()
Expand Down
18 changes: 18 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Teacher(db.Model):

class PreferenceAssignment(db.Model):
__tablename__ = 'preference_assignment'
rank = db.Column(db.Integer, nullable=False)
id = db.Column(db.Integer, primary_key=True)
course_id = db.Column(db.Integer, nullable=False)
course_year = db.Column(db.Integer, nullable=False)
Expand Down Expand Up @@ -172,6 +173,23 @@ class CourseOrganization(db.Model):
)


class PublishAssignment(db.Model):
__tablename__ = 'publish_assignment'
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)
load_q1 = db.Column(db.Integer)
load_q2 = db.Column(db.Integer)
position = db.Column(db.Integer)

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


class Evaluation(db.Model):
__tablename__ = 'evaluation'

Expand Down
46 changes: 46 additions & 0 deletions static/handsontable.full.min.css

Large diffs are not rendered by default.

Loading