diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-14 16:57:48 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-14 16:57:48 +0200 |
commit | d50d5077f9bf5eb6733de1a4a29d3ef1089cdd96 (patch) | |
tree | 8ccbb16c38a59cf640b490e1d1f5e4b40fa3abe6 /ishtar_common | |
parent | 10086eb832b17b596ce8db07efd910d353cce514 (diff) | |
download | Ishtar-d50d5077f9bf5eb6733de1a4a29d3ef1089cdd96.tar.bz2 Ishtar-d50d5077f9bf5eb6733de1a4a29d3ef1089cdd96.zip |
Container - warehouse form configuration - cache precise localisation
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms_common.py | 4 | ||||
-rw-r--r-- | ishtar_common/migrations/0065_author_cached_label.py | 20 | ||||
-rw-r--r-- | ishtar_common/models.py | 54 |
3 files changed, 76 insertions, 2 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index e6f37a794..3745d5f73 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1183,7 +1183,9 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): return item -class DocumentSelect(TableSelect): +class DocumentSelect(TableSelect): # OK + _model = models.Document + search_vector = forms.CharField( label=_(u"Full text search"), widget=widgets.SearchWidget( 'ishtar-common', 'document' diff --git a/ishtar_common/migrations/0065_author_cached_label.py b/ishtar_common/migrations/0065_author_cached_label.py new file mode 100644 index 000000000..adaaed9fa --- /dev/null +++ b/ishtar_common/migrations/0065_author_cached_label.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-14 15:53 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0064_auto_20180808_1116'), + ] + + operations = [ + migrations.AddField( + model_name='author', + name='cached_label', + field=models.TextField(blank=True, db_index=True, null=True, verbose_name='Cached name'), + ), + ] 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) |