diff options
| -rw-r--r-- | archaeological_operations/admin.py | 7 | ||||
| -rw-r--r-- | archaeological_operations/forms.py | 24 | ||||
| -rw-r--r-- | archaeological_operations/models.py | 35 | ||||
| -rw-r--r-- | archaeological_operations/templates/ishtar/sheet_operation.html | 3 | ||||
| -rw-r--r-- | ishtar_common/models.py | 35 | 
5 files changed, 76 insertions, 28 deletions
| diff --git a/archaeological_operations/admin.py b/archaeological_operations/admin.py index e10c962ca..60a1bad3a 100644 --- a/archaeological_operations/admin.py +++ b/archaeological_operations/admin.py @@ -164,6 +164,13 @@ class RelationTypeAdmin(GeneralTypeAdmin):  admin_site.register(models.RelationType, RelationTypeAdmin) +class RecordQualityTypeAdmin(GeneralTypeAdmin): +    list_display = ['label', 'txt_idx', 'available', 'order', 'comment'] + + +admin_site.register(models.RecordQualityType, RecordQualityTypeAdmin) + +  class ActTypeAdmin(GeneralTypeAdmin):      list_filter = ('intented_to',)      list_display = ['label', 'txt_idx', 'available', 'intented_to'] diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 20379e588..af4e21e31 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -739,13 +739,15 @@ class OperationFormGeneral(CustomForm, ManageOldType):      form_slug = "operation-010-general"      file_upload = True -    associated_models = {'scientist': Person, -                         'in_charge': Person, -                         'cira_rapporteur': Person, -                         'operator': Organization, -                         'operation_type': models.OperationType, -                         'report_processing': models.ReportState, -                         } +    associated_models = { +        'scientist': Person, +        'in_charge': Person, +        'cira_rapporteur': Person, +        'operator': Organization, +        'operation_type': models.OperationType, +        'record_quality_type': models.RecordQualityType, +        'report_processing': models.ReportState +    }      pk = forms.IntegerField(required=False, widget=forms.HiddenInput)      if settings.COUNTRY == 'fr':          code_patriarche = forms.CharField(label=u"Code PATRIARCHE", @@ -841,8 +843,8 @@ class OperationFormGeneral(CustomForm, ManageOldType):      scientific_documentation_comment = forms.CharField(          label=_(u"Comment about scientific documentation"),          widget=forms.Textarea, required=False) -    record_quality = forms.ChoiceField(label=_(u"Record quality"), -                                       required=False) +    record_quality_type = forms.ChoiceField(label=_(u"Record quality"), +                                            required=False)      virtual_operation = forms.BooleanField(required=False,                                             label=_(u"Virtual operation")) @@ -861,6 +863,7 @@ class OperationFormGeneral(CustomForm, ManageOldType):      ]      TYPES = [          FieldType('operation_type', models.OperationType), +        FieldType('record_quality_type', models.RecordQualityType),          FieldType('report_processing', models.ReportState),      ] @@ -873,9 +876,6 @@ class OperationFormGeneral(CustomForm, ManageOldType):              if not profile.warehouse:                  for key in self.WAREHOUSE_FIELDS:                      self.remove_field(key) -        if 'record_quality' in self.fields: -            self.fields['record_quality'].choices = \ -                [('', '--')] + list(models.QUALITY)      def clean(self):          cleaned_data = self.cleaned_data diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 035235b51..f09184a32 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -101,12 +101,21 @@ class ArchaeologicalSite(BaseHistorizedItem):      SHOW_URL = 'show-site'      TABLE_COLS = ['reference', 'name', 'towns', 'periods', 'remains']      SLUG = 'site' +      BASE_SEARCH_VECTORS = [ -        "reference", "name", "oceanographic_service_localisation", -        "shipwreck_code", "comment", "shipwreck_name", "discovery_area", +        "comment", +        "discovery_area", +        "locality_cadastral", +        "locality_ngi", +        "name", +        "oceanographic_service_localisation", +        "reference", +        "shipwreck_code", +        "shipwreck_name",      ]      M2M_SEARCH_VECTORS = ["periods__label", "remains__label", "towns__name"]      PARENT_SEARCH_VECTORS = ['operations'] +      reference = models.CharField(_(u"Reference"), max_length=200, unique=True)      name = models.CharField(_(u"Name"), max_length=200,                              null=True, blank=True) @@ -354,12 +363,26 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,                                               u"reference)"),      }      BASE_SEARCH_VECTORS = [ -        "scientist__raw_name", "cached_label", "common_name", "comment", -        "address", "old_code", "seizure_name", "official_report_number", -        "name_of_the_protagonist" +        "abstract", +        "address", +        "code_patriarche", +        "comment", +        "common_name", +        "in_charge__cached_label", +        "name_of_the_protagonist", +        "official_report_number", +        "old_code", +        "operation_type__label", +        "operator_reference", +        "operator__cached_label", +        "scientist__cached_label", +        "scientific_documentation_comment", +        "seizure_name",      ]      INT_SEARCH_VECTORS = ["year"] -    M2M_SEARCH_VECTORS = ["towns__name"] +    M2M_SEARCH_VECTORS = ["periods__label", "remains__label", "towns__name"] +    PARENT_SEARCH_VECTORS = ["associated_file"] +    PARENT_ONLY_SEARCH_VECTORS = ["archaeological_sites"]      ASSOCIATED = {          "scientist": {              ('person_types', PersonType): ( diff --git a/archaeological_operations/templates/ishtar/sheet_operation.html b/archaeological_operations/templates/ishtar/sheet_operation.html index 231db2ae8..91c1501ec 100644 --- a/archaeological_operations/templates/ishtar/sheet_operation.html +++ b/archaeological_operations/templates/ishtar/sheet_operation.html @@ -87,8 +87,7 @@      {%endif%}      {% field_flex_multiple "Remains" item.remains %}      {% field_flex_multiple "Periods" item.periods %} -    {% if item.QUALITY_DICT %}{% field_flex "Record quality" item.record_quality|from_dict:item.QUALITY_DICT %}{% endif %} -    {% if item.history_object and item.history_object.QUALITY_DICT %}{% field_flex "Record quality" item.record_quality|from_dict:item.history_object.QUALITY_DICT %}{% endif %} +    {% field_flex "Record quality" item.record_quality_type %}      {% field_flex "Report delivery date" item.report_delivery_date %}      {% field_flex "Report processing" item.report_processing %}      {% field_flex "Deadline for submission of the documentation" item.documentation_deadline %} diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 678e2ce41..cb225d0f6 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1091,6 +1091,8 @@ class FullSearch(models.Model):      INT_SEARCH_VECTORS = []      M2M_SEARCH_VECTORS = []      PARENT_SEARCH_VECTORS = [] +    # prevent circular dependency +    PARENT_ONLY_SEARCH_VECTORS = []      class Meta:          abstract = True @@ -1105,7 +1107,7 @@ class FullSearch(models.Model):              if issubclass(rel_model, (GeneralType, HierarchicalType)):                  yield k -    def update_search_vector(self, save=True): +    def update_search_vector(self, save=True, exclude_parent=False):          """          Update the search vector          :param save: True if you want to save the object immediately @@ -1153,14 +1155,27 @@ class FullSearch(models.Model):              search_vectors.append(                  "'{}':1".format(q.all()[0][INT_SEARCH_VECTOR])) -        # copy parent vector fields -        for PARENT_SEARCH_VECTOR in self.PARENT_SEARCH_VECTORS: -            parent = getattr(self, PARENT_SEARCH_VECTOR) +        if not exclude_parent: +            # copy parent vector fields +            for PARENT_SEARCH_VECTOR in self.PARENT_SEARCH_VECTORS: +                parent = getattr(self, PARENT_SEARCH_VECTOR) +                if hasattr(parent, 'all'):  # m2m +                    for p in parent.all(): +                        search_vectors.append(p.search_vector) +                elif parent: +                    search_vectors.append(parent.search_vector) + +        for PARENT_ONLY_SEARCH_VECTOR in self.PARENT_ONLY_SEARCH_VECTORS: +            parent = getattr(self, PARENT_ONLY_SEARCH_VECTOR)              if hasattr(parent, 'all'):  # m2m                  for p in parent.all(): -                    search_vectors.append(p.search_vector) +                    search_vectors.append( +                        p.update_search_vector(save=False, exclude_parent=True) +                    )              elif parent: -                search_vectors.append(parent.search_vector) +                search_vectors.append( +                    parent.update_search_vector(save=False, exclude_parent=True) +                )          if self.BASE_SEARCH_VECTORS:              # query "simple" fields @@ -1194,11 +1209,15 @@ class FullSearch(models.Model):                                     [data])                      row = cursor.fetchone()                      search_vectors.append(row[0]) -        self.search_vector = merge_tsvectors(search_vectors) -        changed = old_search != self.search_vector +        # self.search_vector = merge_tsvectors(search_vectors) +        new_search_vector = merge_tsvectors(search_vectors) +        changed = old_search != new_search_vector          if save and changed: +            self.search_vector = new_search_vector              self.skip_history_when_saving = True              self.save() +        elif not save: +            return new_search_vector          return changed | 
