Skip to content
Snippets Groups Projects
Commit 81886377 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Defer to the submitted data to find certain information

parent 58887516
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
{% for submission in applicationsubmission_list %}
<tr>
<td>
{{ submission }}
{{ submission.title }}
</td>
</tr>
{% empty %}
......
......@@ -26,15 +26,14 @@ class CustomFormFieldsBlock(FormFieldsBlock):
else:
error_dict = dict()
required_block_names = [block.name for block in MustIncludeFieldBlock.__subclasses__()]
block_types = [block.block_type for block in value]
missing = set(required_block_names) - set(block_types)
missing = set(REQUIRED_BLOCK_NAMES) - set(block_types)
counted_types = Counter(block_types)
duplicates = [
name for name, count in counted_types.items()
if name in required_block_names and count > 1
if name in REQUIRED_BLOCK_NAMES and count > 1
]
all_errors = list()
......@@ -75,6 +74,7 @@ class MustIncludeStatic(StaticBlock):
def render_form(self, *args, **kwargs):
errors = kwargs.pop('errors')
if errors:
# Pretend the error is a readonly input so that we get nice formatting
error_message= '<div class="error"><input readonly placeholder="{}"></div>'.format(errors[0])
else:
error_message = ''
......@@ -98,3 +98,6 @@ class TitleBlock(MustIncludeFieldBlock):
class ValueBlock(MustIncludeFieldBlock):
name = 'value'
description = 'The value of the project'
REQUIRED_BLOCK_NAMES = [block.name for block in MustIncludeFieldBlock.__subclasses__()]
......@@ -21,7 +21,7 @@ from wagtail.wagtailforms.models import AbstractFormSubmission
from opentech.apply.stream_forms.models import AbstractStreamForm
from .blocks import CustomFormFieldsBlock
from .blocks import CustomFormFieldsBlock, REQUIRED_BLOCK_NAMES
from .forms import WorkflowFormAdminForm
from .workflow import SingleStage, DoubleStage
......@@ -189,4 +189,8 @@ class Round(AbstractStreamForm):
class ApplicationSubmission(AbstractFormSubmission):
pass
def __getattr__(self, item):
# fall back to values defined on the data
if item in REQUIRED_BLOCK_NAMES:
return self.get_data()[item]
return super().__getattr__(item)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment