From f4bad8942ed753b85fcf7bdb00ce666bebe53c97 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 21 Jan 2018 20:28:02 +0100 Subject: Administrativ act: adapt forms, models and sheet --- archaeological_files/forms.py | 4 ++ archaeological_finds/forms_treatments.py | 2 + archaeological_operations/forms.py | 2 + archaeological_operations/models.py | 36 ++++++++------- .../templates/ishtar/sheet_administrativeact.html | 51 +++++++++++++--------- ishtar_common/models.py | 4 ++ ishtar_common/utils.py | 6 +-- 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 %}{% trans "Administrative act" %} - {{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 %}

{% trans "General"%}

- + {% if item.general_contractor %}

{{ item.general_contractor.full_label }}

{% endif %} + {% endcomment %} + {% 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 -- cgit v1.2.3