diff options
Diffstat (limited to 'archaeological_finds/forms_treatments.py')
-rw-r--r-- | archaeological_finds/forms_treatments.py | 71 |
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 |