summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_finds/models_finds.py4
-rw-r--r--archaeological_finds/tests.py8
-rw-r--r--ishtar_common/utils.py13
3 files changed, 21 insertions, 4 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index e53706e9a..706a2bbbf 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -2439,6 +2439,10 @@ class Find(
new.upstream_treatment, new.downstream_treatment = None, None
new.uuid = uuid.uuid4()
new.save()
+ if hasattr(user, "user_ptr"):
+ new.history_creator = user.user_ptr
+ new.history_modifier = user.user_ptr
+ new.save()
# m2m fields
m2m = [
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index cb5ca5644..d0adc766a 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -1515,12 +1515,15 @@ class FindQATest(FindInit, TestCase):
def setUp(self):
self.create_finds(data_base={"label": "Find 1"}, force=True)
self.create_finds(data_base={"label": "Find 2"}, force=True)
- self.username, self.password, self.user = create_superuser()
self.alt_username, self.alt_password, self.alt_user = create_user()
self.alt_user.user_permissions.add(
Permission.objects.get(codename="change_find")
)
+ def get_default_user(self):
+ self.username, self.password, self.user = create_superuser()
+ return self.user
+
def test_duplicate(self):
t1, __ = models.Treatment.objects.get_or_create(
label="Treatment 1", treatment_state=models.TreatmentState.objects.all()[0]
@@ -1560,6 +1563,9 @@ class FindQATest(FindInit, TestCase):
self.assertEqual(models.Find.objects.count(), nb_find + 1)
self.assertEqual(models.BaseFind.objects.count(), nb_bf + 1)
new = models.Find.objects.order_by("-pk").all()[0]
+ self.assertEqual(find.history_creator, self.user)
+ self.assertEqual(new.history_creator, self.alt_user)
+ self.assertEqual(new.base_finds.all()[0].history_creator, self.alt_user)
self.assertEqual(new.description, default_desc)
new_bf = models.BaseFind.objects.order_by("-pk").all()[0]
base_bf = find.get_first_base_find()
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index fa24b3dcb..ed183e4d1 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -811,9 +811,10 @@ def _post_save_geo(sender, **kwargs):
new_point = GEOSGeometry(
"POINT({} {})".format(instance.x, instance.y), srid=csrs.srid
)
- proj_point = instance.point_2d.transform(csrs.srid, clone=True)
- if new_point.distance(proj_point) < 0.01:
- instance.x, instance.y = None, None
+ if instance.point_2d:
+ proj_point = instance.point_2d.transform(csrs.srid, clone=True)
+ if new_point.distance(proj_point) < 0.01:
+ instance.x, instance.y = None, None
instance.point, instance.point_2d = None, None
instance.point_source = None
@@ -2042,6 +2043,12 @@ def duplicate_item(item, user=None, data=None):
for k in data:
setattr(new, k, data[k])
new.save()
+ if hasattr(user, "user_ptr"):
+ if hasattr(new, "history_creator"):
+ new.history_creator = user.user_ptr
+ if hasattr(new, "history_modifier"):
+ new.history_modifier = user.user_ptr
+ new.save()
# m2m fields
m2m = [