From 549f14b2a6b6fd875df7de08c549576bd910dd1f Mon Sep 17 00:00:00 2001 From: sandeepsajan0 <sandeepsajan0@gmail.com> Date: Wed, 27 Apr 2022 18:31:06 +0530 Subject: [PATCH] Add comment and remove unnecesssary code lines --- hypha/apply/funds/admin_views.py | 9 +++++++++ hypha/apply/funds/blocks.py | 3 --- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hypha/apply/funds/admin_views.py b/hypha/apply/funds/admin_views.py index 679444f68..d828302fa 100644 --- a/hypha/apply/funds/admin_views.py +++ b/hypha/apply/funds/admin_views.py @@ -102,6 +102,10 @@ class CopyApplicationFormViewClass(CreateView): class CreateApplicationFormView(CreateView): def get_form(self): + """ + Overriding this method to disable the single file block option from Application Form. + Set 0 as max_number of single file can be added to make single file block option unavailable or disable. + """ form = super(CreateApplicationFormView, self).get_form() form.fields['form_fields'].block.meta.block_counts = {'file': {'min_num': 0, 'max_num': 0}} return form @@ -114,6 +118,11 @@ class CreateApplicationFormView(CreateView): class EditApplicationFormView(EditView): def get_form(self): + """ + Overriding this method to disable the single file block option from Application Form. + Calculating the number of Single file blocks that exist in the instance already. + And set that count as max_number of single file block can be added to make single file option disable. + """ form = super(EditApplicationFormView, self).get_form() single_file_count = sum(1 for block in self.get_instance().form_fields.raw_data if block['type'] == 'file') form.fields['form_fields'].block.meta.block_counts = {'file': {'min_num': 0, 'max_num': single_file_count}} diff --git a/hypha/apply/funds/blocks.py b/hypha/apply/funds/blocks.py index 266a90510..9a458e415 100644 --- a/hypha/apply/funds/blocks.py +++ b/hypha/apply/funds/blocks.py @@ -194,9 +194,6 @@ class ApplicationCustomFormFieldsBlock(CustomFormFieldsBlock, FormFieldsBlock): required_blocks = ApplicationMustIncludeFieldBlock.__subclasses__() single_blocks = ApplicationSingleIncludeFieldBlock.__subclasses__() - class Meta: - block_counts = {} - REQUIRED_BLOCK_NAMES = [block.name for block in ApplicationMustIncludeFieldBlock.__subclasses__()] -- GitLab