diff options
-rw-r--r-- | archaeological_finds/forms_treatments.py | 58 | ||||
-rw-r--r-- | archaeological_finds/ishtar_menu.py | 46 | ||||
-rw-r--r-- | archaeological_finds/migrations/0039_auto_20181113_1600.py | 37 | ||||
-rw-r--r-- | archaeological_finds/models_treatments.py | 4 | ||||
-rw-r--r-- | archaeological_finds/templates/ishtar/sheet_treatment.html | 2 | ||||
-rw-r--r-- | archaeological_finds/views.py | 11 | ||||
-rw-r--r-- | archaeological_finds/wizards.py | 23 | ||||
-rw-r--r-- | archaeological_warehouse/forms.py | 5 | ||||
-rw-r--r-- | archaeological_warehouse/wizards.py | 9 |
9 files changed, 136 insertions, 59 deletions
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index 7ada0f4bc..248b1ef7d 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -94,20 +94,21 @@ class BaseTreatmentForm(CustomForm, ManageOldType): file_upload = True need_user_for_initialization = True - label = forms.CharField(label=_(u"Label"), - max_length=200, required=False) - other_reference = forms.CharField( - label=_(u"Other ref."), max_length=200, required=False) - year = forms.IntegerField(label=_("Year"), - initial=lambda: datetime.datetime.now().year, - validators=[validators.MinValueValidator(1000), - validators.MaxValueValidator(2100)]) - treatment_type = forms.MultipleChoiceField( + treatment_type = widgets.Select2MultipleField( label=_(u"Treatment type"), choices=[], widget=widgets.CheckboxSelectMultiple) treatment_state = forms.ChoiceField(label=_(u"State"), choices=[], required=False) - target_is_basket = forms.NullBooleanField(label=_(u"Target")) + year = forms.IntegerField(label=_("Year"), + initial=lambda: datetime.datetime.now().year, + validators=[validators.MinValueValidator(1000), + validators.MaxValueValidator(2100)]) + location = forms.IntegerField( + label=_(u"Location"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-warehouse'), associated_model=Warehouse, + new=True), + validators=[valid_id(Warehouse)]) person = forms.IntegerField( label=_(u"Responsible"), widget=widgets.JQueryAutoComplete( @@ -120,30 +121,29 @@ class BaseTreatmentForm(CustomForm, ManageOldType): reverse_lazy('autocomplete-organization'), associated_model=Organization, new=True), validators=[valid_id(Organization)], required=False) - location = forms.IntegerField( - label=_(u"Location"), - widget=widgets.JQueryAutoComplete( - reverse_lazy('autocomplete-warehouse'), associated_model=Warehouse, - new=True), - validators=[valid_id(Warehouse)]) + label = forms.CharField(label=_(u"Label"), + max_length=200, required=False) + other_reference = forms.CharField( + label=_(u"Other ref."), max_length=200, required=False) + # target_is_basket = forms.NullBooleanField(label=_(u"Target")) + # external_id = forms.CharField( + # label=_(u"External ref."), max_length=200, required=False) + start_date = forms.DateField(label=_(u"Start date"), required=False, + widget=DatePicker, initial=datetime.date.today) + end_date = forms.DateField(label=_(u"Closing date"), required=False, + widget=DatePicker) container = forms.IntegerField( label=_(u"Container (relevant for packaging)"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-container'), associated_model=Container, new=True), validators=[valid_id(Container)], required=False) - external_id = forms.CharField( - label=_(u"External ref."), max_length=200, required=False) goal = forms.CharField(label=_(u"Goal"), widget=forms.Textarea, required=False) description = forms.CharField(label=_(u"Description"), widget=forms.Textarea, required=False) comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, required=False) - start_date = forms.DateField(label=_(u"Start date"), required=False, - widget=DatePicker) - end_date = forms.DateField(label=_(u"Closing date"), required=False, - widget=DatePicker) estimated_cost = forms.FloatField(label=_(u"Estimated cost ({currency})"), required=False) quoted_cost = forms.FloatField(label=_(u"Quoted cost ({currency})"), @@ -155,9 +155,10 @@ class BaseTreatmentForm(CustomForm, ManageOldType): TYPES = [ FieldType('treatment_state', models.TreatmentState), - FieldType('treatment_type', models.TreatmentType, is_multiple=True, - extra_args={'dct': {'upstream_is_many': False, - 'downstream_is_many': False}}) + FieldType( + 'treatment_type', models.TreatmentType, is_multiple=True, + extra_args={'dct': {'upstream_is_many': False, + 'downstream_is_many': False}}) ] def __init__(self, *args, **kwargs): @@ -176,8 +177,8 @@ class BaseTreatmentForm(CustomForm, ManageOldType): self.fields['person'].initial = person.pk if person.attached_to: self.fields['organization'].initial = person.attached_to.pk - self.fields['target_is_basket'].widget.choices = \ - ((False, _(u"Single find")), (True, _(u"Basket"))) + # self.fields['target_is_basket'].widget.choices = \ + # ((False, _(u"Single find")), (True, _(u"Basket"))) # TODO """ self.fields['basket'].required = False @@ -198,6 +199,7 @@ class BaseTreatmentForm(CustomForm, ManageOldType): if not packaging: logger.warning("No 'packaging' treatment type defined") return + if data.get('container', None) \ and str(packaging.pk) not in data.get('treatment_type', []): raise forms.ValidationError( @@ -240,7 +242,7 @@ class TreatmentModifyForm(BaseTreatmentForm): fields[key] = value if key == 'year': fields['index'] = idx - fields.pop('target_is_basket') + # fields.pop('target_is_basket') self.fields = fields def clean(self, *args, **kwargs): diff --git a/archaeological_finds/ishtar_menu.py b/archaeological_finds/ishtar_menu.py index afd624b74..19d300fbc 100644 --- a/archaeological_finds/ishtar_menu.py +++ b/archaeological_finds/ishtar_menu.py @@ -148,31 +148,27 @@ MENU_SECTIONS = [ profile_restriction='warehouse', css='menu-warehouse', childs=[ - SectionItem( - 'find_treatments', _(u"Simple treatments"), - childs=[ - MenuItem('treatment_search', - _(u"Search"), - model=models.Treatment, - access_controls=['view_treatment', - 'view_own_treatment']), - MenuItem('treatment_creation', - _(u"Creation"), - model=models.Treatment, - access_controls=['change_treatment', - 'change_own_treatment']), - MenuItem('treatment_modification', - _(u"Modification"), - model=models.Treatment, - access_controls=['change_treatment', - 'change_own_treatment']), - MenuItem('treatment_deletion', - _(u"Deletion"), - model=models.Treatment, - access_controls=['change_treatment', - 'change_own_treatment']), - ]), - SectionItem( + MenuItem('treatment_search', + _(u"Search"), + model=models.Treatment, + access_controls=['view_treatment', + 'view_own_treatment']), + MenuItem('treatment_creation', + _(u"Simple treatment - creation"), + model=models.Treatment, + access_controls=['change_treatment', + 'change_own_treatment']), + MenuItem('treatment_modification', + _(u"Modification"), + model=models.Treatment, + access_controls=['change_treatment', + 'change_own_treatment']), + MenuItem('treatment_deletion', + _(u"Deletion"), + model=models.Treatment, + access_controls=['change_treatment', + 'change_own_treatment']), + SectionItem( 'admin_act_treatments', _(u"Administrative act"), childs=[ MenuItem('treatment_admacttreatment_search', diff --git a/archaeological_finds/migrations/0039_auto_20181113_1600.py b/archaeological_finds/migrations/0039_auto_20181113_1600.py new file mode 100644 index 000000000..08877d66b --- /dev/null +++ b/archaeological_finds/migrations/0039_auto_20181113_1600.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-11-13 16:00 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import virtualtime + + +class Migration(migrations.Migration): + + dependencies = [ + ('archaeological_finds', '0038_auto_20181112_1625'), + ] + + operations = [ + migrations.AddField( + model_name='historicaltreatment', + name='creation_date', + field=models.DateTimeField(default=virtualtime.virtual_datetime.now), + ), + migrations.AddField( + model_name='historicaltreatment', + name='find', + field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_finds.Find'), + ), + migrations.AddField( + model_name='treatment', + name='creation_date', + field=models.DateTimeField(default=virtualtime.virtual_datetime.now), + ), + migrations.AddField( + model_name='treatment', + name='find', + field=models.ForeignKey(blank=True, help_text='Related find for non-destructive treatment', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='treatments', to='archaeological_finds.Find', verbose_name='Find'), + ), + ] diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index 6a57a77f5..0bf3cad38 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -147,6 +147,10 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem, goal = models.TextField(_(u"Goal"), blank=True, null=True) start_date = models.DateField(_(u"Start date"), blank=True, null=True) end_date = models.DateField(_(u"Closing date"), blank=True, null=True) + creation_date = models.DateTimeField(default=datetime.datetime.now) + find = models.ForeignKey( + "Find", verbose_name=_(u"Find"), related_name='treatments', blank=True, + null=True, help_text=_(u"Related find for non-destructive treatment")) container = models.ForeignKey(Container, verbose_name=_(u"Container"), blank=True, null=True) estimated_cost = models.FloatField(_(u"Estimated cost"), diff --git a/archaeological_finds/templates/ishtar/sheet_treatment.html b/archaeological_finds/templates/ishtar/sheet_treatment.html index 1a3bb931f..e9c9c0758 100644 --- a/archaeological_finds/templates/ishtar/sheet_treatment.html +++ b/archaeological_finds/templates/ishtar/sheet_treatment.html @@ -1,7 +1,7 @@ {% extends "ishtar/sheet.html" %} {% load i18n window_field from_dict link_to_window window_tables window_ope_tables window_header humanize %} -{% block head_title %}<strong>{% trans "Treatment" %}</strong> - {{ item.label|default:"" }}{% endblock %} +{% block head_title %}<strong>{% trans "Treatment" %}</strong> - {{ item|default:"" }}{% endblock %} {% block toolbar %} {% window_nav item window_id 'show-treatment' 'treatment_modify' 'show-historized-treatment' 'revert-treatment' previous next 1 %} diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index c340639c5..c4dbe0d3d 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -405,10 +405,10 @@ get_downstreamtreatment = get_item( 'downtreatment') treatment_wizard_steps = [ + ('selecfind-treatment_creation', UpstreamFindFormSelection), ('file-treatment_creation', TreatmentFormFileChoice), ('basetreatment-treatment_creation', BaseTreatmentForm), - ('selecfind-treatment_creation', UpstreamFindFormSelection), - ('selecbasket-treatment_creation', SelectFindBasketForm), + # ('selecbasket-treatment_creation', SelectFindBasketForm), # ('resultfind-treatment_creation', ResultFindForm), # ('resultfinds-treatment_creation', ResultFindFormSet), ('final-treatment_creation', FinalForm) @@ -420,8 +420,7 @@ treatment_search_wizard = TreatmentSearch.as_view([ label=_(u"Treatment search"), url_name='treatment_search',) -treatment_creation_wizard = TreatmentWizard.as_view( - treatment_wizard_steps, +""" condition_dict={ 'selecfind-treatment_creation': check_value('basetreatment-treatment_creation', @@ -438,6 +437,10 @@ treatment_creation_wizard = TreatmentWizard.as_view( # 'treatment_type', models.TreatmentType, # 'upstream_is_many') }, +""" + +treatment_creation_wizard = TreatmentWizard.as_view( + treatment_wizard_steps, label=_(u"New treatment"), url_name='treatment_creation',) diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py index 0e0fe80e1..e90fa745c 100644 --- a/archaeological_finds/wizards.py +++ b/archaeological_finds/wizards.py @@ -119,6 +119,29 @@ class TreatmentWizard(Wizard): kwargs['user'] = self.request.user return kwargs + def get_current_find(self): + step = self.steps.current + if not step: + return + find_form_key = 'selecfind-treatment_creation' + find_id = self.session_get_value(find_form_key, "resulting_pk") + try: + return models.Find.objects.get(pk=int(find_id)) + except(TypeError, ValueError, ObjectDoesNotExist): + pass + + def get_form_initial(self, step, data=None): + initial = super(TreatmentWizard, self).get_form_initial(step) + if step != 'basetreatment-treatment_creation': + return initial + find = self.get_current_find() + if not find or not find.container: + return initial + if not initial: + initial = {} + initial['location'] = find.container.location.pk + return initial + def get_extra_model(self, dct, form_list): """ Get items concerned by the treatment diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 954c01918..2dc963ca0 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -18,6 +18,7 @@ # See the file COPYING for details. from collections import OrderedDict +import datetime from django import forms from django.conf import settings @@ -294,7 +295,9 @@ class BasePackagingForm(SelectFindBasketForm): associated_model=Person, new=True), validators=[valid_id(Person)]) start_date = forms.DateField( - label=_(u"Date"), required=False, widget=DatePicker) + label=_(u"Date"), required=False, widget=DatePicker, + initial=datetime.date.today + ) class FindPackagingFormSelection(FindMultipleFormSelection): diff --git a/archaeological_warehouse/wizards.py b/archaeological_warehouse/wizards.py index 41c5c5945..8ee2c2972 100644 --- a/archaeological_warehouse/wizards.py +++ b/archaeological_warehouse/wizards.py @@ -38,6 +38,15 @@ class ContainerSearch(SearchWizard): class PackagingWizard(TreatmentWizard): basket_step = 'base-packaging' + def get_form_initial(self, step, data=None): + initial = super(PackagingWizard, self).get_form_initial(step) + user = self.request.user + if step != 'base-packaging' or not getattr(user, 'ishtaruser', None) \ + or not user.ishtaruser.person: + return initial + initial['person'] = user.ishtaruser.person.pk + return initial + def save_model(self, dct, m2m, whole_associated_models, form_list, return_object): dct = self.get_extra_model(dct, form_list) |