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 or success_url on dynamic_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:

  1. If the status_code for response is not 404 (NOT FOUND) this the FormModelMiddleware will return the response as-is and will not modify it. Thus, server error (5xx) will also not be affected by the middleware.

  2. If there is a FormModel whose submit_url matches the request’s path_info, this model is used to construct and render the view.

  3. If there is a FormModel whose success_url matches the request’s path_info, this model is used to display the success page.

    Note

    Since the success_url of a FormModel is not necessarily be unique, the first model that matches the request path will be used.

  4. If any errors occur while processing a form the original request is returned (if DEBUG = True the respective exception is raised).

Previous topic

Forms

Next topic

Models

This Page