From 8edb1479642a8d208c69a2542745892ebe514bf8 Mon Sep 17 00:00:00 2001 From: kovacspe Date: Thu, 22 Aug 2024 17:28:43 +0200 Subject: [PATCH] Load frozen results as json (#400) --- competition/models.py | 7 ++++--- competition/views.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/competition/models.py b/competition/models.py index b103f2e..8af195f 100644 --- a/competition/models.py +++ b/competition/models.py @@ -1,4 +1,5 @@ import datetime +import json from typing import Optional from django.conf import settings @@ -251,7 +252,7 @@ def get_second_series(self) -> 'Series': def freeze_results(self, results): if any(not series.complete for series in self.series_set.all()): raise FreezingNotClosedResults() - self.frozen_results = results + self.frozen_results = json.dumps(results) @property def complete(self) -> bool: @@ -368,7 +369,7 @@ def freeze_results(self, results): for problem in self.problems.all() ): raise FreezingNotClosedResults() - self.frozen_results = results + self.frozen_results = json.dumps(results) @property def num_problems(self) -> int: @@ -803,7 +804,7 @@ def can_user_modify(self, user): return self.event.can_user_modify(user) def __str__(self): - return str(self.event) # pylint: disable=no-member + return str(self.event) # pylint: disable=no-member class ProblemCorrection(models.Model): diff --git a/competition/views.py b/competition/views.py index f11006e..0ddbd95 100644 --- a/competition/views.py +++ b/competition/views.py @@ -1,4 +1,5 @@ import csv +import json import os import zipfile from io import BytesIO @@ -481,7 +482,7 @@ def results(self, request: Request, pk: Optional[int] = None): """Vráti výsledkovku pre sériu""" series = self.get_object() if series.frozen_results is not None: - return series.frozen_results + return json.loads(series.frozen_results) results = self.__create_result_json(series) return Response(results, status=status.HTTP_200_OK) @@ -639,7 +640,7 @@ def perform_create(self, serializer): def semester_results(semester): """Vyrobí výsledky semestra""" if semester.frozen_results is not None: - return semester.frozen_results + return json.loads(semester.frozen_results) results = [] for registration in semester.eventregistration_set.all(): results.append(generate_result_row(registration, semester))