diff --git a/opentech/apply/funds/admin.py b/opentech/apply/funds/admin.py index 30c750fd9e9aac950eddef504244ef14cb60e73d..9cde07a20e37691c651711b4e965e8de54cee986 100644 --- a/opentech/apply/funds/admin.py +++ b/opentech/apply/funds/admin.py @@ -3,7 +3,7 @@ from django.utils.html import mark_safe from wagtail.contrib.modeladmin.helpers import PermissionHelper from wagtail.contrib.modeladmin.options import ModelAdmin, ModelAdminGroup -from opentech.apply.review.models import ReviewForm +from opentech.apply.review.admin import ReviewFormAdmin from .admin_helpers import ( ButtonsWithPreview, FormsFundRoundListFilter, @@ -68,11 +68,6 @@ class ApplicationFormAdmin(ModelAdmin): return mark_safe('<br>'.join(rows)) -class ReviewFormAdmin(ModelAdmin): - model = ReviewForm - menu_icon = 'form' - - class ApplyAdminGroup(ModelAdminGroup): menu_label = 'Apply' menu_icon = 'folder-open-inverse' diff --git a/opentech/apply/review/admin.py b/opentech/apply/review/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..ea6c485bc0d7bf46116486cb556a24a7c64936b2 --- /dev/null +++ b/opentech/apply/review/admin.py @@ -0,0 +1,8 @@ +from wagtail.contrib.modeladmin.options import ModelAdmin + +from opentech.apply.review.models import ReviewForm + + +class ReviewFormAdmin(ModelAdmin): + model = ReviewForm + menu_icon = 'form' diff --git a/opentech/apply/review/models.py b/opentech/apply/review/models.py index c50f85174e12a6bfdbe863cf428fe36aa762ce8f..63907a74c7711805a227832cce270202539ce5f5 100644 --- a/opentech/apply/review/models.py +++ b/opentech/apply/review/models.py @@ -12,7 +12,7 @@ from opentech.apply.activity.models import Activity from opentech.apply.review.options import YES, NO, MAYBE, RECOMMENDATION_CHOICES from opentech.apply.users.models import User -from .blocks import ReviewCustomFormFieldsBlock, ReviewMustIncludeFieldBlock +from .blocks import ReviewCustomFormFieldsBlock class ReviewForm(models.Model): @@ -98,30 +98,11 @@ class Review(models.Model): return reverse('apply:reviews:review', args=(self.id,)) def __str__(self): - return f'Review for {self.page.title} by {self.author!s}' + return f'Review for {self.submission.title} by {self.author!s}' def __repr__(self): return f'<{self.__class__.__name__}: {str(self.form_data)}>' - @property - def must_include(self): - return { - field.block.name: field.id - for field in self.form_fields - if isinstance(field.block, ReviewMustIncludeFieldBlock) - } - - def clean_submission(self): - for field_name, field_id in self.must_include.items(): - response = self.form_data.pop(field_id, None) - if response: - self.form_data[field_name] = response - - def save(self, *args, **kwargs): - self.clean_submission() - - super().save(*args, **kwargs) - @receiver(post_save, sender=Review) def update_submission_reviewers_list(sender, **kwargs): diff --git a/opentech/apply/utils/blocks.py b/opentech/apply/utils/blocks.py index 0aabdf1465e3f961fa0132a2f1ba5d722864d066..3df0908995fc3a92ed3460762bafac95f9f6d24d 100644 --- a/opentech/apply/utils/blocks.py +++ b/opentech/apply/utils/blocks.py @@ -41,8 +41,7 @@ class RichTextFieldBlock(TextFieldBlock): class CustomFormFieldsBlock(StreamBlock): rich_text = RichTextFieldBlock(group=_('Fields')) - required_blocks = None - required_block_names = None + required_blocks = [] def __init__(self, *args, **kwargs): child_blocks = [(block.name, block(group=_('Required'))) for block in self.required_blocks] @@ -96,6 +95,10 @@ class CustomFormFieldsBlock(StreamBlock): ) def to_python(self, value): + """ + This allows historic data to still be accessible even + if a custom field type is removed from the code in the future. + """ # If the data type is missing, fallback to a CharField for child_data in value: if child_data['type'] not in self.child_blocks: