summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-12-11 17:46:46 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-12-11 17:46:46 +0100
commit52b513e0737f65e30b5e886f728a7fae16ace4c2 (patch)
tree5f60291fe22fc689f608ffc0ea8aeea9f7cd085f /archaeological_finds
parent38c111ec8b259158c152472ea96d070da2d39386 (diff)
downloadIshtar-52b513e0737f65e30b5e886f728a7fae16ace4c2.tar.bz2
Ishtar-52b513e0737f65e30b5e886f728a7fae16ace4c2.zip
Administrative act for treatment and treatment files
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/forms.py341
-rw-r--r--archaeological_finds/forms_treatments.py472
-rw-r--r--archaeological_finds/ishtar_menu.py95
-rw-r--r--archaeological_finds/urls.py56
-rw-r--r--archaeological_finds/views.py121
-rw-r--r--archaeological_finds/wizards.py60
6 files changed, 815 insertions, 330 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 541778d5c..78a415abf 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -21,7 +21,6 @@
Finds forms definitions
"""
-import datetime
import logging
from django import forms
@@ -32,21 +31,53 @@ from django.forms.formsets import formset_factory
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
-from ishtar_common.models import Person, valid_id, valid_ids, \
- get_current_profile, Organization
+from ishtar_common.models import valid_id, valid_ids, get_current_profile
from archaeological_operations.models import Period, ArchaeologicalSite, \
RelationType as OpeRelationType
from archaeological_context_records.models import DatingType, DatingQuality, \
ContextRecord
-from archaeological_warehouse.models import Warehouse, Container
import models
-from ishtar_common import widgets
-from archaeological_operations.widgets import OAWidget
from ishtar_common.forms import FormSet, FloatField, \
get_form_selection, reverse_lazy, TableSelect, get_now, FinalForm, \
ManageOldType
+
from ishtar_common.forms_common import get_town_field, SourceSelect
+from ishtar_common import widgets
+from archaeological_operations.widgets import OAWidget
+
+from archaeological_finds.forms_treatments import TreatmentSelect, \
+ TreatmentFormSelection, BaseTreatmentForm, ModifyTreatmentForm, \
+ AdministrativeActTreatmentForm, TreatmentFormFileChoice, \
+ TreatmentDeletionForm, TreatmentFileSelect, TreatmentFileFormSelection, \
+ TreatmentFileForm, ModifyTreatmentFileForm, TreatmentFileDeletionForm, \
+ AdministrativeActTreatmentFormSelection, \
+ AdministrativeActTreatmentModifForm, \
+ AdministrativeActTreatmentFileForm, \
+ AdministrativeActTreatmentFileFormSelection, \
+ AdministrativeActTreatmentFileModifForm
+
+__all__ = ['TreatmentSelect', 'TreatmentFormSelection', 'BaseTreatmentForm',
+ 'ModifyTreatmentForm', 'AdministrativeActTreatmentForm',
+ 'TreatmentFormFileChoice', 'TreatmentDeletionForm',
+ 'AdministrativeActTreatmentModifForm',
+ 'TreatmentFileSelect', 'TreatmentFileFormSelection',
+ 'TreatmentFileForm', 'ModifyTreatmentFileForm',
+ 'TreatmentFileDeletionForm', 'AdministrativeActTreatmentFileForm',
+ 'AdministrativeActTreatmentFileFormSelection',
+ 'AdministrativeActTreatmentFormSelection',
+ 'AdministrativeActTreatmentFileModifForm',
+ 'RecordFormSelection',
+ 'FindForm', 'DateForm', 'DatingFormSet', 'FindSelect',
+ 'FindFormSelection', 'MultipleFindFormSelection',
+ 'FindMultipleFormSelection', 'check_form', 'check_exist',
+ 'check_not_exist', 'check_value', 'check_type_field',
+ 'check_type_not_field', 'check_treatment', 'ResultFindForm',
+ 'ResultFindFormSet', 'FindDeletionForm',
+ 'UpstreamFindFormSelection', 'SourceFindFormSelection',
+ 'FindSourceSelect', 'FindSourceFormSelection',
+ 'NewFindBasketForm', 'SelectFindBasketForm', 'DeleteFindBasketForm',
+ 'FindBasketAddItemForm']
logger = logging.getLogger(__name__)
@@ -604,304 +635,6 @@ class FindBasketAddItemForm(forms.Form):
return basket
-class TreatmentSelect(TableSelect):
- label = forms.CharField(label=_(u"Label"))
- other_reference = forms.CharField(label=_(u"Other ref."))
- year = forms.IntegerField(label=_(u"Year"))
- index = forms.IntegerField(label=_(u"Index"))
- treatment_types = forms.ChoiceField(label=_(u"Treatment type"), choices=[])
- image = forms.NullBooleanField(label=_(u"Has an image?"))
-
- def __init__(self, *args, **kwargs):
- super(TreatmentSelect, self).__init__(*args, **kwargs)
- self.fields['treatment_types'].choices = \
- models.TreatmentType.get_types()
- self.fields['treatment_types'].help_text = \
- models.TreatmentType.get_help()
-
-
-class TreatmentFormSelection(forms.Form):
- form_label = _("Treatment search")
- associated_models = {'pk': models.Treatment}
- currents = {'pk': models.Treatment}
- pk = forms.IntegerField(
- label="", required=False,
- widget=widgets.JQueryJqGrid(
- reverse_lazy('get-treatment'),
- TreatmentSelect, models.Treatment),
- validators=[valid_id(models.Treatment)])
-
-
-class BaseTreatmentForm(ManageOldType, forms.Form):
- form_label = _(u"Base treatment")
- base_models = ['treatment_type']
- associated_models = {'treatment_type': models.TreatmentType,
- 'person': Person,
- 'location': Warehouse,
- 'organization': Organization,
- 'container': Container,
- }
- 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(1900),
- validators.MaxValueValidator(2100)])
- treatment_type = forms.MultipleChoiceField(
- label=_(u"Treatment type"), choices=[],
- widget=widgets.CheckboxSelectMultiple)
- target_is_basket = forms.NullBooleanField(label=_(u"Target"))
- person = forms.IntegerField(
- label=_(u"Responsible"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-person'), associated_model=Person,
- new=True),
- validators=[valid_id(Person)], required=False)
- organization = forms.IntegerField(
- label=_(u"Organization"),
- widget=widgets.JQueryAutoComplete(
- 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)])
- 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)
- comment = forms.CharField(label=_(u"Comment"),
- widget=forms.Textarea, required=False)
- description = forms.CharField(label=_(u"Description"),
- widget=forms.Textarea, required=False)
- goal = forms.CharField(label=_(u"Goal"),
- widget=forms.Textarea, required=False)
- start_date = forms.DateField(label=_(u"Start date"), required=False,
- widget=widgets.JQueryDate)
- end_date = forms.DateField(label=_(u"End date"), required=False,
- widget=widgets.JQueryDate)
- image = forms.ImageField(
- label=_(u"Image"), help_text=mark_safe(
- _(u"<p>Heavy images are resized to: %(width)dx%(height)d "
- u"(ratio is preserved).</p>") % {
- 'width': settings.IMAGE_MAX_SIZE[0],
- 'height': settings.IMAGE_MAX_SIZE[1]}),
- max_length=255, required=False, widget=widgets.ImageFileInput())
-
- def __init__(self, *args, **kwargs):
- user = kwargs.pop('user')
- super(BaseTreatmentForm, self).__init__(*args, **kwargs)
- q = Person.objects.filter(ishtaruser__pk=user.pk)
- if q.count():
- person = q.all()[0]
- 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['treatment_type'].choices = models.TreatmentType.get_types(
- initial=self.init_data.get('treatment_type'),
- dct={'upstream_is_many': False, 'downstream_is_many': False},
- empty_first=False
- )
- self.fields['treatment_type'].help_text = \
- models.TreatmentType.get_help(
- dct={'upstream_is_many': False, 'downstream_is_many': False})
- # TODO
- """
- self.fields['basket'].required = False
- self.fields['basket'].help_text = \
- _(u"Leave it blank if you want to select a single item")
- self.fields.keyOrder.pop(self.fields.keyOrder.index('basket'))
- self.fields.keyOrder.insert(self.fields.keyOrder.index('description'),
- 'basket')
- """
-
- def clean(self, *args, **kwargs):
- data = self.cleaned_data
- packaging = models.TreatmentType.get_cache('packaging')
- 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(
- _(u"The container field is attached to the treatment. If "
- u"no packaging treatment is done it is not relevant."))
- if not data.get('container', None) \
- and str(packaging.pk) in data.get('treatment_type', []):
- raise forms.ValidationError(
- _(u"If a packaging treatment is done, the container field "
- u"must be filled."))
- if not data.get('person', None) and not data.get('organization', None):
- raise forms.ValidationError(
- _(u"A responsible or an organization must be defined."))
- return data
- # TODO
- """
- for treatment_type in self.cleaned_data.get('treatment_type', []):
- try:
- treatment = models.TreatmentType.objects.get(
- pk=treatment_type, available=True)
- except models.TreatmentType.DoesNotExist:
- raise forms.ValidationError(_(u"This treatment type is not "
- u"available."))
- if treatment.upstream_is_many and \
- not self.cleaned_data.get('basket'):
- raise forms.ValidationError(_(u"This treatment needs a "
- u"basket."))
- """
-
-
-class ModifyTreatmentForm(BaseTreatmentForm):
- index = forms.IntegerField(_(u"Index"))
- id = forms.IntegerField(' ', widget=forms.HiddenInput, required=False)
-
- def clean(self, *args, **kwargs):
- super(ModifyTreatmentForm, self).clean(*args, **kwargs)
- cleaned_data = self.cleaned_data
- year = cleaned_data.get('year')
- pk = cleaned_data.get('id')
- index = cleaned_data.get('index')
- q = models.Treatment.objects\
- .filter(year=year, index=index).exclude(pk=pk)
- if index and q.count():
- raise forms.ValidationError(
- _(u"Another treatment with this index exists for {}."
- ).format(year))
- return cleaned_data
-
-
-class TreatmentFormFileChoice(forms.Form):
- form_label = _(u"Associated file")
- associated_models = {'file': models.TreatmentFile, }
- currents = {'file': models.TreatmentFile}
- file = forms.IntegerField(
- label=_(u"Treatment file"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-treatmentfile'),
- associated_model=models.TreatmentFile),
- validators=[valid_id(models.TreatmentFile)], required=False)
-
-
-class TreatmentDeletionForm(FinalForm):
- confirm_msg = _(
- u"Are you sure you want to delete this treatment? All modification "
- u"made to the associated finds since this treatment record will be "
- u"lost!")
- confirm_end_msg = _(u"Would you like to delete this treatment?")
-
-
-class TreatmentFileSelect(TableSelect):
- name = forms.CharField(label=_(u"Name"))
- internal_reference = forms.CharField(label=_(u"Internal ref."))
- year = forms.IntegerField(label=_(u"Year"))
- index = forms.IntegerField(label=_(u"Index"))
- type = forms.ChoiceField(label=_(u"Treatment file type"), choices=[])
-
- def __init__(self, *args, **kwargs):
- super(TreatmentFileSelect, self).__init__(*args, **kwargs)
- self.fields['type'].choices = models.TreatmentFileType.get_types()
- self.fields['type'].help_text = models.TreatmentFileType.get_help()
-
-
-class TreatmentFileFormSelection(forms.Form):
- form_label = _("Treatment file search")
- associated_models = {'pk': models.TreatmentFile}
- currents = {'pk': models.TreatmentFile}
- pk = forms.IntegerField(
- label="", required=False,
- widget=widgets.JQueryJqGrid(
- reverse_lazy('get-treatmentfile'),
- TreatmentFileSelect, models.TreatmentFile),
- validators=[valid_id(models.Treatment)])
-
-
-class TreatmentFileForm(ManageOldType, forms.Form):
- form_label = _(u"Treatment file")
- base_models = ['treatment_type_type']
- associated_models = {'type': models.TreatmentFileType,
- 'in_charge': Person}
- need_user_for_initialization = True
-
- name = forms.CharField(label=_(u"Name"),
- max_length=1000, required=False)
- internal_reference = forms.CharField(
- label=_(u"Internal ref."), max_length=60, required=False)
- year = forms.IntegerField(label=_("Year"),
- initial=lambda: datetime.datetime.now().year,
- validators=[validators.MinValueValidator(1900),
- validators.MaxValueValidator(2100)])
- type = forms.ChoiceField(
- label=_(u"Treatment file type"), choices=[])
- in_charge = forms.IntegerField(
- label=_(u"Responsible"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-person'), associated_model=Person,
- new=True),
- validators=[valid_id(Person)])
- external_id = forms.CharField(
- label=_(u"External ref."), max_length=200, required=False)
- comment = forms.CharField(label=_(u"Comment"),
- widget=forms.Textarea, required=False)
- creation_date = forms.DateField(label=_(u"Start date"), required=False,
- widget=widgets.JQueryDate,
- initial=lambda: datetime.datetime.now())
- reception_date = forms.DateField(label=_(u"Reception date"), required=False,
- widget=widgets.JQueryDate,
- initial=lambda: datetime.datetime.now())
- end_date = forms.DateField(label=_(u"Closing date"), required=False,
- widget=widgets.JQueryDate)
-
- def __init__(self, *args, **kwargs):
- user = kwargs.pop('user')
- super(TreatmentFileForm, self).__init__(*args, **kwargs)
- q = Person.objects.filter(ishtaruser__pk=user.pk)
- if q.count():
- person = q.all()[0]
- self.fields['in_charge'].initial = person.pk
- self.fields['type'].choices = models.TreatmentFileType.get_types(
- initial=[self.init_data.get('type')], empty_first=False
- )
- self.fields['type'].help_text = models.TreatmentFileType.get_help()
-
-
-class ModifyTreatmentFileForm(TreatmentFileForm):
- index = forms.IntegerField(_(u"Index"))
- id = forms.IntegerField(' ', widget=forms.HiddenInput, required=False)
-
- def clean(self, *args, **kwargs):
- super(ModifyTreatmentFileForm, self).clean(*args, **kwargs)
- cleaned_data = self.cleaned_data
- year = cleaned_data.get('year')
- pk = cleaned_data.get('id')
- index = cleaned_data.get('index')
- q = models.TreatmentFile.objects\
- .filter(year=year, index=index).exclude(pk=pk)
- if index and q.count():
- raise forms.ValidationError(
- _(u"Another treatment file with this index exists for {}."
- ).format(year))
- return cleaned_data
-
-
-class TreatmentFileDeletionForm(FinalForm):
- confirm_msg = _(u"Are you sure you want to delete this treatment file?")
- confirm_end_msg = _(u"Would you like to delete this treatment file?")
-
-
"""
####################################
# Source management for treatments #
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index e69de29bb..4f5bbac07 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -0,0 +1,472 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# See the file COPYING for details.
+
+import datetime
+import logging
+
+from django import forms
+from django.conf import settings
+from django.core import validators
+from django.utils.safestring import mark_safe
+from django.utils.translation import ugettext_lazy as _
+
+from ishtar_common.models import Person, valid_id, Organization
+from archaeological_operations.models import ActType, AdministrativeAct
+from archaeological_warehouse.models import Warehouse, Container
+import models
+
+from archaeological_operations.forms import AdministrativeActOpeForm, \
+ AdministrativeActOpeFormSelection, AdministrativeActModifForm
+
+from ishtar_common.forms import reverse_lazy, TableSelect, FinalForm, \
+ ManageOldType
+
+from ishtar_common import widgets
+
+logger = logging.getLogger(__name__)
+
+# Treatment
+
+
+class TreatmentSelect(TableSelect):
+ label = forms.CharField(label=_(u"Label"))
+ other_reference = forms.CharField(label=_(u"Other ref."))
+ year = forms.IntegerField(label=_(u"Year"))
+ index = forms.IntegerField(label=_(u"Index"))
+ treatment_types = forms.ChoiceField(label=_(u"Treatment type"), choices=[])
+ image = forms.NullBooleanField(label=_(u"Has an image?"))
+
+ def __init__(self, *args, **kwargs):
+ super(TreatmentSelect, self).__init__(*args, **kwargs)
+ self.fields['treatment_types'].choices = \
+ models.TreatmentType.get_types()
+ self.fields['treatment_types'].help_text = \
+ models.TreatmentType.get_help()
+
+
+class TreatmentFormSelection(forms.Form):
+ form_label = _("Treatment search")
+ associated_models = {'pk': models.Treatment}
+ currents = {'pk': models.Treatment}
+ pk = forms.IntegerField(
+ label="", required=False,
+ widget=widgets.JQueryJqGrid(
+ reverse_lazy('get-treatment'),
+ TreatmentSelect, models.Treatment),
+ validators=[valid_id(models.Treatment)])
+
+
+class BaseTreatmentForm(ManageOldType, forms.Form):
+ form_label = _(u"Base treatment")
+ base_models = ['treatment_type']
+ associated_models = {'treatment_type': models.TreatmentType,
+ 'person': Person,
+ 'location': Warehouse,
+ 'organization': Organization,
+ 'container': Container,
+ }
+ 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(1900),
+ validators.MaxValueValidator(2100)])
+ treatment_type = forms.MultipleChoiceField(
+ label=_(u"Treatment type"), choices=[],
+ widget=widgets.CheckboxSelectMultiple)
+ target_is_basket = forms.NullBooleanField(label=_(u"Target"))
+ person = forms.IntegerField(
+ label=_(u"Responsible"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-person'), associated_model=Person,
+ new=True),
+ validators=[valid_id(Person)], required=False)
+ organization = forms.IntegerField(
+ label=_(u"Organization"),
+ widget=widgets.JQueryAutoComplete(
+ 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)])
+ 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)
+ comment = forms.CharField(label=_(u"Comment"),
+ widget=forms.Textarea, required=False)
+ description = forms.CharField(label=_(u"Description"),
+ widget=forms.Textarea, required=False)
+ goal = forms.CharField(label=_(u"Goal"),
+ widget=forms.Textarea, required=False)
+ start_date = forms.DateField(label=_(u"Start date"), required=False,
+ widget=widgets.JQueryDate)
+ end_date = forms.DateField(label=_(u"End date"), required=False,
+ widget=widgets.JQueryDate)
+ image = forms.ImageField(
+ label=_(u"Image"), help_text=mark_safe(
+ _(u"<p>Heavy images are resized to: %(width)dx%(height)d "
+ u"(ratio is preserved).</p>") % {
+ 'width': settings.IMAGE_MAX_SIZE[0],
+ 'height': settings.IMAGE_MAX_SIZE[1]}),
+ max_length=255, required=False, widget=widgets.ImageFileInput())
+
+ def __init__(self, *args, **kwargs):
+ user = kwargs.pop('user')
+ super(BaseTreatmentForm, self).__init__(*args, **kwargs)
+ q = Person.objects.filter(ishtaruser__pk=user.pk)
+ if q.count():
+ person = q.all()[0]
+ 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['treatment_type'].choices = models.TreatmentType.get_types(
+ initial=self.init_data.get('treatment_type'),
+ dct={'upstream_is_many': False, 'downstream_is_many': False},
+ empty_first=False
+ )
+ self.fields['treatment_type'].help_text = \
+ models.TreatmentType.get_help(
+ dct={'upstream_is_many': False, 'downstream_is_many': False})
+ # TODO
+ """
+ self.fields['basket'].required = False
+ self.fields['basket'].help_text = \
+ _(u"Leave it blank if you want to select a single item")
+ self.fields.keyOrder.pop(self.fields.keyOrder.index('basket'))
+ self.fields.keyOrder.insert(self.fields.keyOrder.index('description'),
+ 'basket')
+ """
+
+ def clean(self, *args, **kwargs):
+ data = self.cleaned_data
+ packaging = models.TreatmentType.get_cache('packaging')
+ 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(
+ _(u"The container field is attached to the treatment. If "
+ u"no packaging treatment is done it is not relevant."))
+ if not data.get('container', None) \
+ and str(packaging.pk) in data.get('treatment_type', []):
+ raise forms.ValidationError(
+ _(u"If a packaging treatment is done, the container field "
+ u"must be filled."))
+ if not data.get('person', None) and not data.get('organization', None):
+ raise forms.ValidationError(
+ _(u"A responsible or an organization must be defined."))
+ return data
+ # TODO
+ """
+ for treatment_type in self.cleaned_data.get('treatment_type', []):
+ try:
+ treatment = models.TreatmentType.objects.get(
+ pk=treatment_type, available=True)
+ except models.TreatmentType.DoesNotExist:
+ raise forms.ValidationError(_(u"This treatment type is not "
+ u"available."))
+ if treatment.upstream_is_many and \
+ not self.cleaned_data.get('basket'):
+ raise forms.ValidationError(_(u"This treatment needs a "
+ u"basket."))
+ """
+
+
+class ModifyTreatmentForm(BaseTreatmentForm):
+ index = forms.IntegerField(_(u"Index"))
+ id = forms.IntegerField(' ', widget=forms.HiddenInput, required=False)
+
+ def clean(self, *args, **kwargs):
+ super(ModifyTreatmentForm, self).clean(*args, **kwargs)
+ cleaned_data = self.cleaned_data
+ year = cleaned_data.get('year')
+ pk = cleaned_data.get('id')
+ index = cleaned_data.get('index')
+ q = models.Treatment.objects \
+ .filter(year=year, index=index).exclude(pk=pk)
+ if index and q.count():
+ raise forms.ValidationError(
+ _(u"Another treatment with this index exists for {}."
+ ).format(year))
+ return cleaned_data
+
+
+class TreatmentFormFileChoice(forms.Form):
+ form_label = _(u"Associated file")
+ associated_models = {'file': models.TreatmentFile, }
+ currents = {'file': models.TreatmentFile}
+ file = forms.IntegerField(
+ label=_(u"Treatment file"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-treatmentfile'),
+ associated_model=models.TreatmentFile),
+ validators=[valid_id(models.TreatmentFile)], required=False)
+
+
+class TreatmentDeletionForm(FinalForm):
+ confirm_msg = _(
+ u"Are you sure you want to delete this treatment? All modification "
+ u"made to the associated finds since this treatment record will be "
+ u"lost!")
+ confirm_end_msg = _(u"Would you like to delete this treatment?")
+
+# administrative act treatment
+
+
+class AdministrativeActTreatmentSelect(TableSelect):
+ year = forms.IntegerField(label=_("Year"))
+ index = forms.IntegerField(label=_("Index"))
+ act_type = forms.ChoiceField(label=_("Act type"), choices=[])
+ indexed = forms.NullBooleanField(label=_(u"Indexed?"))
+ act_object = forms.CharField(label=_(u"Object"),
+ max_length=300)
+
+ signature_date_after = forms.DateField(
+ label=_(u"Signature date after"), widget=widgets.JQueryDate)
+ signature_date_before = forms.DateField(
+ label=_(u"Signature date before"), widget=widgets.JQueryDate)
+ treatment__name = forms.CharField(
+ label=_(u"Treatment name"), max_length=200)
+ treatment__year = forms.IntegerField(label=_(u"Treatment year"))
+ treatment__index = forms.IntegerField(label=_(u"Treatment index"))
+ treatment__internal_reference = forms.CharField(
+ max_length=200, label=_(u"Treatment internal reference"))
+ history_modifier = forms.IntegerField(
+ label=_(u"Modified by"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-person',
+ args=['0', 'user']),
+ associated_model=Person),
+ validators=[valid_id(Person)])
+
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActTreatmentSelect, self).__init__(*args, **kwargs)
+ self.fields['act_type'].choices = ActType.get_types(
+ dct={'intented_to': 'T'})
+ self.fields['act_type'].help_text = ActType.get_help(
+ dct={'intented_to': 'T'})
+
+
+class AdministrativeActTreatmentFormSelection(
+ AdministrativeActOpeFormSelection):
+ pk = forms.IntegerField(
+ label="", required=False,
+ widget=widgets.JQueryJqGrid(
+ reverse_lazy('get-administrativeacttreatment'),
+ AdministrativeActTreatmentSelect, AdministrativeAct),
+ validators=[valid_id(AdministrativeAct)])
+
+
+class AdministrativeActTreatmentForm(AdministrativeActOpeForm):
+ act_type = forms.ChoiceField(label=_(u"Act type"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActTreatmentForm, self).__init__(*args, **kwargs)
+ self.fields['act_type'].choices = ActType.get_types(
+ initial=self.init_data.get('act_type'),
+ dct={'intented_to': 'T'})
+ self.fields['act_type'].help_text = ActType.get_help(
+ dct={'intented_to': 'T'})
+
+
+class AdministrativeActTreatmentModifForm(
+ AdministrativeActModifForm, AdministrativeActTreatmentForm):
+ pk = forms.IntegerField(required=False, widget=forms.HiddenInput)
+ index = forms.IntegerField(label=_("Index"), required=False)
+
+# treatment files
+
+
+class TreatmentFileSelect(TableSelect):
+ name = forms.CharField(label=_(u"Name"))
+ internal_reference = forms.CharField(label=_(u"Internal ref."))
+ year = forms.IntegerField(label=_(u"Year"))
+ index = forms.IntegerField(label=_(u"Index"))
+ type = forms.ChoiceField(label=_(u"Treatment file type"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(TreatmentFileSelect, self).__init__(*args, **kwargs)
+ self.fields['type'].choices = models.TreatmentFileType.get_types()
+ self.fields['type'].help_text = models.TreatmentFileType.get_help()
+
+
+class TreatmentFileFormSelection(forms.Form):
+ form_label = _("Treatment file search")
+ associated_models = {'pk': models.TreatmentFile}
+ currents = {'pk': models.TreatmentFile}
+ pk = forms.IntegerField(
+ label="", required=False,
+ widget=widgets.JQueryJqGrid(
+ reverse_lazy('get-treatmentfile'),
+ TreatmentFileSelect, models.TreatmentFile),
+ validators=[valid_id(models.Treatment)])
+
+
+class TreatmentFileForm(ManageOldType, forms.Form):
+ form_label = _(u"Treatment file")
+ base_models = ['treatment_type_type']
+ associated_models = {'type': models.TreatmentFileType,
+ 'in_charge': Person}
+ need_user_for_initialization = True
+
+ name = forms.CharField(label=_(u"Name"),
+ max_length=1000, required=False)
+ internal_reference = forms.CharField(
+ label=_(u"Internal ref."), max_length=60, required=False)
+ year = forms.IntegerField(label=_("Year"),
+ initial=lambda: datetime.datetime.now().year,
+ validators=[validators.MinValueValidator(1900),
+ validators.MaxValueValidator(2100)])
+ type = forms.ChoiceField(
+ label=_(u"Treatment file type"), choices=[])
+ in_charge = forms.IntegerField(
+ label=_(u"Responsible"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-person'), associated_model=Person,
+ new=True),
+ validators=[valid_id(Person)])
+ external_id = forms.CharField(
+ label=_(u"External ref."), max_length=200, required=False)
+ comment = forms.CharField(label=_(u"Comment"),
+ widget=forms.Textarea, required=False)
+ creation_date = forms.DateField(label=_(u"Start date"), required=False,
+ widget=widgets.JQueryDate,
+ initial=lambda: datetime.datetime.now())
+ reception_date = forms.DateField(label=_(u"Reception date"), required=False,
+ widget=widgets.JQueryDate,
+ initial=lambda: datetime.datetime.now())
+ end_date = forms.DateField(label=_(u"Closing date"), required=False,
+ widget=widgets.JQueryDate)
+
+ def __init__(self, *args, **kwargs):
+ user = kwargs.pop('user')
+ super(TreatmentFileForm, self).__init__(*args, **kwargs)
+ q = Person.objects.filter(ishtaruser__pk=user.pk)
+ if q.count():
+ person = q.all()[0]
+ self.fields['in_charge'].initial = person.pk
+ self.fields['type'].choices = models.TreatmentFileType.get_types(
+ initial=[self.init_data.get('type')], empty_first=False
+ )
+ self.fields['type'].help_text = models.TreatmentFileType.get_help()
+
+
+class ModifyTreatmentFileForm(TreatmentFileForm):
+ index = forms.IntegerField(_(u"Index"))
+ id = forms.IntegerField(' ', widget=forms.HiddenInput, required=False)
+
+ def clean(self, *args, **kwargs):
+ super(ModifyTreatmentFileForm, self).clean(*args, **kwargs)
+ cleaned_data = self.cleaned_data
+ year = cleaned_data.get('year')
+ pk = cleaned_data.get('id')
+ index = cleaned_data.get('index')
+ q = models.TreatmentFile.objects \
+ .filter(year=year, index=index).exclude(pk=pk)
+ if index and q.count():
+ raise forms.ValidationError(
+ _(u"Another treatment file with this index exists for {}."
+ ).format(year))
+ return cleaned_data
+
+
+class TreatmentFileDeletionForm(FinalForm):
+ confirm_msg = _(u"Are you sure you want to delete this treatment file?")
+ confirm_end_msg = _(u"Would you like to delete this treatment file?")
+
+
+class AdministrativeActTreatmentFileSelect(TableSelect):
+ year = forms.IntegerField(label=_("Year"))
+ index = forms.IntegerField(label=_("Index"))
+ act_type = forms.ChoiceField(label=_("Act type"), choices=[])
+ indexed = forms.NullBooleanField(label=_(u"Indexed?"))
+ act_object = forms.CharField(label=_(u"Object"),
+ max_length=300)
+
+ signature_date_after = forms.DateField(
+ label=_(u"Signature date after"), widget=widgets.JQueryDate)
+ signature_date_before = forms.DateField(
+ label=_(u"Signature date before"), widget=widgets.JQueryDate)
+ treatment_file__name = forms.CharField(
+ label=_(u"Treatment file name"), max_length=200)
+ treatment_file__year = forms.IntegerField(label=_(u"Treatment file year"))
+ treatment_file__index = forms.IntegerField(label=_(u"Treatment file index"))
+ treatment_file__internal_reference = forms.CharField(
+ max_length=200, label=_(u"Treatment file internal reference"))
+ history_modifier = forms.IntegerField(
+ label=_(u"Modified by"),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-person',
+ args=['0', 'user']),
+ associated_model=Person),
+ validators=[valid_id(Person)])
+
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActTreatmentFileSelect, self).__init__(*args,
+ **kwargs)
+ self.fields['act_type'].choices = ActType.get_types(
+ dct={'intented_to': 'TF'})
+ self.fields['act_type'].help_text = ActType.get_help(
+ dct={'intented_to': 'TF'})
+
+
+class AdministrativeActTreatmentFileFormSelection(
+ AdministrativeActOpeFormSelection):
+ pk = forms.IntegerField(
+ label="", required=False,
+ widget=widgets.JQueryJqGrid(
+ reverse_lazy('get-administrativeacttreatmentfile'),
+ AdministrativeActTreatmentFileSelect, AdministrativeAct),
+ validators=[valid_id(AdministrativeAct)])
+
+
+class AdministrativeActTreatmentFileForm(AdministrativeActOpeForm):
+ act_type = forms.ChoiceField(label=_(u"Act type"), choices=[])
+
+ def __init__(self, *args, **kwargs):
+ super(AdministrativeActTreatmentFileForm, self).__init__(*args,
+ **kwargs)
+ self.fields['act_type'].choices = ActType.get_types(
+ initial=self.init_data.get('act_type'),
+ dct={'intented_to': 'TF'})
+ self.fields['act_type'].help_text = ActType.get_help(
+ dct={'intented_to': 'TF'})
+
+
+class AdministrativeActTreatmentFileModifForm(
+ AdministrativeActModifForm, AdministrativeActTreatmentFileForm):
+ pk = forms.IntegerField(required=False, widget=forms.HiddenInput)
+ index = forms.IntegerField(label=_("Index"), required=False)
diff --git a/archaeological_finds/ishtar_menu.py b/archaeological_finds/ishtar_menu.py
index 7824c94fe..39cc5d910 100644
--- a/archaeological_finds/ishtar_menu.py
+++ b/archaeological_finds/ishtar_menu.py
@@ -21,6 +21,7 @@ from django.utils.translation import ugettext_lazy as _
from ishtar_common.menu_base import SectionItem, MenuItem
+from archaeological_operations.models import AdministrativeAct
import models
# be carreful: each access_controls must be relevant with check_rights in urls
@@ -103,33 +104,60 @@ MENU_SECTIONS = [
])),
(60,
SectionItem(
- 'treatment_management', _(u"Treatment"),
+ 'treatmentfle_management', _(u"Treatment file"),
profile_restriction='warehouse',
childs=[
+ MenuItem('treatmentfle_search',
+ _(u"Search"),
+ model=models.TreatmentFile,
+ access_controls=['view_find',
+ 'view_own_find']),
+ MenuItem('treatmentfle_creation',
+ _(u"Creation"),
+ model=models.TreatmentFile,
+ access_controls=['change_find',
+ 'change_own_find']),
+ MenuItem('treatmentfle_modification',
+ _(u"Modification"),
+ model=models.TreatmentFile,
+ access_controls=['change_find',
+ 'change_own_find']),
+ MenuItem('treatmentfle_deletion',
+ _(u"Deletion"),
+ model=models.TreatmentFile,
+ access_controls=['change_find',
+ 'change_own_find']),
SectionItem(
- 'find_treatmentfiles', _(u"Treatment Files"),
+ 'admin_act_fletreatments', _(u"Administrative act"),
childs=[
- MenuItem('treatmentfle_search',
+ MenuItem('treatmentfle_admacttreatmentfle_search',
_(u"Search"),
- model=models.TreatmentFile,
- access_controls=['view_find',
- 'view_own_find']),
- MenuItem('treatmentfle_creation',
+ model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ MenuItem('treatmentfle_admacttreatmentfle',
_(u"Creation"),
- model=models.TreatmentFile,
- access_controls=['change_find',
- 'change_own_find']),
- MenuItem('treatmentfle_modification',
- _(u"Modification"),
- model=models.TreatmentFile,
- access_controls=['change_find',
- 'change_own_find']),
- MenuItem('treatmentfle_deletion',
+ model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ MenuItem('treatmentfle_admacttreatmentfle_modification',
+ _(u"Modification"), model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ MenuItem('treatmentfle_admacttreatmentfle_deletion',
_(u"Deletion"),
- model=models.TreatmentFile,
- access_controls=['change_find',
- 'change_own_find']),
- ]),
+ model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ MenuItem('treatmentfle_administrativeact_document',
+ _(u"Documents"),
+ model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ ]
+ )
+ ]
+ )),
+ (70,
+ SectionItem(
+ 'treatment_management', _(u"Treatment"),
+ profile_restriction='warehouse',
+ childs=[
SectionItem(
'find_treatments', _(u"Simple treatments"),
childs=[
@@ -154,6 +182,31 @@ MENU_SECTIONS = [
access_controls=['change_find',
'change_own_find']),
]),
- ]
+ SectionItem(
+ 'admin_act_treatments', _(u"Administrative act"),
+ childs=[
+ MenuItem('treatment_admacttreatment_search',
+ _(u"Search"),
+ model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ MenuItem('treatment_admacttreatment',
+ _(u"Creation"),
+ model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ MenuItem(
+ 'treatment_admacttreatment_modification',
+ _(u"Modification"), model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ MenuItem('treatment_admacttreatment_deletion',
+ _(u"Deletion"),
+ model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ MenuItem('treatment_admacttreatment_document',
+ _(u"Documents"),
+ model=AdministrativeAct,
+ access_controls=['change_administrativeact']),
+ ]
+ )
+ ]
)),
]
diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py
index c780b14fb..120fa1ed0 100644
--- a/archaeological_finds/urls.py
+++ b/archaeological_finds/urls.py
@@ -88,20 +88,65 @@ urlpatterns = patterns(
url(r'^find_basket_deletion/$',
check_rights(['change_find', 'change_own_find'])(
views.DeleteFindBasketView.as_view()), name='delete_findbasket'),
- url(r'treatment_creation/(?P<step>.+)?$',
+ url(r'^treatment_creation/(?P<step>.+)?$',
check_rights(['change_find', 'change_own_find'])(
views.treatment_creation_wizard), name='treatment_creation'),
- url(r'treatment_modification/(?P<step>.+)?$',
+ url(r'^treatment_modification/(?P<step>.+)?$',
check_rights(['change_find', 'change_own_find'])(
views.treatment_modification_wizard),
name='treatment_modification'),
- url(r'treatment_search/(?P<step>.+)?$',
+ url(r'^treatment_search/(?P<step>.+)?$',
check_rights(['view_find', 'view_own_find'])(
views.treatment_search_wizard), name='treatment_search'),
url(r'^treatment_deletion/(?P<step>.+)?$',
check_rights(['change_find', 'change_own_find'])(
views.treatment_deletion_wizard), name='treatment_deletion'),
- url(r'treatmentfle_search/(?P<step>.+)?$',
+
+ url(r'^treatment_admacttreatment_search/(?P<step>.+)?$',
+ check_rights(['change_administrativeact'])(
+ views.treatment_administrativeact_search_wizard),
+ name='treatment_admacttreatment_search'),
+ url(r'^treatment_admacttreatment/(?P<step>.+)?$',
+ check_rights(['change_administrativeact'])(
+ views.treatment_administrativeact_wizard),
+ name='treatment_admacttreatment'),
+ url(r'^treatment_admacttreatment_modification/(?P<step>.+)?$',
+ check_rights(['change_administrativeact'])(
+ views.treatment_administrativeact_modification_wizard),
+ name='treatment_admacttreatment_modification'),
+ url(r'^treatment_administrativeacttreatment_modify/(?P<pk>.+)/$',
+ views.treatment_administrativeacttreatment_modify,
+ name='treatment_administrativeacttreatment_modify'),
+ url(r'^treatment_admacttreatment_deletion/(?P<step>.+)?$',
+ check_rights(['change_administrativeact'])(
+ views.treatment_admacttreatment_deletion_wizard),
+ name='treatment_admacttreatment_deletion'),
+ url(r'^get-administrativeacttreatment/(?P<type>.+)?$',
+ views.get_administrativeacttreatment,
+ name='get-administrativeacttreatment'),
+
+ url(r'^treatmentfle_admacttreatmentfle_search/(?P<step>.+)?$',
+ check_rights(['change_administrativeact'])(
+ views.treatmentfile_admacttreatmentfile_search_wizard),
+ name='treatmentfle_admacttreatmentfle_search'),
+ url(r'^treatmentfle_admacttreatmentfle_modification/(?P<step>.+)?$',
+ check_rights(['change_administrativeact'])(
+ views.treatmentfile_admacttreatmentfile_modification_wizard),
+ name='treatmentfle_admacttreatmentfle_modification'),
+ url(r'^treatmentfle_admacttreatmentfle/(?P<step>.+)?$',
+ check_rights(['change_administrativeact'])(
+ views.treatmentfile_admacttreatmentfile_wizard),
+ name='treatmentfle_admacttreatmentfle'),
+ url(r'^treatmentfile_administrativeacttreatmentfile_modify/(?P<pk>.+)/$',
+ views.treatmentfile_administrativeacttreatmentfile_modify,
+ name='treatmentfile_administrativeacttreatmentfile_modify'),
+ url(r'^treatmentfle_admacttreatmentfle_deletion/(?P<step>.+)?$',
+ check_rights(['change_administrativeact'])(
+ views.treatmentfile_admacttreatmentfile_deletion_wizard),
+ name='treatmentfle_admacttreatmentfle_deletion'),
+
+
+ url(r'^treatmentfle_search/(?P<step>.+)?$',
check_rights(['change_find', 'change_own_find'])(
views.treatmentfile_search_wizard),
name='treatmentfile_search'),
@@ -117,6 +162,9 @@ urlpatterns = patterns(
check_rights(['change_find', 'change_own_find'])(
views.treatmentfile_deletion_wizard),
name='treatmentfile_deletion'),
+ url(r'get-administrativeacttreatmentfile/(?P<type>.+)?$',
+ views.get_administrativeacttreatmentfile,
+ name='get-administrativeacttreatmentfile'),
url(r'get-upstreamtreatment/(?P<type>.+)?$', views.get_upstreamtreatment,
name='get-upstreamtreatment'),
url(r'get-downstreamtreatment/(?P<type>.+)?$',
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index 1b08e9853..35c7d5976 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -28,16 +28,21 @@ from django.utils.translation import ugettext_lazy as _
from django.views.generic import TemplateView
from django.views.generic.edit import CreateView, FormView
+from ishtar_common.models import IshtarUser
+from archaeological_operations.models import AdministrativeAct
+
from ishtar_common.forms import FinalForm
from ishtar_common.forms_common import SourceForm, AuthorFormset, \
SourceDeletionForm
-from ishtar_common.models import IshtarUser
+from archaeological_operations.forms import FinalAdministrativeActDeleteForm
from archaeological_context_records.forms \
import RecordFormSelection as RecordFormSelectionTable
from ishtar_common.views import get_item, show_item, revert_item, \
get_autocomplete_generic, IshtarMixin, LoginRequiredMixin
+
from ishtar_common.wizards import SearchWizard
+from archaeological_operations.wizards import AdministrativeActDeletionWizard
from wizards import *
from forms import *
@@ -55,10 +60,20 @@ get_find_for_treatment = get_item(
show_treatment = show_item(models.Treatment, 'treatment')
get_treatment = get_item(models.Treatment, 'get_treatement', 'treatment')
+get_administrativeacttreatment = get_item(
+ AdministrativeAct, 'get_administrativeacttreatment',
+ 'administrativeacttreatment',
+ base_request={"treatment__pk__isnull": False})
+
show_treatmentfile = show_item(models.TreatmentFile, 'treatmentfile')
get_treatmentfile = get_item(models.TreatmentFile, 'get_treatementfile',
'treatmentfile')
+get_administrativeacttreatmentfile = get_item(
+ AdministrativeAct, 'get_administrativeacttreatmentfile',
+ 'administrativeacttreatmentfile',
+ base_request={"treatment_file__pk__isnull": False})
+
def autocomplete_treatmentfile(request):
if not request.user.has_perm('ishtar_common.view_treatment',
@@ -375,6 +390,59 @@ treatment_deletion_wizard = TreatmentDeletionWizard.as_view([
label=_(u"Treatment deletion"),
url_name='treatment_deletion',)
+treatment_administrativeact_search_wizard = \
+ SearchWizard.as_view([
+ ('selec-treatment_admacttreatment_search',
+ AdministrativeActTreatmentFormSelection)],
+ label=_(u"Treatment: search administrative act"),
+ url_name='treatment_admacttreatment_search',)
+
+treatment_administrativeact_wizard = \
+ TreatmentAdministrativeActWizard.as_view([
+ ('selec-treatment_admacttreatment', TreatmentFormSelection),
+ ('administrativeact-treatment_admacttreatment',
+ AdministrativeActTreatmentForm),
+ ('final-treatment_admacttreatment', FinalForm)],
+ label=_(u"Treatment: new administrative act"),
+ url_name='treatment_admacttreatment',)
+
+treatment_administrativeact_modification_wizard = \
+ TreatmentEditAdministrativeActWizard.as_view([
+ ('selec-treatment_admacttreatment_modification',
+ AdministrativeActTreatmentFormSelection),
+ ('administrativeact-treatment_admacttreatment_modification',
+ AdministrativeActTreatmentModifForm),
+ ('final-treatment_admacttreatment_modification', FinalForm)],
+ label=_(u"Treatment: administrative act modification"),
+ url_name='treatment_admacttreatment_modification',)
+
+treatment_admacttreatment_deletion_wizard = \
+ AdministrativeActDeletionWizard.as_view([
+ ('selec-treatment_admacttreatment_deletion',
+ AdministrativeActTreatmentFormSelection),
+ ('final-treatment_admacttreatment_deletion',
+ FinalAdministrativeActDeleteForm)],
+ label=_(u"Treatment: administrative act deletion"),
+ url_name='treatment_admacttreatment_deletion',)
+
+
+def treatment_administrativeacttreatment_modify(request, pk):
+ treatment_administrativeact_modification_wizard(request)
+ TreatmentEditAdministrativeActWizard.session_set_value(
+ request,
+ 'selec-treatment_admacttreatment_modification',
+ 'pk', pk, reset=True)
+ return redirect(
+ reverse(
+ 'treatment_admacttreatment_modification',
+ kwargs={
+ 'step':
+ 'administrativeact-treatment_admacttreatment_modification'
+ }))
+
+
+# treatment file
+
treatmentfile_search_wizard = SearchWizard.as_view([
('general-treatmentfile_search', TreatmentFileFormSelection)],
label=_(u"Treatment file search"),
@@ -404,6 +472,57 @@ treatmentfile_deletion_wizard = TreatmentFileDeletionWizard.as_view([
label=_(u"Treatment file deletion"),
url_name='treatmentfile_deletion',)
+treatmentfile_admacttreatmentfile_search_wizard = \
+ SearchWizard.as_view([
+ ('selec-treatmentfle_admacttreatmentfle_search',
+ AdministrativeActTreatmentFileFormSelection)],
+ label=_(u"Treatment file: search administrative act"),
+ url_name='treatmentfle_admacttreatmentfle_search',)
+
+
+treatmentfile_admacttreatmentfile_wizard = \
+ TreatmentFileAdministrativeActWizard.as_view([
+ ('selec-treatmentfle_admacttreatmentfle', TreatmentFileFormSelection),
+ ('admact-treatmentfle_admacttreatmentfle',
+ AdministrativeActTreatmentFileForm),
+ ('final-treatmentfle_admacttreatmentfle', FinalForm)],
+ label=_(u"Treatment file: new administrative act"),
+ url_name='treatmentfle_admacttreatmentfle',)
+
+treatmentfile_admacttreatmentfile_modification_wizard = \
+ TreatmentFileEditAdministrativeActWizard.as_view([
+ ('selec-treatmentfle_admacttreatmentfle_modification',
+ AdministrativeActTreatmentFileFormSelection),
+ ('admact-treatmentfle_admacttreatmentfle_modification',
+ AdministrativeActTreatmentFileModifForm),
+ ('final-treatmentfle_admacttreatmentfle_modification', FinalForm)],
+ label=_(u"Treatment file: administrative act modification"),
+ url_name='treatmentfle_admacttreatmentfle_modification',)
+
+treatmentfile_admacttreatmentfile_deletion_wizard = \
+ AdministrativeActDeletionWizard.as_view([
+ ('selec-treatmentfle_admacttreatmentfle_deletion',
+ AdministrativeActTreatmentFileFormSelection),
+ ('final-treatmentfle_admacttreatmentfle_deletion',
+ FinalAdministrativeActDeleteForm)],
+ label=_(u"Treatment file: administrative act deletion"),
+ url_name='treatmentfle_admacttreatmentfle_deletion',)
+
+
+def treatmentfile_administrativeacttreatmentfile_modify(request, pk):
+ treatmentfile_admacttreatmentfile_modification_wizard(request)
+ TreatmentFileEditAdministrativeActWizard.session_set_value(
+ request,
+ 'selec-treatmentfle_admacttreatmentfle_modification',
+ 'pk', pk, reset=True)
+ return redirect(
+ reverse(
+ 'treatmentfle_admacttreatmentfle_modification',
+ kwargs={
+ 'step':
+ 'admact-treatmentfle_admacttreatmentfle_modification'
+ }))
+
"""
treatment_source_creation_wizard = TreatmentSourceWizard.as_view([
('selec-treatment_source_creation', SourceTreatmentFormSelection),
diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py
index eb838eb66..f5f43f1e6 100644
--- a/archaeological_finds/wizards.py
+++ b/archaeological_finds/wizards.py
@@ -22,6 +22,9 @@ from django.utils.translation import ugettext_lazy as _
from ishtar_common.forms import reverse_lazy
from ishtar_common.wizards import Wizard, DeletionWizard, SourceWizard
+from archaeological_operations.wizards import OperationAdministrativeActWizard
+
+from archaeological_operations.models import AdministrativeAct
import models
@@ -129,6 +132,23 @@ class TreatmentDeletionWizard(DeletionWizard):
'goal', 'start_date', 'end_date', 'container']
+class TreatmentAdministrativeActWizard(OperationAdministrativeActWizard):
+ model = models.Treatment
+ current_obj_slug = 'administrativeacttreatment'
+ ref_object_key = 'treatment'
+
+ def get_reminder(self):
+ return
+
+
+class TreatmentEditAdministrativeActWizard(TreatmentAdministrativeActWizard):
+ model = AdministrativeAct
+ edit = True
+
+ def get_associated_item(self, dct):
+ return self.get_current_object().treatment
+
+
class TreatmentFileWizard(Wizard):
model = models.TreatmentFile
wizard_done_window = reverse_lazy('show-treatmentfile')
@@ -145,6 +165,46 @@ class TreatmentFileDeletionWizard(DeletionWizard):
'creation_date', 'end_date', 'comment']
+class TreatmentFileAdministrativeActWizard(
+ OperationAdministrativeActWizard):
+ model = models.TreatmentFile
+ current_obj_slug = 'administrativeacttreatmentfile'
+ ref_object_key = 'treatment_file'
+
+ def get_reminder(self):
+ form_key = 'selec-' + self.url_name
+ if self.url_name.endswith('_administrativeactop'):
+ # modification and deletion are suffixed with '_modification'
+ # and '_deletion' so it is creation
+ pk = self.session_get_value(form_key, "pk")
+ try:
+ return (
+ (_(u"Treatment file"),
+ unicode(models.Operation.objects.get(pk=pk))),
+ )
+ except models.TreatmentFile.DoesNotExist:
+ return
+ else:
+ admin_id = self.session_get_value(form_key, "pk")
+ try:
+ admin = AdministrativeAct.objects.get(pk=admin_id)
+ if not admin.operation:
+ return
+ return ((_(u"Operation"), unicode(admin.operation)),)
+ except AdministrativeAct.DoesNotExist:
+ return
+ return
+
+
+class TreatmentFileEditAdministrativeActWizard(
+ TreatmentFileAdministrativeActWizard):
+ model = AdministrativeAct
+ edit = True
+
+ def get_associated_item(self, dct):
+ return self.get_current_object().treatment_file
+
+
class FindSourceWizard(SourceWizard):
wizard_done_window = reverse_lazy('show-findsource')
model = models.FindSource