diff options
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 54 | 
1 files changed, 53 insertions, 1 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e16c4a360..81a391b3b 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3168,6 +3168,8 @@ class Author(FullSearch):      person = models.ForeignKey(Person, verbose_name=_(u"Person"),                                 related_name='author')      author_type = models.ForeignKey(AuthorType, verbose_name=_(u"Author type")) +    cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, +                                    db_index=True)      class Meta:          verbose_name = _(u"Author") @@ -3182,6 +3184,12 @@ class Author(FullSearch):          )      def __unicode__(self): +        if self.cached_label: +            return self.cached_label +        self.save() +        return self.cached_label + +    def _generate_cached_label(self):          return unicode(self.person) + settings.JOINT + \              unicode(self.author_type) @@ -3196,6 +3204,9 @@ class Author(FullSearch):              list(self.contextrecordsource_related.all()) +post_save.connect(cached_label_changed, sender=Author) + +  class SourceType(HierarchicalType):      class Meta:          verbose_name = _(u"Source type") @@ -3276,9 +3287,50 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported):              "finds__base_finds__context_record__pk",          "finds__base_finds__context_record__operation":              "finds__base_finds__context_record__operation__pk", -        "authors__person": "authors__person__pk"      } +    # alternative names of fields for searches +    ALT_NAMES = { +        'authors': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"author"), +            'authors__cached_label__icontains' +        ), +        'title': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"title"), +            'title__icontains' +        ), +        'source_type': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"type"), +            'source_type__label__iexact' +        ), +        'reference': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"reference"), +            'reference__icontains' +        ), +        'internal_reference': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"internal-reference"), +            'internal_reference__icontains' +        ), +        'description': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"description"), +            'description__icontains' +        ), +        'comment': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"comment"), +            'comment__icontains' +        ), +        'additional_information': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"additional-information"), +            'additional_information__icontains' +        ), +        'duplicate': ( +            pgettext_lazy(TXT_SEARCH_COMMENT, u"has-duplicate"), +            'duplicate' +        ), +    } +    for v in ALT_NAMES.values(): +        EXTRA_REQUEST_KEYS[v[0]] = v[1] +      title = models.TextField(_(u"Title"), blank=True, default='')      associated_file = models.FileField(          upload_to=get_image_path, blank=True, null=True, max_length=255) | 
