summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_finds/admin.py7
-rw-r--r--archaeological_finds/forms_treatments.py2
-rw-r--r--archaeological_finds/migrations/0046_treatmentfiletype_treatment_type.py21
-rw-r--r--archaeological_finds/models_treatments.py20
-rw-r--r--archaeological_finds/urls.py4
-rw-r--r--archaeological_finds/views.py44
6 files changed, 93 insertions, 5 deletions
diff --git a/archaeological_finds/admin.py b/archaeological_finds/admin.py
index 033d5bb96..8903ca5d7 100644
--- a/archaeological_finds/admin.py
+++ b/archaeological_finds/admin.py
@@ -180,10 +180,15 @@ class ConservatoryStateAdmin(GeneralTypeAdmin):
list_display = GeneralTypeAdmin.list_display + ['order']
+@admin.register(models.TreatmentFileType, site=admin_site)
+class TreatmentFileType(GeneralTypeAdmin):
+ list_display = GeneralTypeAdmin.list_display + ["treatment_type"]
+
+
general_models = [
models.RemarkabilityType,
models.IntegrityType,
- models.TreatmentFileType, models.TreatmentState,
+ models.TreatmentState,
models.BatchType, models.AlterationCauseType, models.AlterationType,
models.TreatmentEmergencyType, models.ObjectTypeQualityType,
models.MaterialTypeQualityType
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index a0ac1a7c6..5f3e49887 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -131,7 +131,7 @@ class BaseTreatmentForm(CustomForm, ManageOldType):
end_date = forms.DateField(label=_(u"Closing date"), required=False,
widget=DatePicker)
container = forms.IntegerField(
- label=_(u"Container (relevant for packaging and loan)"),
+ label=_(u"Destination container (relevant for packaging and loan)"),
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-container'),
associated_model=Container, new=True),
diff --git a/archaeological_finds/migrations/0046_treatmentfiletype_treatment_type.py b/archaeological_finds/migrations/0046_treatmentfiletype_treatment_type.py
new file mode 100644
index 000000000..867cd4545
--- /dev/null
+++ b/archaeological_finds/migrations/0046_treatmentfiletype_treatment_type.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-12-02 18:31
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_finds', '0045_migrate_current_container_to_ref_container'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='treatmentfiletype',
+ name='treatment_type',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='archaeological_finds.TreatmentType'),
+ ),
+ ]
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index 1083b479b..15ef64040 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -21,6 +21,7 @@ import datetime
from django.conf import settings
from django.contrib.gis.db import models
+from django.core.urlresolvers import reverse
from django.db.models import Max, Q
from django.db.models.signals import post_save, post_delete, pre_delete
from django.template.defaultfilters import slugify
@@ -699,6 +700,8 @@ class FindTreatments(AbsFindTreatments):
class TreatmentFileType(GeneralType):
+ treatment_type = models.ForeignKey(TreatmentType, blank=True, null=True)
+
class Meta:
verbose_name = _(u"Treatment request type")
verbose_name_plural = _(u"Treatment request types")
@@ -839,6 +842,23 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem,
for attr in ('year', 'index', 'internal_reference',
'name') if getattr(self, attr)])
+ def get_extra_actions(self, request):
+ if not self.associated_basket:
+ return []
+ if self.type.treatment_type and self.treatments.filter(
+ treatment_types__pk=self.type.treatment_type.pk).count():
+ # a treatment of this type already exists
+ return []
+ actions = []
+ can_edit_find = self.can_do(request, 'change_find')
+ if can_edit_find:
+ actions += [
+ (reverse('treatmentfile-add-treatment', args=[self.pk]),
+ _(u"Add associated treatment"), "fa fa-exchange", "", "",
+ False),
+ ]
+ return actions
+
@classmethod
def get_owns(cls, user, menu_filtr=None, limit=None, values=None,
get_short_menu_class=None):
diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py
index cf3522d43..7e27221a0 100644
--- a/archaeological_finds/urls.py
+++ b/archaeological_finds/urls.py
@@ -97,6 +97,10 @@ urlpatterns = [
check_rights(['change_find', 'change_own_find'])(
views.find_treatment_add),
name='find-add-treatment'),
+ url(r'^treatmentfile-add-treatment/(?P<pk>[0-9-]+)/$',
+ check_rights(['change_find', 'change_own_find'])(
+ views.treatmentfile_treatment_add),
+ name='treatmentfile-add-treatment'),
url(r'^find-qa-bulk-update/(?P<pks>[0-9-]+)?/$',
check_rights(['change_find', 'change_own_find'])(
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index a04d7fe2f..a0964fa47 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -529,13 +529,37 @@ def treatment_modify(request, pk):
kwargs={'step': 'basetreatment-treatment_modification'}))
-def treatment_add(request, pks):
+def treatment_add(request, pks, treatment_file=None):
treatment_creation_wizard(request)
wizards.TreatmentWizard.session_set_value(
request, 'selecfind-treatment_creation',
'resulting_pk', pks, reset=True)
- wizards.TreatmentWizard.session_set_value(
- request, 'file-treatment_creation', 'file', '')
+ if treatment_file:
+ wizards.TreatmentWizard.session_set_value(
+ request, 'file-treatment_creation', 'file', treatment_file.pk)
+ else:
+ wizards.TreatmentWizard.session_set_value(
+ request, 'file-treatment_creation', 'file', '')
+ if treatment_file:
+ in_charge = treatment_file.in_charge
+ if not in_charge:
+ in_charge = request.user.ishtaruser.person
+ dct = {
+ "treatment_type": treatment_file.type.treatment_type.pk
+ if treatment_file.type else "",
+ "year": treatment_file.year,
+ "person": in_charge.pk,
+ }
+ locas = list(
+ set([str(f.container.location.pk)
+ for f in treatment_file.associated_basket.items.all()
+ if f.container and f.container.location])
+ )
+ if len(locas) == 1: # one and only one location for all finds
+ dct["location"] = locas[0]
+ for k in dct:
+ wizards.TreatmentWizard.session_set_value(
+ request, 'basetreatment-treatment_creation', k, dct[k])
return redirect(reverse(
'treatment_creation',
kwargs={'step': 'basetreatment-treatment_creation'}))
@@ -565,6 +589,20 @@ def container_treatment_add(request, pk, current_right=None):
",".join([str(f.pk) for f in basket.items.all()]))
+def treatmentfile_treatment_add(request, pk, current_right=None):
+ try:
+ tf = models.TreatmentFile.objects.get(pk=pk)
+ except models.TreatmentFile.DoesNotExist:
+ raise Http404()
+ if not tf.associated_basket:
+ raise Http404()
+ basket = tf.associated_basket
+ return treatment_add(
+ request, ",".join([str(f.pk) for f in basket.items.all()]),
+ treatment_file=tf
+ )
+
+
treatment_deletion_wizard = wizards.TreatmentDeletionWizard.as_view([
('selec-treatment_deletion', forms.TreatmentFormSelection),
('final-treatment_deletion', forms.TreatmentDeletionForm)],