@@ -205,8 +205,8 @@ def __init__(self, user, queryset=None, ):
205205 @param queryset: Queryset to use for export, Default to full quetyset
206206 """
207207 super ().__init__ ()
208- self ._user = user
209208 self ._queryset = queryset
209+ self ._user = user
210210
211211 @classmethod
212212 def validate_and_sort_dataset (cls , dataset ):
@@ -221,10 +221,9 @@ def after_import_instance(self, instance, new, **kwargs):
221221 def import_obj (self , instance , row , dry_run , ** kwargs ):
222222 instance .head = row ['head' ]
223223 instance .current_village_id = row ['village_id' ]
224-
225224 if not instance .id :
226225 instance .card_issued = False
227- instance . audit_user_id = self . _user . i_user . id
226+
228227
229228 if not instance .head :
230229 family = Family .objects .all ().filter (validity_to__isnull = True ) \
@@ -239,15 +238,22 @@ def import_obj(self, instance, row, dry_run, **kwargs):
239238 # important to be at the end
240239 super ().import_obj (instance , row , dry_run , ** kwargs )
241240
242- def after_save_instance (self , instance , using_transactions , dry_run ):
243- super ().after_save_instance (instance , using_transactions , dry_run )
241+ def after_save_instance (self , instance , row , ** kwargs ):
242+ super ().after_save_instance (instance , row , ** kwargs )
244243 if instance .head :
245244 # if not using_transactions and dry_run this code will cause changes in database on dry run
246- if using_transactions or not dry_run :
245+ if not kwargs . get ( ' using_transactions' , False ) or not kwargs . get ( ' dry_run' , False ) :
247246 instance .family = self .create_family (instance )
248247 instance .current_village = None
249248 instance .save ()
250-
249+ def before_save_instance (self , instance , row , ** kwargs ):
250+ if hasattr (instance , 'audit_user_id' ):
251+ if self ._user and self ._user ._u .id :
252+ instance .audit_user_id = self ._user ._u .id
253+ else :
254+ instance .audit_user_id = - 1
255+ logger .warning (_ ("im_export.save_without_user" ))
256+
251257 def create_family (self , instance ):
252258 return Family .objects .create (** {
253259 'validity_from' : datetime .now (),
0 commit comments