diff --git a/hypha/apply/funds/admin_views.py b/hypha/apply/funds/admin_views.py index 4b3dbef3650eb7b58a612508130b72e61790350d..d828302fa5c073a31132cab9a91e82f4f4162529 100644 --- a/hypha/apply/funds/admin_views.py +++ b/hypha/apply/funds/admin_views.py @@ -101,6 +101,15 @@ 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 + def form_invalid(self, form): show_admin_form_error_messages(self.request, form) return self.render_to_response(self.get_context_data(form=form)) @@ -108,6 +117,17 @@ 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}} + return form + def form_invalid(self, form): show_admin_form_error_messages(self.request, form) return self.render_to_response(self.get_context_data(form=form)) diff --git a/hypha/apply/stream_forms/blocks.py b/hypha/apply/stream_forms/blocks.py index f4bba3a4b423fd89b6792ed4e17639d501887765..4abc4c2758f744193a96fb122b96ec81b97bc8cd 100644 --- a/hypha/apply/stream_forms/blocks.py +++ b/hypha/apply/stream_forms/blocks.py @@ -429,6 +429,7 @@ class MultiFileFieldBlock(UploadableMediaBlock): field_class = MultiFileField class Meta: + icon = 'download' label = _('Multiple File field') template = 'stream_forms/render_multi_file_field.html'