Skip to content
Snippets Groups Projects
Commit 1e9ae5c6 authored by sks444's avatar sks444
Browse files

When default screening status changes replace submission with new default

parent ed6504e0
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ from django.apps import apps ...@@ -4,6 +4,7 @@ from django.apps import apps
from wagtail.admin.forms import WagtailAdminModelForm, WagtailAdminPageForm from wagtail.admin.forms import WagtailAdminModelForm, WagtailAdminPageForm
from .workflow import WORKFLOWS from .workflow import WORKFLOWS
from .models.submissions import ApplicationSubmission
class WorkflowFormAdminForm(WagtailAdminPageForm): class WorkflowFormAdminForm(WagtailAdminPageForm):
...@@ -87,20 +88,25 @@ class RoundBasePageAdminForm(WagtailAdminPageForm): ...@@ -87,20 +88,25 @@ class RoundBasePageAdminForm(WagtailAdminPageForm):
class ScreeningStatusAdminForm(WagtailAdminModelForm): class ScreeningStatusAdminForm(WagtailAdminModelForm):
def clean(self): def save(self, commit=True):
cleaned_data = super().clean() default = self.cleaned_data['default']
default = cleaned_data['default'] yes = self.cleaned_data['yes']
yes = cleaned_data['yes']
ScreeningStatus = apps.get_model('funds', 'ScreeningStatus') ScreeningStatus = apps.get_model('funds', 'ScreeningStatus')
if default: if default:
try: try:
default_yes = ScreeningStatus.objects.get( default_screening = ScreeningStatus.objects.get(
default=True, yes=yes default=default, yes=yes
) )
except ScreeningStatus.DoesNotExist: except ScreeningStatus.DoesNotExist:
pass pass
else: else:
if default_yes.id != self.instance.id: screening = super().save(commit)
yes_or_no = 'yes' if yes else 'no' if default_screening.id != screening.id:
self.add_error('default', f'Can not set two ScreeningStatus as default {yes_or_no}') submissions = ApplicationSubmission.objects.filter(screening_statuses__id=default_screening.id)
return cleaned_data for submission in submissions:
submission.screening_statuses.remove(default_screening)
submission.screening_statuses.add(screening)
default_screening.default = False
default_screening.save()
return screening
return super().save(commit)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment