#NEWLINE# def create_object( request , model = None , template_name = None , template_loader = loader , extra_context = None , post_save_redirect = None , login_required = False , context_processors = None , form_class = None ) : #NEWLINE# #INDENT# '\n    Generic object-creation function.\n\n    Templates: ``<app_label>/<model_name>_form.html``\n    Context:\n        form\n            the form for the object\n    ' #NEWLINE# if ( extra_context is None ) : #NEWLINE# #INDENT# extra_context = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( login_required and ( not request . user . is_authenticated ( ) ) ) : #NEWLINE# #INDENT# return redirect_to_login ( request . path ) #NEWLINE# #UNINDENT# ( model , form_class ) = get_model_and_form_class ( model , form_class ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = form_class ( request . POST , request . FILES ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# new_object = form . save ( ) #NEWLINE# msg = ( ugettext ( 'The %(verbose_name)s was created successfully.' ) % { #NEWLINE# #INDENT# 'verbose_name' : model . _meta . verbose_name , #NEWLINE# #UNINDENT# } ) #NEWLINE# messages . success ( request , msg , fail_silently = True ) #NEWLINE# return redirect ( post_save_redirect , new_object ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = form_class ( ) #NEWLINE# #UNINDENT# if ( not template_name ) : #NEWLINE# #INDENT# template_name = ( '%s/%s_form.html' % ( model . _meta . app_label , model . _meta . object_name . lower ( ) ) ) #NEWLINE# #UNINDENT# t = template_loader . get_template ( template_name ) #NEWLINE# c = RequestContext ( request , { #NEWLINE# #INDENT# 'form' : form , #NEWLINE# #UNINDENT# } , extra_context ) #NEWLINE# apply_extra_context ( extra_context , c ) #NEWLINE# return HttpResponse ( t . render ( c ) )