605 |
605 |
form.attrs['style'] = 'display: none;'
|
606 |
606 |
if self.keywords:
|
607 |
607 |
form.attrs['data-keywords'] = ' '.join(self.keywords_list)
|
608 |
|
current_page_fields = []
|
609 |
|
on_disabled_page = False
|
610 |
|
on_page = False
|
611 |
|
for i, field in enumerate(self.fields):
|
612 |
|
if field.type == 'page':
|
613 |
|
on_disabled_page = False
|
614 |
|
if not field.is_visible(dict, self):
|
615 |
|
on_disabled_page = True
|
616 |
|
form_field = False
|
617 |
|
for f in self.fields[self.fields.index(field)+1:]:
|
618 |
|
if f.key == 'page':
|
619 |
|
break
|
620 |
|
if isinstance(f, fields.WidgetField):
|
621 |
|
form_field = True
|
622 |
|
break
|
623 |
|
if form_field is False:
|
624 |
|
on_disabled_page = True
|
625 |
608 |
|
626 |
|
if on_disabled_page:
|
627 |
|
continue
|
|
609 |
form_fields = self.fields
|
|
610 |
if form_fields and form_fields[0].type != 'page':
|
|
611 |
# add fake initial page in case it's missing
|
|
612 |
form_fields = [fields.PageField(label='', type='page')] + form_fields
|
628 |
613 |
|
|
614 |
# 1st pass to group fields on different pages
|
|
615 |
pages = []
|
|
616 |
current_page = {}
|
|
617 |
for field in form_fields:
|
629 |
618 |
if field.type == 'page':
|
630 |
|
if on_page:
|
631 |
|
form.widgets.append(HtmlWidget(htmltext('</div></div>')))
|
632 |
|
form.widgets.append(HtmlWidget(
|
633 |
|
htmltext('<div class="page"><h3>%s</h3><div>' % field.label)))
|
634 |
|
on_page = field
|
635 |
|
current_page_fields = []
|
|
619 |
current_page = {'page': field, 'fields': []}
|
|
620 |
current_page['disabled'] = not field.is_visible(dict, self)
|
|
621 |
pages.append(current_page)
|
636 |
622 |
continue
|
637 |
623 |
|
638 |
|
if field.type == 'title' and on_page and (
|
639 |
|
not current_page_fields and
|
640 |
|
on_page.label == field.label):
|
|
624 |
if current_page['disabled']:
|
|
625 |
continue
|
|
626 |
|
|
627 |
if field.type == 'title' and (
|
|
628 |
not current_page['fields'] and
|
|
629 |
current_page['page'].label == field.label):
|
641 |
630 |
# don't include first title of a page if that title has the
|
642 |
631 |
# same text as the page.
|
643 |
632 |
continue
|
644 |
633 |
|
645 |
|
if field.type == 'comment' and not field.include_in_validation_page:
|
|
634 |
if field.type in ('title', 'subtitle', 'comment') and not field.include_in_validation_page:
|
646 |
635 |
# don't render field that wouldn't be displayed.
|
647 |
636 |
continue
|
648 |
637 |
|
649 |
638 |
if not field.is_visible(dict, self):
|
650 |
639 |
continue
|
651 |
640 |
|
652 |
|
current_page_fields.append(field)
|
653 |
|
value = dict.get(field.id)
|
654 |
|
|
655 |
|
if not field.include_in_validation_page:
|
656 |
|
form.widgets.append(HtmlWidget(htmltext('<div style="display: none;">')))
|
657 |
|
field.add_to_view_form(form, value)
|
658 |
|
form.widgets.append(HtmlWidget(htmltext('</div>')))
|
659 |
|
else:
|
660 |
|
field.add_to_view_form(form, value)
|
|
641 |
current_page['fields'].append(field)
|
|
642 |
|
|
643 |
# 2nd pass to create view form
|
|
644 |
for page in pages:
|
|
645 |
visible_contents = False
|
|
646 |
if page['fields'] and any([x.include_in_validation_page for x in page['fields']]):
|
|
647 |
visible_contents = True
|
|
648 |
form.widgets.append(HtmlWidget(htmltext('<div class="page">')))
|
|
649 |
if page['page'].label:
|
|
650 |
form.widgets.append(HtmlWidget(htmltext('<h3>%s</h3>') % page['page'].label))
|
|
651 |
form.widgets.append(HtmlWidget(htmltext('<div>')))
|
|
652 |
|
|
653 |
for field in page['fields']:
|
|
654 |
value = dict.get(field.id)
|
|
655 |
if not field.include_in_validation_page:
|
|
656 |
form.widgets.append(HtmlWidget(htmltext('<div style="display: none;">')))
|
|
657 |
field.add_to_view_form(form, value)
|
|
658 |
form.widgets.append(HtmlWidget(htmltext('</div>')))
|
|
659 |
else:
|
|
660 |
field.add_to_view_form(form, value)
|
661 |
661 |
|
662 |
|
if on_page:
|
663 |
|
form.widgets.append(HtmlWidget(htmltext('</div></div>')))
|
|
662 |
if visible_contents:
|
|
663 |
form.widgets.append(HtmlWidget(htmltext('</div></div>')))
|
664 |
664 |
|
665 |
665 |
return form
|
666 |
666 |
|
667 |
|
-
|