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_urlorsuccess_urlondynamic_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_codeforresponseis not 404 (NOT FOUND) this theFormModelMiddlewarewill 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
FormModelwhosesubmit_urlmatches the request’spath_info, this model is used to construct and render the view.If there is a
FormModelwhosesuccess_urlmatches the request’spath_info, this model is used to display the success page.Note
Since the
success_urlof aFormModelis 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 = Truethe respective exception is raised).
-