From 526ff62414b6252d0e10a6b267c57747c59b490b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Palma?= Date: Thu, 30 May 2024 22:51:01 +0100 Subject: [PATCH 1/2] feat: storing unit id on direct exchanges --- django/university/exchange/utils.py | 4 +++- django/university/views.py | 8 ++------ mysql/sql/00_schema_mysql.sql | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/django/university/exchange/utils.py b/django/university/exchange/utils.py index 6aace82..a276de5 100644 --- a/django/university/exchange/utils.py +++ b/django/university/exchange/utils.py @@ -53,7 +53,7 @@ def build_student_schedule_dicts(student_schedules, exchanges, semana_ini, seman return (ExchangeStatus.SUCCESS, None) -def check_for_overlaps(student_schedules, exchanges, inserted_exchanges, exchange_db_model, auth_user): +def create_direct_exchange_participants(student_schedules, exchanges, inserted_exchanges, exchange_db_model, auth_user): if exchange_overlap(student_schedules, auth_user): return (ExchangeStatus.CLASSES_OVERLAP, None) @@ -68,6 +68,7 @@ def check_for_overlaps(student_schedules, exchanges, inserted_exchanges, exchang old_class=curr_exchange["old_class"], new_class=curr_exchange["new_class"], course_unit=curr_exchange["course_unit"], + course_unit_id=curr_exchange["course_unit_id"], direct_exchange=exchange_db_model, accepted=False )) @@ -77,6 +78,7 @@ def check_for_overlaps(student_schedules, exchanges, inserted_exchanges, exchang old_class=curr_exchange["new_class"], # This is not a typo, the old class of the authenticted student is the new class of the other student new_class=curr_exchange["old_class"], course_unit=curr_exchange["course_unit"], + course_unit_id=curr_exchange["course_unit_id"], direct_exchange=exchange_db_model, accepted=False )) diff --git a/django/university/views.py b/django/university/views.py index 106e4c5..46d4b5e 100644 --- a/django/university/views.py +++ b/django/university/views.py @@ -7,7 +7,7 @@ from django.core.paginator import Paginator from tts_be.settings import JWT_KEY, VERIFY_EXCHANGE_TOKEN_EXPIRATION_SECONDS from university.exchange.utils import course_unit_name, curr_semester_weeks, get_student_schedule_url, build_student_schedule_dict, exchange_overlap, build_student_schedule_dicts, get_unit_schedule_url, update_schedule, update_schedule_accepted_exchanges -from university.exchange.utils import ExchangeStatus, build_new_schedules, check_for_overlaps, convert_sigarra_schedule +from university.exchange.utils import ExchangeStatus, build_new_schedules, create_direct_exchange_participants, convert_sigarra_schedule from university.models import Faculty from university.models import Course from university.models import CourseUnit @@ -332,10 +332,6 @@ def submit_direct_exchange(request): if(curr_student_schedule.status_code != 200): return HttpResponse(status=curr_student_schedule.status_code) - # TODO We need to change the fetched schedule with the exchange information we have in our database - # user_schedule_offset = DirectExchangeParticipants.objects.filter("""direct_exchange__accepted=True,""" participant=request.session["username"], accepted=True) - user_schedule_offset = DirectExchangeParticipants.objects.filter(participant=request.session["username"]) - username = request.session["username"] schedule_data = json.loads(curr_student_schedule.content)["horario"] @@ -360,7 +356,7 @@ def submit_direct_exchange(request): return JsonResponse({"error": "students-with-incorrect-classes"}, status=400, safe=False) inserted_exchanges = [] - (status, trailing) = check_for_overlaps(student_schedules, exchanges, inserted_exchanges, exchange_model, request.session["username"]) + (status, trailing) = create_direct_exchange_participants(student_schedules, exchanges, inserted_exchanges, exchange_model, request.session["username"]) if status == ExchangeStatus.CLASSES_OVERLAP: return JsonResponse({"error": "classes-overlap"}, status=400, safe=False) diff --git a/mysql/sql/00_schema_mysql.sql b/mysql/sql/00_schema_mysql.sql index dad08de..04acaec 100644 --- a/mysql/sql/00_schema_mysql.sql +++ b/mysql/sql/00_schema_mysql.sql @@ -154,6 +154,7 @@ CREATE TABLE `direct_exchange_participants` ( `old_class` varchar(16) NOT NULL, `new_class` varchar(16) NOT NULL, `course_unit` varchar(64) NOT NULL, + `course_unit_id` varchar(16) NOT NULL, `direct_exchange` INTEGER NOT NULL, `accepted` boolean NOT NULL, `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, From 2ea78ac421a00f800b15e7c39dcd033b46de3a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Fernandes?= <93282636+joaonevesf@users.noreply.github.com> Date: Tue, 4 Jun 2024 21:16:37 +0100 Subject: [PATCH 2/2] added popup warning when the schedule is different from sigarra (#25) --- django/university/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/django/university/views.py b/django/university/views.py index 46d4b5e..f87a7b3 100644 --- a/django/university/views.py +++ b/django/university/views.py @@ -1,5 +1,3 @@ -import random -import string from datetime import datetime, timedelta from django.utils import timezone from django.http.response import HttpResponse @@ -32,6 +30,7 @@ import time from django.utils import timezone from django.core.cache import cache +import hashlib # Create your views here. @@ -230,10 +229,14 @@ def student_schedule(request, student): return HttpResponse(status=response.status_code) schedule_data = response.json()['horario'] + old_schedule = hashlib.sha256(json.dumps(schedule_data, sort_keys=True).encode()).hexdigest() update_schedule_accepted_exchanges(student, schedule_data, request.COOKIES) - new_response = JsonResponse(convert_sigarra_schedule(schedule_data), safe=False) + new_schedule = hashlib.sha256(json.dumps(schedule_data, sort_keys=True).encode()).hexdigest() + sigarra_synchronized = old_schedule == new_schedule + + new_response = JsonResponse({"schedule": convert_sigarra_schedule(schedule_data), "noChanges": sigarra_synchronized}, safe=False) new_response.status_code = response.status_code return new_response