Skip to content

Commit

Permalink
Merge branch 'develop' into feature/send-email
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspalma committed Jun 5, 2024
2 parents 09dd1cc + 2ea78ac commit 3b8eb63
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion django/university/exchange/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
))
Expand All @@ -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
))
Expand Down
17 changes: 8 additions & 9 deletions django/university/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import random
from django.core.mail import send_mail
import string
from datetime import datetime, timedelta
from django.utils import timezone
from django.http.response import HttpResponse
from rest_framework.views import APIView
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
Expand All @@ -33,6 +31,7 @@
import time
from django.utils import timezone
from django.core.cache import cache
import hashlib
# Create your views here.


Expand Down Expand Up @@ -231,10 +230,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

Expand Down Expand Up @@ -333,10 +336,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"]

Expand All @@ -361,7 +360,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)

Expand Down
1 change: 1 addition & 0 deletions mysql/sql/00_schema_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3b8eb63

Please sign in to comment.