-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forms: More easily overridable landing page rendering #4024
Forms: More easily overridable landing page rendering #4024
Conversation
wagtail/wagtailforms/models.py
Outdated
self.get_landing_page_template(request), | ||
self.get_context(request) | ||
) | ||
|
||
def serve(self, request, *args, **kwargs): | ||
if request.method == 'POST': | ||
form = self.get_form(request.POST, request.FILES, page=self, user=request.user) | ||
|
||
if form.is_valid(): | ||
self.process_form_submission(form) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate of comment on #2834
We need a way to ensure that the form_submission instance can be passed to the context of the landing page.
As per this outstanding item in #2833
The FormSubmission instance should then be passed to the render context for the "landing page".
the render_landing_page
method should also accept a parameter form_submission
.
Which should be generated by updating the line:
self.process_form_submission(form)
to
form_submission = self.process_form_submission(form)
Then
return self.render_landing_page(request, *args, **kwargs)
to
return self.render_landing_page(request, form_submission=form_submission, *args, **kwargs)
Finally, the context should be updated in the render_landing_page return render eg.
# TODO: It is much better to redirect to it
context = self.get_context(request)
context['form_submission'] = form_submission
return render(
request,
self.get_landing_page_template(request),
context
)
I've added the form_submission to the context as suggested. |
(Nevermind, i forgot about preview) |
@strindhaug when you are editing a form page, there is a way to preview both the form and the landing page easily. Does that achieve the goal you wanted? Screenshot attached. This made me realise that Also, you will need to update the preview code here to ensure that previews of landing page use the new https://github.com/wagtail/wagtail/blob/master/wagtail/wagtailforms/models.py#L295 |
Oh, I didn't realize there was a preview mode for it, that's nice. =) Well then the parameter idea is pointless. I've updated the serve_preview and made the form_submission optional with default value |
@strindhaug are you able to put in some additional tests? possibly a model that overrides this method (eg. add something to the context or render with a different template) - to ensure that it gets used in both normal and preview mode and also that the default landing page contains the form_submission in the context let me know if you need a hand |
I started creating a form that redirects instead of landing page but it fails before it starts because the table is missing. Also, is there any deterministic data in the default form_submission that can be outputted easily in the template that doesn't require modifying the model? I tried outputting |
Hi @strindhaug - you can create migrations for the test app by running django-admin.py makemigrations --settings=wagtail.tests.settings from the Wagtail root. |
Previously answered [here](#4024 (comment)) and [here](https://groups.google.com/forum/#!msg/wagtail-developers/P6x9N5qzq-I/0gbRzWgBBgAJ). Just adding this into these docs for future contributors.
@strindhaug as This Stack Overflow question has a bunch of ways, depending on what is needed. There is no default Django tag to get values from keys in a dict though. eg. something like:
|
Previously answered [here](#4024 (comment)) and [here](https://groups.google.com/forum/#!msg/wagtail-developers/P6x9N5qzq-I/0gbRzWgBBgAJ). Just adding this into these docs for future contributors.
Cleaner test for form_submission in normal form. Output and test the username field from the custom form submission.
Used the for loop you suggested. Though it's sort of meaningless thing to output, at least it's testing that the form_submission is added somewhat cleanly without having lots of html entities in the test code. Added a similar test to the |
self.get_context(request) | ||
) | ||
form_submission = self.process_form_submission(form) | ||
# Forwarding args and kwargs just in case for flexibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment can be removed.
@strindhaug added one minor comment - just to remove a comment you added about the passing of args/kwargs, I don't think that is needed. I will bring this up at our dev meeting today. @tomdyson FYI |
@strindhaug one last thing is adding some docs about this new awesome feature. Best to put them at the end of this docs page which is built from docs/reference/contrib/forms/customisation.rst. Items that need updating (from a quick look)
Let me know if you need a hand. |
@gasman I have committed these changes to master, struggled a bit with the rebase though. The commits are not linked to this PR correctly but they are there, should I close this PR now? |
@lb- Yes please. Having to close PRs manually is normal behaviour when you rebase them on the command line. |
Merged |
Move the landing page rendering to an easily overridable method.
Partial fix/improvement for #2834