summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-01-21 20:28:02 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-01-21 20:28:02 +0100
commitf4bad8942ed753b85fcf7bdb00ce666bebe53c97 (patch)
tree5e230e6e9a775029ee560a92a4678064ae1a3ec4
parentaf1ea36dabb2cd1e165e54020286ff723c109f37 (diff)
downloadIshtar-f4bad8942ed753b85fcf7bdb00ce666bebe53c97.tar.bz2
Ishtar-f4bad8942ed753b85fcf7bdb00ce666bebe53c97.zip
Administrativ act: adapt forms, models and sheet
-rw-r--r--archaeological_files/forms.py4
-rw-r--r--archaeological_finds/forms_treatments.py2
-rw-r--r--archaeological_operations/forms.py2
-rw-r--r--archaeological_operations/models.py36
-rw-r--r--archaeological_operations/templates/ishtar/sheet_administrativeact.html51
-rw-r--r--ishtar_common/models.py4
-rw-r--r--ishtar_common/utils.py6
7 files changed, 66 insertions, 39 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index d72791ac0..b075c6fc8 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -403,6 +403,7 @@ class FinalFileDeleteForm(FinalForm):
class AdministrativeActFileModifySelect(TableSelect):
+ search_vector = forms.CharField(label=_(u"Full text search"))
year = forms.IntegerField(label=_("Year"))
index = forms.IntegerField(label=_("Index"))
if settings.COUNTRY == 'fr':
@@ -430,6 +431,7 @@ class AdministrativeActFileModifySelect(TableSelect):
class AdministrativeActFileSelect(TableSelect):
+ search_vector = forms.CharField(label=_(u"Full text search"))
year = forms.IntegerField(label=_("Year"))
index = forms.IntegerField(label=_("Index"))
if settings.COUNTRY == 'fr':
@@ -519,6 +521,7 @@ class AdministrativeActFileSelect(TableSelect):
class AdministrativeActFileFormSelection(AdministrativeActOpeFormSelection):
+ SEARCH_AND_SELECT = True
pk = forms.IntegerField(
label="", required=False,
widget=widgets.DataTable(
@@ -530,6 +533,7 @@ class AdministrativeActFileFormSelection(AdministrativeActOpeFormSelection):
class AdministrativeActFileModifyFormSelection(
AdministrativeActOpeFormSelection):
+ SEARCH_AND_SELECT = True
pk = forms.IntegerField(
label="", required=False,
widget=widgets.DataTable(
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index fd74cc599..6dfc028e6 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -333,6 +333,7 @@ class DashboardForm(IshtarForm):
class AdministrativeActTreatmentSelect(TableSelect):
+ search_vector = forms.CharField(label=_(u"Full text search"))
year = forms.IntegerField(label=_("Year"))
index = forms.IntegerField(label=_("Index"))
act_type = forms.ChoiceField(label=_("Act type"), choices=[])
@@ -588,6 +589,7 @@ class DashboardTreatmentFileForm(IshtarForm):
class AdministrativeActTreatmentFileSelect(TableSelect):
+ search_vector = forms.CharField(label=_(u"Full text search"))
year = forms.IntegerField(label=_("Year"))
index = forms.IntegerField(label=_("Index"))
act_type = forms.ChoiceField(label=_("Act type"), choices=[])
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index d26af8771..3541020d8 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -1327,6 +1327,7 @@ OperationSourceFormSelection = get_form_selection(
class AdministrativeActOpeSelect(TableSelect):
+ search_vector = forms.CharField(label=_(u"Full text search"))
year = forms.IntegerField(label=_("Year"))
index = forms.IntegerField(label=_("Index"))
if settings.COUNTRY == 'fr':
@@ -1380,6 +1381,7 @@ class AdministrativeActOpeSelect(TableSelect):
class AdministrativeActOpeFormSelection(IshtarForm):
+ SEARCH_AND_SELECT = True
form_label = _("Administrative act search")
associated_models = {'pk': models.AdministrativeAct}
currents = {'pk': models.AdministrativeAct}
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 58fa8b8c6..d46d55089 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -986,6 +986,8 @@ class ActType(GeneralType):
verbose_name = _(u"Act type")
verbose_name_plural = _(u"Act types")
ordering = ('label',)
+
+
post_save.connect(post_save_cache, sender=ActType)
post_delete.connect(post_save_cache, sender=ActType)
@@ -1051,6 +1053,12 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
RELATIVE_SESSION_NAMES = [('operation', 'operation__pk'),
('file', 'associated_file__pk')]
COL_LABELS = {'full_ref': _(u"Ref.")}
+ BASE_SEARCH_VECTORS = ['act_type__label', 'act_object',
+ 'towns_label']
+ INT_SEARCH_VECTORS = ["year", "index"]
+ PARENT_SEARCH_VECTORS = ['operator', 'scientist', 'signatory',
+ 'associated_file', 'operation', 'treatment_file',
+ 'treatment']
# fields
act_type = models.ForeignKey(ActType, verbose_name=_(u"Act type"))
@@ -1248,25 +1256,23 @@ class AdministrativeAct(BaseHistorizedItem, OwnPerms, ValueGetter):
if 'force' in kwargs:
force = kwargs.pop('force')
- if not self.signature_date:
- return super(AdministrativeAct, self).save(*args, **kwargs)
- self.year = self.signature_date.year
-
- if not self.act_type.indexed:
- return super(AdministrativeAct, self).save(*args, **kwargs)
-
- if not force:
- self._get_index()
- else:
- try:
- self._get_index()
- except:
- pass
-
+ if self.signature_date:
+ self.year = self.signature_date.year
+ if self.act_type.indexed:
+ if not force:
+ self._get_index()
+ else:
+ try:
+ self._get_index()
+ except:
+ pass
super(AdministrativeAct, self).save(*args, **kwargs)
if hasattr(self, 'associated_file') and self.associated_file:
self.associated_file.update_has_admin_act()
self.associated_file.update_short_menu_class()
+ updated = self.update_search_vector()
+ if updated:
+ self.save()
def strip_zero(value):
diff --git a/archaeological_operations/templates/ishtar/sheet_administrativeact.html b/archaeological_operations/templates/ishtar/sheet_administrativeact.html
index 92246ba80..1ea2a789d 100644
--- a/archaeological_operations/templates/ishtar/sheet_administrativeact.html
+++ b/archaeological_operations/templates/ishtar/sheet_administrativeact.html
@@ -1,9 +1,9 @@
{% extends "ishtar/sheet.html" %}
{% load i18n window_header window_field %}
-{% block head_title %}{% trans "Administrative act" %}{% endblock %}
+{% block head_title %}<strong>{% trans "Administrative act" %}</strong> - {{item.full_ref}}{% endblock %}
-{% block content %}
+{% block toolbar %}
{% if item.operation %}
{% window_nav item window_id 'show-administrativeact' 'operation_administrativeactop_modify' %}
{% endif %}
@@ -16,31 +16,40 @@
{% if item.treatment_file %}
{% window_nav item window_id 'show-administrativeact' 'treatmentfile_administrativeacttreatmentfile_modify' %}
{% endif %}
+{% endblock %}
+
+{% block content %}
<h3>{% trans "General"%}</h3>
-<ul class='form-flex'>
- {% field_li "Year" item.year %}
- {% field_li "Index" item.index %}
- {% field_li "Internal reference" item.ref_sra %}
- {% field_li "Type" item.act_type %}
- {% field_li "Object" item.act_object %}
- {% field_li "Signature date" item.signature_date %}
- {% field_li "In charge" item.in_charge %}
- {% field_li "Archaeological preventive operator" item.operator %}
- {% field_li_detail "Associated file" item.associated_file %}
- {% field_li_detail "Operation" item.operation %}
- {% field_li_detail "Treatment" item.treatment %}
- {% field_li_detail "Treatment request" item.treatment_file %}
+<div class="row">
+ {% field_flex "Year" item.year %}
+ {% field_flex "Index" item.index %}
+ {% field_flex "Internal reference" item.ref_sra %}
+ {% field_flex "Type" item.act_type %}
+ {% field_flex "Object" item.act_object %}
+ {% field_flex "Signature date" item.signature_date %}
+ {% field_flex "In charge" item.in_charge %}
+ {% field_flex "Archaeological preventive operator" item.operator %}
+ {% field_flex_detail "Associated file" item.associated_file %}
+ {% field_flex_detail "Operation" item.operation %}
+ {% field_flex_detail "Treatment" item.treatment %}
+ {% field_flex_detail "Treatment request" item.treatment_file %}
{% if item.operation and item.operation.surface %}
- <li><label>{% trans "Surface"%}</label> <span class='value'>{{ item.operation.surface }} m<sup>2</sup> ({{ item.operation.surface_ha }} ha)</span></li>
+ <div class="col-12 col-md-6 col-lg-4 d-flex flex-wrap row">
+ <dt class="col-5">{% trans "Surface"%}</dt>
+ <dd class='col-7'>
+ {{ item.operation.surface }} m<sup>2</sup> ({{ item.operation.surface_ha }} ha)
+ </dd>
+ </div>
{% endif %}
- {% field_li_detail "Created by" item.history_creator.ishtaruser.person %}
-{% comment %}{% if item.general_contractor.attached_to %}<p>
+ {% field_flex_detail "Created by" item.history_creator.ishtaruser.person %}
+
+ {% comment %}{% if item.general_contractor.attached_to %}<p>
<label>{% trans "General contractor organisation"%}</label>
<span class='value'>{{ item.general_contractor.attached_to }}</span></p>{% endif %} <!-- Contractor's organisation displayed as concat of Name/Adress/postal_code/city -->
-{% if item.general_contractor %}<p><label>{%trans "General contractor"%}</label> <span class='value'>{{ item.general_contractor.full_label }}</span></p>{% endif %}
-{% endcomment %}
-</ul>
+ {% if item.general_contractor %}<p><label>{%trans "General contractor"%}</label> <span class='value'>{{ item.general_contractor.full_label }}</span></p>{% endif %}
+ {% endcomment %}
+</div>
{% endblock %}
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index eb84f8a7e..3af92a39e 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1030,6 +1030,10 @@ class FullSearch(models.Model):
:param save: True if you want to save the object immediately
:return: True if modified
"""
+ if not self.pk:
+ logger.warning("Cannot update search vector before save or "
+ "after deletion.")
+ return
if not self.BASE_SEARCH_VECTORS and not self.M2M_SEARCH_VECTORS \
and not self.INT_SEARCH_VECTORS \
and not self.PARENT_SEARCH_VECTORS:
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 4ecddfc92..23020ac95 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -129,11 +129,11 @@ def cached_label_changed(sender, **kwargs):
if hasattr(instance, '_cascade_change') and instance._cascade_change:
instance.skip_history_when_saving = True
instance.save()
- if hasattr(instance, 'update_search_vector'):
- instance.update_search_vector()
updated = False
+ if hasattr(instance, 'update_search_vector'):
+ updated = instance.update_search_vector()
if hasattr(instance, '_cached_labels_bulk_update'):
- updated = instance._cached_labels_bulk_update()
+ updated = instance._cached_labels_bulk_update() or updated
if not updated and hasattr(instance, '_get_associated_cached_labels'):
for item in instance._get_associated_cached_labels():
item._cascade_change = True