summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-04-13 13:23:35 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-04-13 13:23:35 +0200
commitae9366fc3f24d869fa9cce7c0077d06e6db95571 (patch)
tree71d968e3d0b0571b4c1d1bef036774f30e98dbcf
parentb790e4875b47e2951a65eedd36dc661079667541 (diff)
downloadIshtar-ae9366fc3f24d869fa9cce7c0077d06e6db95571.tar.bz2
Ishtar-ae9366fc3f24d869fa9cce7c0077d06e6db95571.zip
New type of operation: court-ordered seizure with associated fields (refs #4048)
* models * migrations * wizard panel * forms * sheet
-rw-r--r--archaeological_finds/forms.py30
-rw-r--r--archaeological_finds/migrations/0022_auto_20180413_1147.py25
-rw-r--r--archaeological_finds/models_finds.py7
-rw-r--r--archaeological_finds/templates/ishtar/sheet_find.html1
-rw-r--r--archaeological_finds/wizards.py7
-rw-r--r--archaeological_operations/forms.py16
-rw-r--r--archaeological_operations/migrations/0023_auto_20180413_1147.py45
-rw-r--r--archaeological_operations/models.py8
-rw-r--r--archaeological_operations/templates/ishtar/sheet_operation.html9
-rw-r--r--archaeological_operations/views.py13
-rw-r--r--archaeological_operations/wizards.py22
-rw-r--r--ishtar_common/forms.py7
-rw-r--r--ishtar_common/migrations/0040_auto_20180413_1147.py25
-rw-r--r--ishtar_common/models.py33
14 files changed, 223 insertions, 25 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 6811f7773..15d86f91f 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -152,6 +152,7 @@ class FindForm(CustomForm, ManageOldType):
get_first_base_find__excavation_id = forms.CharField(
label=_(u"Excavation ID"), required=False)
museum_id = forms.CharField(label=_(u"Museum ID"), required=False)
+ seal_number = forms.CharField(label=_(u"Seal number"), required=False)
mark = forms.CharField(label=_(u"Mark"), required=False)
HEADERS['description'] = FormHeader(_(u"Description"))
@@ -235,25 +236,24 @@ class FindForm(CustomForm, ManageOldType):
FieldType('communicabilitie', models.CommunicabilityType,
is_multiple=True),
FieldType('get_first_base_find__batch', models.BatchType),
+ FieldType('get_first_base_find__spatial_reference_system',
+ SpatialReferenceSystem),
]
+ PROFILE_FILTER = {
+ 'mapping': [
+ 'get_first_base_find__x', 'get_first_base_find__y',
+ 'get_first_base_find__z', 'get_first_base_find__estimated_error_x',
+ 'get_first_base_find__estimated_error_y',
+ 'get_first_base_find__estimated_error_z',
+ 'get_first_base_find__spatial_reference_system'
+ ],
+ }
def __init__(self, *args, **kwargs):
+ context_record = kwargs.pop('context_record')
super(FindForm, self).__init__(*args, **kwargs)
- if not get_current_profile().mapping:
- for k in ['get_first_base_find__x', 'get_first_base_find__y',
- 'get_first_base_find__z',
- 'get_first_base_find__estimated_error_x',
- 'get_first_base_find__estimated_error_y',
- 'get_first_base_find__estimated_error_z',
- 'get_first_base_find__spatial_reference_system',]:
- self.fields.pop(k)
- else:
- srs = 'get_first_base_find__spatial_reference_system'
- self.fields[srs].choices = \
- SpatialReferenceSystem.get_types(
- initial=self.init_data.get(srs))
- self.fields[srs].help_text = \
- SpatialReferenceSystem.get_help()
+ if not context_record.operation.operation_type.judiciary:
+ self.fields.pop('seal_number')
self.fields['checked'].choices = models.CHECK_CHOICES
def clean(self):
diff --git a/archaeological_finds/migrations/0022_auto_20180413_1147.py b/archaeological_finds/migrations/0022_auto_20180413_1147.py
new file mode 100644
index 000000000..4b46d4da6
--- /dev/null
+++ b/archaeological_finds/migrations/0022_auto_20180413_1147.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-04-13 11:47
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_finds', '0021_auto_20180403_1120'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='find',
+ name='seal_number',
+ field=models.TextField(blank=True, null=True, verbose_name='Seal number'),
+ ),
+ migrations.AddField(
+ model_name='historicalfind',
+ name='seal_number',
+ field=models.TextField(blank=True, null=True, verbose_name='Seal number'),
+ ),
+ ]
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index ae3c45579..ecb4d049b 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -559,7 +559,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel,
CHECK_DICT = dict(CHECK_CHOICES)
SHOW_URL = 'show-find'
SLUG = 'find'
- TABLE_COLS = ['external_id', 'label', 'base_finds__context_record__parcel__town__name',
+ TABLE_COLS = ['external_id', 'label',
+ 'base_finds__context_record__parcel__town__name',
'base_finds__context_record__operation__common_name',
'base_finds__context_record__label',
'material_types__label', 'object_types__label',
@@ -683,6 +684,10 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel,
external_id = models.TextField(_(u"External ID"), blank=True, null=True)
auto_external_id = models.BooleanField(
_(u"External ID is set automatically"), default=False)
+ # judiciary operation
+ seal_number = models.TextField(
+ _(u"Seal number"), blank=True, null=True
+ )
order = models.IntegerField(_(u"Order"), default=1)
label = models.TextField(_(u"Free ID"))
denomination = models.TextField(_(u"Denomination"), blank=True, null=True)
diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html
index de1993634..5062963ba 100644
--- a/archaeological_finds/templates/ishtar/sheet_find.html
+++ b/archaeological_finds/templates/ishtar/sheet_find.html
@@ -41,6 +41,7 @@
{% field_flex "Previous ID" item.previous_id %}
{% field_flex "Excavation ID" item.excavation_ids %}
{% field_flex "Museum ID" item.museum_id %}
+ {% field_flex "Seal number" item.seal_number %}
{% trans "Administrative index" as admin_index_label %}
{% field_flex admin_index_label item.administrative_index %}
{% include "ishtar/blocks/sheet_creation_section.html" %}
diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py
index b4471a80b..b244118cd 100644
--- a/archaeological_finds/wizards.py
+++ b/archaeological_finds/wizards.py
@@ -51,6 +51,13 @@ class FindWizard(Wizard):
if base_finds:
return base_finds[0].context_record
+ def get_form_kwargs(self, step=None):
+ kwargs = super(FindWizard, self).get_form_kwargs(step)
+ if step not in ('find-find_creation', 'find-find_modification'):
+ return kwargs
+ kwargs['context_record'] = self.get_current_contextrecord()
+ return kwargs
+
def get_context_data(self, form, **kwargs):
"""
Get the operation and context record "reminder" on top of wizard forms
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 9906709d9..bb2393ab9 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -997,6 +997,22 @@ OperationFormModifGeneral.associated_models = \
OperationFormModifGeneral.associated_models['associated_file'] = File
+class CourtOrderedSeizureForm(CustomForm, IshtarForm):
+ form_label = _(u"Court-ordered seizure")
+ form_admin_name = _(u"Operation - 015 - Court-ordered seizure")
+ form_slug = "operation-015-court-ordered-seizure"
+
+ seizure_name = forms.CharField(
+ label=_(u"Seizure name"), required=False,
+ )
+ official_report_number = forms.CharField(
+ label=_(u"Official report number"), required=False,
+ )
+ name_of_the_protagonist = forms.CharField(
+ label=_(u"Name of the protagonist"), required=False,
+ )
+
+
class CollaboratorForm(CustomForm, IshtarForm):
form_label = _(u"Collaborators")
form_admin_name = _(u"Operation - 020 - Collaborators")
diff --git a/archaeological_operations/migrations/0023_auto_20180413_1147.py b/archaeological_operations/migrations/0023_auto_20180413_1147.py
new file mode 100644
index 000000000..421f0e3e2
--- /dev/null
+++ b/archaeological_operations/migrations/0023_auto_20180413_1147.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-04-13 11:47
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_operations', '0022_auto_20180403_1120'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='historicaloperation',
+ name='name_of_the_protagonist',
+ field=models.TextField(blank=True, null=True, verbose_name='Name of the protagonist'),
+ ),
+ migrations.AddField(
+ model_name='historicaloperation',
+ name='official_report_number',
+ field=models.TextField(blank=True, null=True, verbose_name='Official report number'),
+ ),
+ migrations.AddField(
+ model_name='historicaloperation',
+ name='seizure_name',
+ field=models.TextField(blank=True, null=True, verbose_name='Seizure name'),
+ ),
+ migrations.AddField(
+ model_name='operation',
+ name='name_of_the_protagonist',
+ field=models.TextField(blank=True, null=True, verbose_name='Name of the protagonist'),
+ ),
+ migrations.AddField(
+ model_name='operation',
+ name='official_report_number',
+ field=models.TextField(blank=True, null=True, verbose_name='Official report number'),
+ ),
+ migrations.AddField(
+ model_name='operation',
+ name='seizure_name',
+ field=models.TextField(blank=True, null=True, verbose_name='Seizure name'),
+ ),
+ ]
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 6daf9dc12..12c1cce8e 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -468,6 +468,14 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms,
finds_received = models.NullBooleanField(
_(u"Finds received"), blank=True, null=True)
+ # judiciary
+ seizure_name = models.TextField(_(u"Seizure name"), blank=True, null=True)
+ official_report_number = models.TextField(_(u"Official report number"),
+ blank=True, null=True)
+ name_of_the_protagonist = models.TextField(_(u"Name of the protagonist"),
+ blank=True, null=True)
+
+ # gis
point = models.PointField(_(u"Point"), blank=True, null=True)
multi_polygon = models.MultiPolygonField(_(u"Multi polygon"), blank=True,
null=True)
diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html
index 3be570326..8530d0579 100644
--- a/archaeological_operations/templates/ishtar/sheet_operation.html
+++ b/archaeological_operations/templates/ishtar/sheet_operation.html
@@ -131,6 +131,15 @@
</div>
{% endif %}
+{% if item.seizure_name or item.official_report_number or item.name_of_the_protagonist %}
+<h3>{% trans "Court-ordered seizure"%}</h3>
+<div class="row">
+ {% field_flex "Seizure name" item.seizure_name %}
+ {% field_flex "Official report number" item.official_report_number %}
+ {% field_flex "Name of the protagonist" item.name_of_the_protagonist %}
+</div>
+{% endif %}
+
{% if not next %}
{% if item.towns.count %}
<h3>{% trans "Localisation"%}</h3>
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 61c9e6c19..fcd6c3252 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -44,13 +44,14 @@ from archaeological_operations.forms import ArchaeologicalSiteForm, \
AdministrativeActOpeFormSelection, AdministrativeActOpeForm, \
AdministrativeActOpeModifForm, FinalAdministrativeActDeleteForm, \
AdministrativeActRegisterFormSelection, DocumentGenerationAdminActForm, \
- SiteForm, SiteTownFormset, SiteUnderwaterForm, check_underwater_module
+ SiteForm, SiteTownFormset, SiteUnderwaterForm, check_underwater_module, \
+ CourtOrderedSeizureForm
from ishtar_common.views import get_item, show_item, revert_item, new_item
from ishtar_common.wizards import SearchWizard, check_rights_condition
from archaeological_operations.wizards import has_associated_file, \
- is_preventive, OperationWizard, OperationModificationWizard, \
+ is_preventive, is_judiciary, OperationWizard, OperationModificationWizard, \
OperationClosingWizard, OperationDeletionWizard, SiteSearch, \
OperationSourceWizard, OperationSourceDeletionWizard, \
OperationAdministrativeActWizard, OperationEditAdministrativeActWizard, \
@@ -192,6 +193,7 @@ operation_search_wizard = SearchWizard.as_view(
wizard_steps = [
('filechoice-operation_creation', OperationFormFileChoice),
('general-operation_creation', OperationFormGeneral),
+ ('judiciary-operation_creation', CourtOrderedSeizureForm),
('collaborators-operation_creation', CollaboratorForm),
('archaeologicalsite-operation_creation', ArchaeologicalSiteFormSet),
('preventive-operation_creation', OperationFormPreventive),
@@ -223,6 +225,9 @@ check_files_for_operation = get_check_files_for_operation()
ope_crea_condition_dict = {
'filechoice-operation_creation': check_files_for_operation,
+ 'judiciary-operation_creation': is_judiciary(
+ 'general-operation_creation', models.OperationType, 'operation_type',
+ ),
'preventive-operation_creation':
get_check_files_for_operation(
is_preventive('general-operation_creation', models.OperationType,
@@ -250,6 +255,7 @@ operation_creation_wizard = OperationWizard.as_view(
operation_modif_wizard_steps = [
('selec-operation_modification', OperationFormSelection),
('general-operation_modification', OperationFormModifGeneral),
+ ('judiciary-operation_modification', CourtOrderedSeizureForm),
('collaborators-operation_modification', CollaboratorForm),
('archaeologicalsite-operation_modification', ArchaeologicalSiteFormSet),
('preventive-operation_modification', OperationFormPreventive),
@@ -275,6 +281,9 @@ ope_modif_condition_dict = {
get_check_files_for_operation(
is_preventive('general-operation_modification', models.OperationType,
'operation_type', 'arch_diagnostic')),
+ 'judiciary-operation_modification': is_judiciary(
+ 'general-operation_modification', models.OperationType, 'operation_type',
+ ),
'townsgeneral-operation_modification': has_associated_file(
'general-operation_modification', negate=True),
'towns-operation_modification': has_associated_file(
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py
index ddad8dd2e..d4830a2e7 100644
--- a/archaeological_operations/wizards.py
+++ b/archaeological_operations/wizards.py
@@ -526,6 +526,28 @@ def is_not_preventive(form_name, model, type_key='operation_type', key=''):
return func
+def is_judiciary(form_name, model, type_key='operation_type'):
+ def func(self):
+ request = self.request
+ storage = self.storage
+ if storage.prefix not in request.session or \
+ 'step_data' not in request.session[storage.prefix] or \
+ form_name not in request.session[storage.prefix]['step_data'] \
+ or form_name + '-' + type_key not in \
+ request.session[storage.prefix]['step_data'][form_name]:
+ return False
+ try:
+ typ = request.session[storage.prefix][
+ 'step_data'][form_name][form_name + '-' + type_key]
+ if type(typ) in (list, tuple):
+ typ = typ[0]
+ typ = int(typ)
+ return model.is_judiciary(typ)
+ except ValueError:
+ return False
+ return func
+
+
def has_associated_file(form_name, file_key='associated_file', negate=False):
def func(self):
request = self.request
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index c4d6f2026..70e144980 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -279,10 +279,17 @@ class FormHeader(object):
class IshtarForm(forms.Form):
TYPES = [] # FieldType list
+ PROFILE_FILTER = {} # profile key associated to field list
HEADERS = {} # field key associated to FormHeader instance
def __init__(self, *args, **kwargs):
super(IshtarForm, self).__init__(*args, **kwargs)
+ if self.PROFILE_FILTER:
+ profile = models.get_current_profile()
+ for profile_key in self.PROFILE_FILTER:
+ if not getattr(profile, profile_key):
+ for field_key in self.PROFILE_FILTER[profile_key]:
+ self.fields.pop(field_key)
for field in self.TYPES:
self._init_type(field)
for k in self.fields:
diff --git a/ishtar_common/migrations/0040_auto_20180413_1147.py b/ishtar_common/migrations/0040_auto_20180413_1147.py
new file mode 100644
index 000000000..2dd9ab3de
--- /dev/null
+++ b/ishtar_common/migrations/0040_auto_20180413_1147.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-04-13 11:47
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0039_auto_20180405_1923'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='operationtype',
+ name='judiciary',
+ field=models.BooleanField(default=False, verbose_name='Is judiciary'),
+ ),
+ migrations.AlterField(
+ model_name='import',
+ name='state',
+ field=models.CharField(choices=[(b'C', 'Created'), (b'AP', 'Analyse in progress'), (b'A', 'Analysed'), (b'HQ', 'Check modified in queue'), (b'IQ', 'Import in queue'), (b'HP', 'Check modified in progress'), (b'IP', 'Import in progress'), (b'PI', 'Partially imported'), (b'FE', 'Finished with errors'), (b'F', 'Finished'), (b'AC', 'Archived')], default='C', max_length=2, verbose_name='State'),
+ ),
+ ]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 8d0339b92..b92614e08 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3069,15 +3069,19 @@ m2m_changed.connect(town_child_changed, sender=Town.children.through)
class OperationType(GeneralType):
order = models.IntegerField(_(u"Order"), default=1)
preventive = models.BooleanField(_(u"Is preventive"), default=True)
+ judiciary = models.BooleanField(_(u"Is judiciary"), default=False)
class Meta:
verbose_name = _(u"Operation type")
verbose_name_plural = _(u"Operation types")
- ordering = ['-preventive', 'order', 'label']
+ ordering = ['judiciary', '-preventive', 'order', 'label']
@classmethod
- def get_types(cls, dct={}, instances=False, exclude=[], empty_first=True,
- default=None, initial=[]):
+ def get_types(cls, dct=None, instances=False, exclude=None,
+ empty_first=True, default=None, initial=None):
+ dct = dct or {}
+ exclude = exclude or []
+ initial = initial or []
tuples = []
dct['available'] = True
if not instances and empty_first and not default:
@@ -3093,7 +3097,7 @@ class OperationType(GeneralType):
exclude.append(default.txt_idx)
if exclude:
items = items.exclude(txt_idx__in=exclude)
- current_preventive, current_lst = None, None
+ current_preventive, current_judiciary, current_lst = None, None, None
item_list = list(items.order_by(*cls._meta.ordering).all())
new_vals = cls._get_initial_types(initial, [i.pk for i in item_list],
instance=True)
@@ -3103,12 +3107,19 @@ class OperationType(GeneralType):
if instances:
return item_list
for item in item_list:
- if not current_lst or item.preventive != current_preventive:
+ if not current_lst or item.preventive != current_preventive \
+ or item.judiciary != current_judiciary:
if current_lst:
tuples.append(current_lst)
- current_lst = [_(u"Preventive") if item.preventive else
- _(u"Research"), []]
+ if item.judiciary:
+ gp_lbl = _(u"Judiciary")
+ elif item.preventive:
+ gp_lbl = _(u"Preventive")
+ else:
+ gp_lbl = _(u"Research")
+ current_lst = [gp_lbl, []]
current_preventive = item.preventive
+ current_judiciary = item.judiciary
current_lst[1].append((item.pk, _(unicode(item))))
if current_lst:
tuples.append(current_lst)
@@ -3124,6 +3135,14 @@ class OperationType(GeneralType):
return op_type.preventive
return key == op_type.txt_idx
+ @classmethod
+ def is_judiciary(cls, ope_type_id):
+ try:
+ op_type = cls.objects.get(pk=ope_type_id)
+ except cls.DoesNotExist:
+ return False
+ return op_type.judiciary
+
post_save.connect(post_save_cache, sender=OperationType)
post_delete.connect(post_save_cache, sender=OperationType)