Skip to content

Commit

Permalink
Load frozen results as json (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe authored Aug 22, 2024
1 parent c3bd358 commit 8edb147
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions competition/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import json
from typing import Optional

from django.conf import settings
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions competition/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csv
import json
import os
import zipfile
from io import BytesIO
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 8edb147

Please sign in to comment.