Package expedient :: Package common :: Package utils :: Module views
[hide private]
[frames] | no frames]

Module views

source code

Created on Jun 18, 2010


Author: jnaous

Functions [hide private]
 
generic_crud(request, obj_id, model, template, redirect, extra_context={}, form_class=None, extra_form_params={}, template_object_name='object', pre_save=None, post_save=None, success_msg=None)
Generic way to create/update a bit more advanced than the django's generic views.
source code
Variables [hide private]
  __package__ = 'expedient.common.utils'
Function Details [hide private]

generic_crud(request, obj_id, model, template, redirect, extra_context={}, form_class=None, extra_form_params={}, template_object_name='object', pre_save=None, post_save=None, success_msg=None)

source code 

Generic way to create/update a bit more advanced than the django's generic views. The context will contain the form as form, the object when updating as the value in template_object_name which defaults to "object", and anything specified in extra_context.

Parameters:
  • request - The request object
  • obj_id - The object's id to update or None if creating an object
  • model - The model class
  • template - the name of the template to use
  • redirect - callable that takes the created/saved instance as argument and returns a URL to redirect to.
  • extra_context - dict of fields to add to the template context.
  • form_class - the form class to use for the object (ModelForm subclass)
  • extra_form_params - dict of additional keyword parameters to pass to the form when init'ing the form instance.
  • template_object_name - name of the object field in the template context. This is only available when updating.
  • pre_save - function to call before saving the object instantiated from the form. Called with arguments (instance, created).
  • post_save - function to call after saving the object instantiated from the form but before calling m2m_save() on it. Called with argument (instance, created).
  • success_msg - callable that should take instance as parameter and return a string to be put in a success DatedMessage and sent to the user on success.