summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-07 18:31:27 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-08-13 18:26:03 +0200
commit19130981f08faba30336fb57bdd78677753863c7 (patch)
tree13628f76c00eb4ca80a5902ae648da30ed1e4ccd
parentad6fd98f3416d9d9e2686d4607b2feae8ade5383 (diff)
downloadIshtar-19130981f08faba30336fb57bdd78677753863c7.tar.bz2
Ishtar-19130981f08faba30336fb57bdd78677753863c7.zip
Person: add a cached label with organization
-rw-r--r--archaeological_operations/models.py9
-rw-r--r--ishtar_common/migrations/0063_auto_20180807_1824.py25
-rw-r--r--ishtar_common/models.py24
3 files changed, 50 insertions, 8 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index b9e1d2e20..28bc4614a 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -127,6 +127,7 @@ class ArchaeologicalSite(BaseHistorizedItem):
_(u"Sinking date"), null=True, blank=True)
discovery_area = models.TextField(
_(u"Discovery area"), null=True, blank=True)
+
documents = models.ManyToManyField(
Document, related_name="sites", verbose_name=_(u"Documents"),
blank=True)
@@ -373,6 +374,10 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
pgettext_lazy(TXT_SEARCH_COMMENT, u"town"),
'towns__cached_label__iexact'
),
+ 'parcel': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"parcel"),
+ 'parcels__cached_label__iexact'
+ ),
'towns__numero_insee__startswith': (
pgettext_lazy(TXT_SEARCH_COMMENT, u"department"),
'towns__numero_insee__startswith'
@@ -393,6 +398,10 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
pgettext_lazy(TXT_SEARCH_COMMENT, u"is-open"),
'end_date__isnull'
),
+ 'in_charge': (
+ pgettext_lazy(TXT_SEARCH_COMMENT, u"in-charge"),
+ 'in_charge__cached_label__iexact'
+ ),
'periods': (
pgettext_lazy(TXT_SEARCH_COMMENT, u"period"),
'periods__pk'
diff --git a/ishtar_common/migrations/0063_auto_20180807_1824.py b/ishtar_common/migrations/0063_auto_20180807_1824.py
new file mode 100644
index 000000000..d39f5368f
--- /dev/null
+++ b/ishtar_common/migrations/0063_auto_20180807_1824.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-08-07 18:24
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0062_searchquery'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='historicalperson',
+ name='cached_label',
+ field=models.TextField(blank=True, db_index=True, null=True, verbose_name='Cached name'),
+ ),
+ migrations.AddField(
+ model_name='person',
+ 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 af63cb7c1..1aaa44b59 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2619,6 +2619,8 @@ class Person(Address, Merge, OwnPerms, ValueGetter):
attached_to = models.ForeignKey(
'Organization', related_name='members', on_delete=models.SET_NULL,
verbose_name=_(u"Is attached to"), blank=True, null=True)
+ cached_label = models.TextField(_(u"Cached name"), null=True, blank=True,
+ db_index=True)
history = HistoricalRecords()
class Meta:
@@ -2661,16 +2663,19 @@ class Person(Address, Merge, OwnPerms, ValueGetter):
return u" ".join(values)
def __unicode__(self):
- values = [unicode(getattr(self, attr)) for attr in ('surname', 'name')
- if getattr(self, attr)]
- if not values and self.raw_name:
- values = [self.raw_name]
+ if self.cached_label:
+ return self.cached_label
+ self.save()
+ return self.cached_label
+
+ def _generate_cached_label(self):
+ lbl = get_external_id('person_raw_name', self)
+ if not lbl:
+ return u"-"
if self.attached_to:
attached_to = unicode(self.attached_to)
- if values:
- values.append(u'-')
- values.append(attached_to)
- return u" ".join(values)
+ lbl += u" ({})".format(attached_to)
+ return lbl
def fancy_str(self):
values = ["<strong>"]
@@ -2829,6 +2834,9 @@ class Person(Address, Merge, OwnPerms, ValueGetter):
=user.ishtaruser)
+post_save.connect(cached_label_changed, sender=Person)
+
+
class ProfileType(GeneralType):
groups = models.ManyToManyField(Group, verbose_name=_(u"Groups"),
blank=True)