summaryrefslogtreecommitdiff
path: root/archaeological_finds/forms_treatments.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-08-29 17:22:48 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-05 16:09:19 +0200
commit1720a9a24b4d53cd4d5981f1b847bd3642fa6fae (patch)
treef3fa122ebc9f98091a9511abff79088de71c299d /archaeological_finds/forms_treatments.py
parentf38be838170e93c60c7f7cd1f1d0f7c0fd0cf2fa (diff)
downloadIshtar-1720a9a24b4d53cd4d5981f1b847bd3642fa6fae.tar.bz2
Ishtar-1720a9a24b4d53cd4d5981f1b847bd3642fa6fae.zip
✨ manage find localization history
Diffstat (limited to 'archaeological_finds/forms_treatments.py')
-rw-r--r--archaeological_finds/forms_treatments.py71
1 files changed, 36 insertions, 35 deletions
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index f7d260f42..50469828b 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -426,7 +426,7 @@ class QAFindTreatmentForm(IshtarForm):
label=_("Year"), initial=lambda: datetime.datetime.now().year,
validators=[validators.MinValueValidator(1000),
validators.MaxValueValidator(2100)], required=False)
- start_date = DateField(label=_("Precise date"), required=False)
+ start_date = DateField(label=_("Precise date"), required=False, initial=lambda: datetime.datetime.today())
person = forms.IntegerField(
label=_("Responsible"),
widget=widgets.JQueryAutoComplete(
@@ -451,7 +451,9 @@ class QAFindTreatmentForm(IshtarForm):
tt_change_ref_loca = list(
models.TreatmentType.objects.filter(
- available=True, change_reference_location=True).all())
+ available=True, change_reference_location=True,
+ change_current_location=False
+ ).all())
self.treatment_type_ref_choices = "".join(
"<option value='{}'>{}</option>".format(tt.pk, str(tt))
@@ -460,26 +462,34 @@ class QAFindTreatmentForm(IshtarForm):
tt_change_current_loca = list(
models.TreatmentType.objects.filter(
- available=True, change_current_location=True).all())
+ available=True, change_current_location=True,
+ change_reference_location=False
+ ).all())
self.treatment_type_current_choices = "".join(
"<option value='{}'>{}</option>".format(tt.pk, str(tt))
for tt in tt_change_current_loca
)
+ tt_change_both_loca = list(
+ models.TreatmentType.objects.filter(
+ available=True, change_current_location=True,
+ change_reference_location=True
+ ).all())
+
self.treatment_type_all_choices = "".join(
"<option value='{}'>{}</option>".format(tt.pk, str(tt))
- for tt in set(tt_change_current_loca + tt_change_ref_loca)
+ for tt in tt_change_both_loca
)
- super(QAFindTreatmentForm, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
if not self.user:
return
# treatment type is dynamic put all for check
self.fields['treatment_type'].choices = [
(tt.pk, str(tt)) for tt in set(
- tt_change_ref_loca + tt_change_current_loca)
+ tt_change_ref_loca + tt_change_current_loca + tt_change_both_loca)
]
q = Person.objects.filter(ishtaruser__pk=self.user.pk)
@@ -505,14 +515,16 @@ class QAFindTreatmentForm(IshtarForm):
def save(self, items, user):
container = Container.objects.get(pk=self.cleaned_data['container'])
container_to_change = self.cleaned_data.get('container_to_change', '')
+ container_attrs = []
+ if container_to_change in ('reference', 'current-and-reference'):
+ container_attrs.append('container_ref')
+ if container_to_change in ('current', 'current-and-reference'):
+ container_attrs.append('container')
+
if self.cleaned_data['create_treatment']:
treat_type = models.TreatmentType.objects.get(
pk=self.cleaned_data['treatment_type'])
- treat_state, __ = models.TreatmentState.objects.get_or_create(
- txt_idx='completed',
- defaults={
- 'label': _("Completed"), 'executed': True,
- 'available': True})
+ treat_state = models.TreatmentState.get_completed_state()
t = models.Treatment.objects.create(
container=container,
year=self.cleaned_data['year'],
@@ -524,30 +536,19 @@ class QAFindTreatmentForm(IshtarForm):
treatment_state=treat_state
)
t.treatment_types.add(treat_type)
- new_items = t.save(items=items, return_new=True)
- if new_items:
- items = new_items
- container_attrs = []
- if container_to_change in ('reference', 'current-and-reference'):
- container_attrs.append('container_ref')
- if container_to_change in ('current', 'current-and-reference'):
- container_attrs.append('container')
- #collection = None
- #if self.cleaned_data.get("collection"):
- # collection = container.location_id
- for find in items:
- changed = False
- #if collection and find.collection_id != collection:
- # find.collection_id = collection
- # changed = True
- for container_attr in container_attrs:
- if getattr(find, container_attr) == container:
- continue
- setattr(find, container_attr, container)
- changed = True
- if changed:
- find.history_modifier = user
- find.save()
+ t.save(items=items)
+ t.move_finds_to_new_container(container_attrs=container_attrs)
+ else:
+ for find in items:
+ changed = False
+ for container_attr in container_attrs:
+ if getattr(find, container_attr) == container:
+ continue
+ setattr(find, container_attr, container)
+ changed = True
+ if changed:
+ find.history_modifier = user
+ find.save()
# administrative act treatment