Middlewares¶
-
class
dynamic_forms.middlewares.
FormModelMiddleware
¶ This middleware intercepts all HTTP 404 responses and checks if there is a form mapped to this URL. This way an explicit URL mapping from the projects ROOT_URLCONF cannot accidentally be overridden by wrong setting for
submit_url
orsuccess_url
ondynamic_forms.models.FormModel
.This technique is comparable to the one used by Django’s
FlatpageFallbackMiddleware
.-
process_response
(request, response)¶ The algorithm that decides if and which form to display works like this:
If the
status_code
forresponse
is not 404 (NOT FOUND
) this theFormModelMiddleware
will return the response as-is and will not modify it. Thus, server error (5xx) will also not be affected by the middleware.If there is a
FormModel
whosesubmit_url
matches the request’spath_info
, this model is used to construct and render the view.If there is a
FormModel
whosesuccess_url
matches the request’spath_info
, this model is used to display the success page.Note
Since the
success_url
of aFormModel
is not necessarily be unique, the first model that matches the request path will be used.If any errors occur while processing a form the original request is returned (if
DEBUG = True
the respective exception is raised).
-