<commit_before>'''
Created on Jun 18, 2010

@author: jnaous
'''
from django.shortcuts import get_object_or_404
from django.views.generic.create_update import get_model_and_form_class
from django.views.generic import simple
from django.http import HttpResponseRedirect, HttpResponseNotAllowed
from expedient.common.messaging.models import DatedMessage

def 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. The context will contain the form as C{form}, the object when
    updating as the value in C{template_object_name} which defaults to
    "object", and anything specified in C{extra_context}.
    
    @param request: The request object
    @param obj_id: The object's id to update or None if creating an object
    @param model: The model class
    @param template: the name of the template to use
    @param redirect: callable that takes the created/saved instance as argument
        and returns a URL to redirect to.
    @keyword extra_context: dict of fields to add to the template context.
    @keyword form_class: the form class to use for the object
        (ModelForm subclass)
    @keyword extra_form_params: dict of additional keyword parameters to pass
        to the form.
    @keyword template_object_name: name of the object field in the template
        context. This is only available when updating.
    @keyword pre_save: function to call before saving the object instantiated
        from the form. Called with arguments (C{instance}, C{created}).
    @keyword post_save: function to call after saving the object instantiated<commit_msg>minor doc update<commit_after>'''
Created on Jun 18, 2010

@author: jnaous
'''
from django.shortcuts import get_object_or_404
from django.views.generic.create_update import get_model_and_form_class
from django.views.generic import simple
from django.http import HttpResponseRedirect, HttpResponseNotAllowed
from expedient.common.messaging.models import DatedMessage

def 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. The context will contain the form as C{form}, the object when
    updating as the value in C{template_object_name} which defaults to
    "object", and anything specified in C{extra_context}.
    
    @param request: The request object
    @param obj_id: The object's id to update or None if creating an object
    @param model: The model class
    @param template: the name of the template to use
    @param redirect: callable that takes the created/saved instance as argument
        and returns a URL to redirect to.
    @keyword extra_context: dict of fields to add to the template context.
    @keyword form_class: the form class to use for the object
        (ModelForm subclass)
    @keyword extra_form_params: dict of additional keyword parameters to pass
        to the form when init'ing the form instance.
    @keyword template_object_name: name of the object field in the template
        context. This is only available when updating.
    @keyword pre_save: function to call before saving the object instantiated
        from the form. Called with arguments (C{instance}, C{created}).
    @keyword post_save: function to call after saving the object instantiated
{'fraction_non_alphanumeric': 0.05744055570398077, 'fraction_numerical': 0.004808976756612343, 'mean_word_length': 3.7035175879396984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3859047', 'n_tokens_mistral': 973, 'n_tokens_neox': 943, 'n_words': 426}