Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename testdata folder for manually managed problems on change code #200

Merged
merged 2 commits into from Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion judge/models/problem.py
@@ -1,3 +1,4 @@
import errno
from operator import attrgetter

import celery
Expand All @@ -16,6 +17,7 @@
from django.utils.translation import gettext_lazy as _

from judge.fulltext import SearchQuerySet
from judge.models.problem_data import problem_data_storage
from judge.models.profile import Organization, Profile
from judge.models.runtime import Language
from judge.user_translations import gettext as user_gettext
Expand Down Expand Up @@ -479,16 +481,26 @@ def save(self, *args, **kwargs):
try:
problem_data = self.data_files
except AttributeError:
pass
try:
problem_data_storage.rename(self.__original_code, self.code)
except OSError as e:
if e.errno != errno.ENOENT:
raise
else:
problem_data._update_code(self.__original_code, self.code)
# Now the instance is saved, we need to update the original code to
# new code so that if the user uses .save() multiple time, it will not run
# update_code() multiple time
self.__original_code = self.code

# self.__original_points will be None if:
# - create new instance (should ignore)
# - The `points` field got deferred (not sure about this?)
# in both cases, we don't rescore submissions.
if self.__original_points is not None and self.points != self.__original_points:
self._rescore()
# same reason as update __original_code
self.__original_points = self.points

save.alters_data = True

Expand Down