diff --git a/hypha/apply/funds/admin.py b/hypha/apply/funds/admin.py index 5a48fa379e1c497aa6126ccdcf483e7d2ec96eed..f120758328f903c6f9b1f529e2b0668c1e7551d9 100644 --- a/hypha/apply/funds/admin.py +++ b/hypha/apply/funds/admin.py @@ -113,6 +113,7 @@ class ScreeningStatusPermissionHelper(PermissionHelper): class ScreeningStatusAdmin(ModelAdmin): model = ScreeningStatus menu_icon = 'tag' + list_display = ('title', 'yes', 'default') permission_helper_class = ScreeningStatusPermissionHelper diff --git a/hypha/apply/funds/admin_forms.py b/hypha/apply/funds/admin_forms.py index 1cca6f9d2be4d20c9e877f863a8a8fdb9730a63b..73c6da525cef27fe781b09ef99fa9d7f4d898d27 100644 --- a/hypha/apply/funds/admin_forms.py +++ b/hypha/apply/funds/admin_forms.py @@ -1,6 +1,7 @@ from collections import Counter -from wagtail.admin.forms import WagtailAdminPageForm +from django.apps import apps +from wagtail.admin.forms import WagtailAdminModelForm, WagtailAdminPageForm from .workflow import WORKFLOWS @@ -82,3 +83,20 @@ class RoundBasePageAdminForm(WagtailAdminPageForm): self.add_error('start_date', 'Please select start date.') return cleaned_data + + +class ScreeningStatusAdminForm(WagtailAdminModelForm): + + def clean(self): + cleaned_data = super().clean() + default = cleaned_data['default'] + yes = cleaned_data['yes'] + ScreeningStatus = apps.get_model('funds', 'ScreeningStatus') + default_screening = ScreeningStatus.objects.filter( + default=True, yes=yes + ).first() + if default: + # Can't set two defaults for yes/no. + default_screening.default = False + default_screening.save() + return cleaned_data diff --git a/hypha/apply/funds/migrations/0080_add_yes_and_default_fields_to_screening_status.py b/hypha/apply/funds/migrations/0080_add_yes_and_default_fields_to_screening_status.py new file mode 100644 index 0000000000000000000000000000000000000000..c44ee4cc1d4f1808c80c62cf3a5d83023425830b --- /dev/null +++ b/hypha/apply/funds/migrations/0080_add_yes_and_default_fields_to_screening_status.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.16 on 2020-11-02 06:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('funds', '0079_add_reviewer_settings_for_submission_access'), + ] + + operations = [ + migrations.AddField( + model_name='screeningstatus', + name='default', + field=models.BooleanField(default=False, help_text='Only one Yes and No screening status can be set as default.', verbose_name='Default Yes/No'), + ), + migrations.AddField( + model_name='screeningstatus', + name='yes', + field=models.BooleanField(default=False, help_text='Tick mark for Yes otherwise No.', verbose_name='Yes/No'), + ), + ] diff --git a/hypha/apply/funds/models/screening.py b/hypha/apply/funds/models/screening.py index c590704b145651314664e60798c8a61ff563dc46..3c0084f5579b0530194b2b1beaa54d008a7bc2ea 100644 --- a/hypha/apply/funds/models/screening.py +++ b/hypha/apply/funds/models/screening.py @@ -1,8 +1,20 @@ from django.db import models +from ..admin_forms import ScreeningStatusAdminForm + class ScreeningStatus(models.Model): title = models.CharField(max_length=128) + yes = models.BooleanField( + default=False, verbose_name="Yes/No", + help_text='Tick mark for Yes otherwise No.' + ) + default = models.BooleanField( + default=False, verbose_name="Default Yes/No", + help_text='Only one Yes and No screening status can be set as default.' + ) + + base_form_class = ScreeningStatusAdminForm class Meta: verbose_name_plural = "screening statuses"