diff --git a/opentech/apply/funds/blocks.py b/opentech/apply/funds/blocks.py index 06513827f13da391874045d3b3f3e0b8f6dc7815..7750bb0281cf2b1257fd67d529df2c23a8ed549f 100644 --- a/opentech/apply/funds/blocks.py +++ b/opentech/apply/funds/blocks.py @@ -1,9 +1,46 @@ from django.utils.translation import ugettext_lazy as _ +from django.utils.text import mark_safe -from opentech.apply.stream_forms.blocks import FormFieldsBlock +from wagtail.wagtailcore.blocks import StaticBlock +from opentech.apply.stream_forms.blocks import FormFieldsBlock, FormFieldBlock from opentech.apply.categories.blocks import CategoryQuestionBlock class CustomFormFieldsBlock(FormFieldsBlock): category = CategoryQuestionBlock(group=_('Custom')) + + def __init__(self, *args, **kwargs): + child_blocks = [(block.name, block(group=_('Required'))) for block in MustIncludeFieldBlock.__subclasses__()] + super().__init__(child_blocks, *args, **kwargs) + + +class MustIncludeStatic(StaticBlock): + def __init__(self, *args, description='', **kwargs): + self.description = description + super().__init__(*args, **kwargs) + + class Meta: + admin_text = 'Much be included in the form once.' + + def render_form(self, *args, **kwargs): + form = super().render_form(*args, **kwargs) + form = '<br>'.join([self.description, form]) + return mark_safe(form) + + +class MustIncludeFieldBlock(FormFieldBlock): + def __init__(self, *args, **kwargs): + info_name = f'{self.name}_field' + child_blocks = [(info_name, MustIncludeStatic(description=self.description))] + super().__init__(child_blocks, *args, **kwargs) + + +class TitleBlock(MustIncludeFieldBlock): + name = 'title' + description = 'The title of the project' + + +class ValueBlock(MustIncludeFieldBlock): + name = 'value' + description = 'The value of the project' diff --git a/opentech/apply/stream_forms/blocks.py b/opentech/apply/stream_forms/blocks.py index 8340e7433d801929dbc5e590294968ce5124725d..e5810e208f099c05843d0f2af190d651b6bd1374 100644 --- a/opentech/apply/stream_forms/blocks.py +++ b/opentech/apply/stream_forms/blocks.py @@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _ from unidecode import unidecode from wagtail.wagtailcore.blocks import ( StructBlock, TextBlock, CharBlock, BooleanBlock, ListBlock, StreamBlock, - DateBlock, TimeBlock, DateTimeBlock, ChoiceBlock, RichTextBlock, + DateBlock, TimeBlock, DateTimeBlock, ChoiceBlock, RichTextBlock,StaticBlock )