diff --git a/hypha/apply/funds/admin_views.py b/hypha/apply/funds/admin_views.py index 679444f6887b70c5b5dd8d5b9b906682c09b170c..d828302fa5c073a31132cab9a91e82f4f4162529 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 266a9051054c38da92def89cd0b293ad4423d98d..9a458e415908b0fe07f4c0828bcc218958078569 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__()]