Move dirty logic to admin
This commit is contained in:
parent
e1a38d42c3
commit
11bc57f2b1
4 changed files with 38 additions and 31 deletions
|
@ -33,6 +33,7 @@ from judge.widgets import (
|
|||
CheckboxSelectMultipleWithSelectAll,
|
||||
HeavyPreviewAdminPageDownWidget,
|
||||
)
|
||||
from judge.utils.problems import user_editable_ids, user_tester_ids
|
||||
|
||||
MEMORY_UNITS = (("KB", "KB"), ("MB", "MB"))
|
||||
|
||||
|
@ -359,12 +360,31 @@ class ProblemAdmin(CompareVersionAdmin):
|
|||
self._rescore(request, obj.id)
|
||||
|
||||
def save_related(self, request, form, formsets, change):
|
||||
editors = set()
|
||||
testers = set()
|
||||
if "curators" in form.changed_data or "authors" in form.changed_data:
|
||||
editors = set(form.instance.editor_ids)
|
||||
if "testers" in form.changed_data:
|
||||
testers = set(form.instance.tester_ids)
|
||||
|
||||
super().save_related(request, form, formsets, change)
|
||||
# Only rescored if we did not already do so in `save_model`
|
||||
obj = form.instance
|
||||
obj.curators.add(request.profile)
|
||||
obj.is_organization_private = obj.organizations.count() > 0
|
||||
obj.save()
|
||||
|
||||
if "curators" in form.changed_data or "authors" in form.changed_data:
|
||||
del obj.editor_ids
|
||||
editors = editors.union(set(obj.editor_ids))
|
||||
if "testers" in form.changed_data:
|
||||
del obj.tester_ids
|
||||
testers = testers.union(set(obj.tester_ids))
|
||||
|
||||
for editor in editors:
|
||||
user_editable_ids.dirty(editor)
|
||||
for tester in testers:
|
||||
user_tester_ids.dirty(tester)
|
||||
|
||||
# Create notification
|
||||
if "is_public" in form.changed_data or "organizations" in form.changed_data:
|
||||
users = set(obj.authors.all())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue