#NEWLINE# @ csrf_protect_m #NEWLINE# @ transaction . atomic #NEWLINE# def bulk_view( self , request , form_url = '' , extra_context = None ) : #NEWLINE# #INDENT# to_field = request . POST . get ( TO_FIELD_VAR , request . GET . get ( TO_FIELD_VAR ) ) #NEWLINE# if ( to_field and ( not self . to_field_allowed ( request , to_field ) ) ) : #NEWLINE# #INDENT# raise DisallowedModelAdminToField ( ( 'The field %s cannot be referenced.' % to_field ) ) #NEWLINE# #UNINDENT# model = self . model #NEWLINE# opts = model . _meta #NEWLINE# continue_requested = request . POST . get ( '_continue' , request . GET . get ( '_continue' ) ) #NEWLINE# force_continue = False #NEWLINE# inline = self . get_bulk_inline ( request ) #NEWLINE# formset_class = inline . get_formset ( request ) #NEWLINE# formset_params = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# prefix = formset_class . get_default_prefix ( ) #NEWLINE# queryset = inline . get_queryset ( request ) #NEWLINE# if ( not self . has_add_permission ( request ) ) : #NEWLINE# #INDENT# formset_class . max_num = 0 #NEWLINE# #UNINDENT# if ( request . method == 'GET' ) : #NEWLINE# #INDENT# if ( ( 'pks' in request . GET ) and self . has_change_permission ( request ) ) : #NEWLINE# #INDENT# pks = [ opts . pk . to_python ( pk ) for pk in request . GET . get ( 'pks' ) . split ( ',' ) ] #NEWLINE# queryset = queryset . filter ( pk__in = pks ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# queryset = queryset . none ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# management_form = ManagementForm ( request . POST , prefix = prefix ) #NEWLINE# if ( not management_form . is_valid ( ) ) : #NEWLINE# #INDENT# raise ValidationError ( _ ( 'ManagementForm data is missing or has been tampered with' ) , code = 'missing_management_form' ) #NEWLINE# #UNINDENT# if ( ( not self . has_add_permission ( request ) ) and ( management_form . cleaned_data [ INITIAL_FORM_COUNT ] < management_form . cleaned_data [ TOTAL_FORM_COUNT ] ) ) : #NEWLINE# #INDENT# raise PermissionDenied #NEWLINE# #UNINDENT# if ( ( not self . has_change_permission ( request ) ) and ( management_form . cleaned_data [ INITIAL_FORM_COUNT ] > 0 ) ) : #NEWLINE# #INDENT# raise PermissionDenied #NEWLINE# #UNINDENT# queryset = self . transform_queryset ( request , queryset , management_form , prefix ) #NEWLINE# ( post , files , force_continue ) = self . transform_post_and_files ( request , prefix ) #NEWLINE# formset_params . update ( { #NEWLINE# #INDENT# 'data' : post , #NEWLINE# 'files' : files , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# formset_params [ 'queryset' ] = pk #NEWLINE# formset = formset_class ( ** formset_params ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# if formset . is_valid ( ) : #NEWLINE# #INDENT# self . save_formset ( request , form = None , formset = formset , change = False ) #NEWLINE# if ( continue_requested or force_continue ) : #NEWLINE# #INDENT# if self . has_change_permission ( request ) : #NEWLINE# #INDENT# queryset = _ListQueryset ( queryset ) #NEWLINE# queryset . extend ( formset . new_objects ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# queryset = _ListQueryset ( ) #NEWLINE# #UNINDENT# formset_params . update ( { #NEWLINE# #INDENT# 'data' : None , #NEWLINE# 'files' : None , #NEWLINE# 'queryset' : queryset , #NEWLINE# #UNINDENT# } ) #NEWLINE# formset = formset_class ( ** formset_params ) #NEWLINE# msg = ( _ ( 'The %s were bulk added successfully. You may edit them again below.' ) % ( force_text ( opts . verbose_name_plural ) , ) ) #NEWLINE# self . message_user ( request , msg , messages . SUCCESS ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . response_bulk ( request , formset ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# media = self . media #NEWLINE# inline_formsets = self . get_inline_formsets ( request , [ formset ] , [ inline ] , obj = None ) #NEWLINE# for inline_formset in inline_formsets : #NEWLINE# #INDENT# media = ( media + inline_formset . media ) #NEWLINE# #UNINDENT# errors = ErrorList ( ) #NEWLINE# if formset . is_bound : #NEWLINE# #INDENT# errors . extend ( formset . non_form_errors ( ) ) #NEWLINE# for formset_errors in formset . errors : #NEWLINE# #INDENT# errors . extend ( list ( six . itervalues ( formset_errors ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# context = dict ( ( self . admin_site . each_context ( request ) if ( django . VERSION >= ( 1 , 8 ) ) else self . admin_site . each_context ( ) ) , bulk = True , bulk_formset_prefix = prefix , bulk_upload_fields = self . get_bulk_upload_fields ( request ) , title = ( _ ( 'Bulk add %s' ) % force_text ( opts . verbose_name_plural ) ) , is_popup = ( ( IS_POPUP_VAR in request . POST ) or ( IS_POPUP_VAR in request . GET ) ) , to_field = to_field , media = media , inline_admin_formsets = inline_formsets , errors = errors , preserved_filters = self . get_preserved_filters ( request ) ) #NEWLINE# context . update ( ( extra_context or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) #NEWLINE# return self . render_change_form ( request , context , add = True , change = False , obj = None , form_url = form_url )