Skip to content

Commit 8c594b2

Browse files
authored
Merge pull request #20 from openimis/release/25.04
MERGING release/25.04 into develop
2 parents 83d2520 + bb4d385 commit 8c594b2

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

im_export/resources.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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(),

im_export/tests/test_insuree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def test_simple_import(self):
7979

8080
dir_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
8181
resource = InsureeResource(user=self.user)
82+
#with Patch("ImportExportConfig.im_export_date_format", '%m/%d/%Y')
8283
with open(os.path.join(dir_path, 'tests/import_example.csv'), 'r') as f:
8384
imported_data = resource \
8485
.validate_and_sort_dataset(Dataset(headers=InsureeResource.insuree_headers).load(f.read()))

im_export/views.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@
66
from rest_framework.response import Response
77
from insuree.apps import InsureeConfig
88
from .services import InsureeImportExportService
9+
from core.views import check_user_rights
910

1011
logger = logging.getLogger(__name__)
1112

1213

13-
def check_user_rights(rights):
14-
class UserWithRights(IsAuthenticated):
15-
def has_permission(self, request, view):
16-
return super().has_permission(request, view) and request.user.has_perms(rights)
17-
18-
return UserWithRights
1914

2015

2116
@api_view(["POST"])

0 commit comments

Comments
 (0)