Skip to content

Commit

Permalink
modified it to be update or create
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo authored Mar 6, 2024
1 parent 560eef6 commit 55cf15b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gameserver/models/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class ContestScore(models.Model):
flag_count = models.PositiveIntegerField(help_text="The amount of flags the user/team has.", default=0)

@classmethod
def update(cls, change_in_score: int, contest: Contest, user: Optional[User] = None, team: Optional[Team] = None, update_flags: bool = False):
def update_or_create(cls, change_in_score: int, contest: Contest, user: Optional[User] = None, team: Optional[Team] = None, update_flags: bool = True):

if not user and not team:
raise ValueError("You must specify either a user or a team")
Expand All @@ -438,6 +438,9 @@ def update(cls, change_in_score: int, contest: Contest, user: Optional[User] = N
queryset = queryset.filter(user=user)
elif team:
queryset = queryset.filter(team=team)
if not queryset.exists(): # no user/team found matching that
cls.objects.create(contest=contest, user=user, team=team, flag_count=int(update_flags), points=change_in_score)
return cls.update_or_create(contest=contest, change_in_score=change_in_score, user=user, team=team, update_flags=update_flags)

with transaction.atomic():
queryset.select_for_update()
Expand Down
1 change: 1 addition & 0 deletions gameserver/views/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def _create_submission_object(self, form, is_correct=None):
submission=submission,
participation=self.request.participation,
)
#models.ContestScore.
return submission

def get_form_kwargs(self, *args, **kwargs):
Expand Down

0 comments on commit 55cf15b

Please sign in to comment.