diff options
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 121 | 
1 files changed, 99 insertions, 22 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 6f083fe7f..035235b51 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -79,14 +79,24 @@ class ReportState(GeneralType):          verbose_name_plural = _(u"Types of report state")          ordering = ('order',) -    def __unicode__(self): -        return self.label -  post_save.connect(post_save_cache, sender=ReportState)  post_delete.connect(post_save_cache, sender=ReportState) +class RecordQualityType(GeneralType): +    order = models.IntegerField(_(u"Order")) + +    class Meta: +        verbose_name = _(u"Type of record quality") +        verbose_name_plural = _(u"Types of record quality") +        ordering = ('order',) + + +post_save.connect(post_save_cache, sender=RecordQualityType) +post_delete.connect(post_save_cache, sender=RecordQualityType) + +  class ArchaeologicalSite(BaseHistorizedItem):      SHOW_URL = 'show-site'      TABLE_COLS = ['reference', 'name', 'towns', 'periods', 'remains'] @@ -95,7 +105,7 @@ class ArchaeologicalSite(BaseHistorizedItem):          "reference", "name", "oceanographic_service_localisation",          "shipwreck_code", "comment", "shipwreck_name", "discovery_area",      ] -    M2M_SEARCH_VECTORS = ["periods__name", "remains__name", "towns__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, @@ -131,6 +141,8 @@ class ArchaeologicalSite(BaseHistorizedItem):      documents = models.ManyToManyField(          Document, related_name="sites", verbose_name=_(u"Documents"),          blank=True) +    cached_label = models.TextField(_(u"Cached name"), +                                    null=True, blank=True, db_index=True)      class Meta:          verbose_name = _(u"Archaeological site") @@ -149,6 +161,12 @@ class ArchaeologicalSite(BaseHistorizedItem):          )      def __unicode__(self): +        if self.cached_label: +            return self.cached_label +        self.save() +        return self.cached_label + +    def _generate_cached_label(self):          name = self.reference          if self.name:              name += u" %s %s" % (settings.JOINT, self.name) @@ -157,7 +175,7 @@ class ArchaeologicalSite(BaseHistorizedItem):          for k, lbl in keys:              if getattr(self, k).count():                  name += lbl.format(u", ".join([ -                    v.name for v in getattr(self, k).all() +                    unicode(v) for v in getattr(self, k).all()                  ]))          return name @@ -219,6 +237,9 @@ class ArchaeologicalSite(BaseHistorizedItem):              ) +post_save.connect(cached_label_changed, sender=ArchaeologicalSite) + +  def get_values_town_related(item, prefix, values):      values[prefix + 'parcellist'] = item.render_parcels()      values[prefix + 'towns'] = '' @@ -240,11 +261,6 @@ def get_values_town_related(item, prefix, values):      return values -QUALITY = (('ND', _(u"Not documented")), -           ('A', _(u"Arbitrary")), -           ('R', _(u"Reliable")),) - -  class ClosedItem(object):      def closing(self):          if self.is_active(): @@ -275,7 +291,6 @@ class ClosedItem(object):  class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,                  ShortMenuItem, DashboardFormItem, RelationItem): -    QUALITY_DICT = dict(QUALITY)      SHOW_URL = 'show-operation'      TABLE_COLS = ['year', 'towns', 'common_name', 'operation_type',                    'start_date', 'excavation_end_date', 'remains'] @@ -309,8 +324,6 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          'history_creator__ishtaruser__person__pk',          'history_modifier':          'history_modifier__ishtaruser__person__pk', -        'archaeological_sites': -        'archaeological_sites__pk',          'documentation_deadline_before': 'documentation_deadline__lte',          'documentation_deadline_after': 'documentation_deadline__gte',          'finds_deadline_before': 'finds_deadline__lte', @@ -384,15 +397,15 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          ),          'common_name': (              pgettext_lazy(TXT_SEARCH_COMMENT, u"name"), -            'common_name' +            'common_name__icontains'          ),          'address': (              pgettext_lazy(TXT_SEARCH_COMMENT, u"address"), -            'address' +            'address__icontains'          ),          'operation_type': (              pgettext_lazy(TXT_SEARCH_COMMENT, u"type"), -            'operation_type__pk' +            'operation_type__label__iexact'          ),          'end_date': (              pgettext_lazy(TXT_SEARCH_COMMENT, u"is-open"), @@ -412,11 +425,11 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          ),          'remains': (              pgettext_lazy(TXT_SEARCH_COMMENT, u"remain"), -            'remains__pk' +            'remains__label__iexact'          ),          'periods': (              pgettext_lazy(TXT_SEARCH_COMMENT, u"period"), -            'periods__pk' +            'periods__label__iexact'          ),          'start_before': (              pgettext_lazy(TXT_SEARCH_COMMENT, u"start-before"), @@ -437,7 +450,71 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          'relation_types': (              pgettext_lazy(TXT_SEARCH_COMMENT, u"relation-types"),              'relation_types' -        ) +        ), +        'comment': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"comment"), +            'comment__icontains' +        ), +        'abstract': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"abstract"), +            'abstract__icontains' +        ), +        'scientific_documentation_comment': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, +                          u"scientific-documentation-comment"), +            'scientific_documentation_comment__icontains' +        ), +        'record_quality_type': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"record-quality"), +            'record_quality_type__label__iexact' +        ), +        'report_processing': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, +                          u"report-processing"), +            'report_processing__label__iexact' +        ), +        'virtual_operation': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, +                          u"virtual_operation"), +            'virtual_operation' +        ), +        'archaeological_sites': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, +                          u"site"), +            'archaeological_sites__cached_label__icontains' +        ), +        'history_creator': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"created-by"), +            'history_creator__ishtaruser__person__cached_label__iexact' +        ), +        'history_modifier': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"modified-by"), +            'history_modifier__ishtaruser__person__cached_label__iexact' +        ), +        'documentation_received': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"documentation-received"), +            'documentation_received' +        ), +        'documentation_deadline_before': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"documentation-deadline-before"), +            'documentation_deadline__lte' +        ), +        'documentation_deadline_after': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"documentation-deadline-after"), +            'documentation_deadline__gte' +        ), +        'finds_received': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"finds-received"), +            'finds_received' +        ), +        'finds_deadline_before': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"finds-deadline-before"), +            'finds_deadline__lte' +        ), +        'finds_deadline_after': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"finds-deadline-after"), +            'finds_deadline__gte' +        ),      }      for v in ALT_NAMES.values():          EXTRA_REQUEST_KEYS[v[0]] = v[1] @@ -550,9 +627,9 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          default=False, help_text=_(              u"If checked, it means that this operation have not been "              u"officialy registered.")) -    record_quality = models.CharField( -        _(u"Record quality"), max_length=2, null=True, blank=True, -        choices=QUALITY) +    record_quality_type = models.ForeignKey( +        RecordQualityType, verbose_name=_(u"Record quality"), +        null=True, blank=True,)      abstract = models.TextField(_(u"Abstract"), null=True, blank=True)      documentation_deadline = models.DateField(          _(u"Deadline for submission of the documentation"), blank=True, | 
