#NEWLINE# @ csrf_protect_m #NEWLINE# @ atomic_decorator #NEWLINE# def change_view( self , request , object_id , extra_context = None , **kwargs ) : #NEWLINE# #INDENT# "The 'change' admin view for this model." #NEWLINE# model = self . model #NEWLINE# opts = model . _meta #NEWLINE# obj = self . get_object ( request , unquote ( object_id ) ) #NEWLINE# if ( not self . has_change_permission ( request , obj ) ) : #NEWLINE# #INDENT# raise PermissionDenied #NEWLINE# #UNINDENT# if ( obj is None ) : #NEWLINE# #INDENT# raise Http404 ( ( _ ( '%(name)s object with primary key %(key)r does not exist.' ) % { #NEWLINE# #INDENT# 'name' : force_unicode ( opts . verbose_name ) , #NEWLINE# 'key' : escape ( object_id ) , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# if ( ( request . method == 'POST' ) and ( '_saveasnew' in request . POST ) ) : #NEWLINE# #INDENT# return self . add_view ( request , form_url = '../add/' ) #NEWLINE# #UNINDENT# ModelForm = self . get_form ( request , obj ) #NEWLINE# formsets = [ ] #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = ModelForm ( request . POST , request . FILES , instance = obj ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# form_validated = True #NEWLINE# new_object = self . save_form ( request , form , change = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# form_validated = False #NEWLINE# new_object = obj #NEWLINE# #UNINDENT# prefixes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( FormSet , inline ) in zip ( self . get_formsets ( request , new_object ) , self . get_inline_instances ( request ) ) : #NEWLINE# #INDENT# prefix = FormSet . get_default_prefix ( ) #NEWLINE# prefixes [ prefix ] = ( prefixes . get ( prefix , 0 ) + 1 ) #NEWLINE# if ( prefixes [ prefix ] != 1 ) : #NEWLINE# #INDENT# prefix = '{0}-{1}' . format ( prefix , prefixes [ prefix ] ) #NEWLINE# #UNINDENT# formset = FormSet ( request . POST , request . FILES , instance = new_object , prefix = prefix , queryset = inline . queryset ( request ) ) #NEWLINE# formsets . append ( formset ) #NEWLINE# for inline in self . get_inline_instances ( request ) : #NEWLINE# #INDENT# if ( inline . inlines and ( inline . model == formset . model ) ) : #NEWLINE# #INDENT# for nested in inline . inline_instances : #NEWLINE# #INDENT# for the_form in formset . forms : #NEWLINE# #INDENT# InlineFormSet = nested . get_formset ( request , the_form . instance ) #NEWLINE# prefix = '{0}-{1}' . format ( the_form . prefix , InlineFormSet . get_default_prefix ( ) ) #NEWLINE# formsets . append ( InlineFormSet ( request . POST , request . FILES , instance = the_form . instance , prefix = prefix ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( all_valid ( formsets ) and form_validated ) : #NEWLINE# #INDENT# self . save_model ( request , new_object , form , change = True ) #NEWLINE# form . save_m2m ( ) #NEWLINE# for formset in formsets : #NEWLINE# #INDENT# self . save_formset ( request , form , formset , change = True ) #NEWLINE# #UNINDENT# change_message = self . construct_change_message ( request , form , formsets ) #NEWLINE# self . log_change ( request , new_object , change_message ) #NEWLINE# return self . response_change ( request , new_object ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = ModelForm ( instance = obj ) #NEWLINE# prefixes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( FormSet , inline ) in zip ( self . get_formsets ( request , obj ) , self . get_inline_instances ( request ) ) : #NEWLINE# #INDENT# prefix = FormSet . get_default_prefix ( ) #NEWLINE# prefixes [ prefix ] = ( prefixes . get ( prefix , 0 ) + 1 ) #NEWLINE# if ( prefixes [ prefix ] != 1 ) : #NEWLINE# #INDENT# prefix = '{0}-{1}' . format ( prefix , prefixes [ prefix ] ) #NEWLINE# #UNINDENT# formset = FormSet ( instance = obj , prefix = prefix , queryset = inline . queryset ( request ) ) #NEWLINE# formsets . append ( formset ) #NEWLINE# #UNINDENT# #UNINDENT# adminForm = helpers . AdminForm ( form , self . get_fieldsets ( request , obj ) , self . prepopulated_fields , self . get_readonly_fields ( request , obj ) , model_admin = self ) #NEWLINE# media = ( self . media + adminForm . media ) #NEWLINE# inline_admin_formsets = [ ] #NEWLINE# for ( inline , formset ) in zip ( self . get_inline_instances ( request ) , formsets ) : #NEWLINE# #INDENT# fieldsets = list ( inline . get_fieldsets ( request , obj ) ) #NEWLINE# readonly = list ( inline . get_readonly_fields ( request , obj ) ) #NEWLINE# inline_admin_formset = helpers . InlineAdminFormSet ( inline , formset , fieldsets , readonly , model_admin = self ) #NEWLINE# if inline . inlines : #NEWLINE# #INDENT# for form in formset . forms : #NEWLINE# #INDENT# if form . instance . pk : #NEWLINE# #INDENT# instance = form . instance #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# instance = None #NEWLINE# #UNINDENT# form . inlines = inline . get_inlines ( request , instance , prefix = form . prefix ) #NEWLINE# #UNINDENT# inline_admin_formset . inlines = inline . get_inlines ( request ) #NEWLINE# #UNINDENT# inline_admin_formsets . append ( inline_admin_formset ) #NEWLINE# media = ( media + inline_admin_formset . media ) #NEWLINE# #UNINDENT# context = { #NEWLINE# #INDENT# 'title' : ( _ ( 'Change %s' ) % force_unicode ( opts . verbose_name ) ) , #NEWLINE# 'adminform' : adminForm , #NEWLINE# 'object_id' : object_id , #NEWLINE# 'original' : obj , #NEWLINE# 'is_popup' : ( '_popup' in request . REQUEST ) , #NEWLINE# 'media' : mark_safe ( media ) , #NEWLINE# 'inline_admin_formsets' : inline_admin_formsets , #NEWLINE# 'errors' : helpers . AdminErrorList ( form , formsets ) , #NEWLINE# 'app_label' : opts . app_label , #NEWLINE# #UNINDENT# } #NEWLINE# context . update ( ( extra_context or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# return self . render_change_form ( request , context , change = True , obj = obj )