diff options
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r-- | archaeological_context_records/models.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index a98f7792a..0123dd2ed 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -21,9 +21,11 @@ from django.conf import settings from django.contrib.gis.db import models from django.core.urlresolvers import reverse from django.db.models import Q -from django.db.models.signals import post_delete +from django.db.models.signals import post_delete, post_save from django.utils.translation import ugettext_lazy as _, ugettext, pgettext +from ishtar_common.utils import cached_label_changed + from ishtar_common.models import GeneralType, BaseHistorizedItem, \ HistoricalRecords, OwnPerms, ShortMenuItem, Source, GeneralRelationType,\ GeneralRecordRelations, post_delete_record_relation, get_external_id, \ @@ -108,6 +110,7 @@ class IdentificationType(GeneralType): class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): SHOW_URL = 'show-contextrecord' + SLUG = 'contextrecord' TABLE_COLS = ['parcel.town', 'operation.year', 'operation.operation_code', 'label', 'unit'] @@ -177,6 +180,7 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): 'ContextRecord', through='RecordRelations', blank=True, null=True) point = models.PointField(_(u"Point"), blank=True, null=True, dim=3) polygon = models.PolygonField(_(u"Polygon"), blank=True, null=True) + cached_label = models.TextField(_(u"Cached name"), null=True, blank=True) history = HistoricalRecords() class Meta: @@ -193,6 +197,7 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): ("delete_own_contextrecord", ugettext(u"Can delete own Context Record")), ) + ordering = ('cached_label',) @property def name(self): @@ -220,11 +225,17 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): Q(operation__in_charge=user.ishtaruser.person) |\ Q(history_creator=user) + @classmethod + def get_owns(cls, user, menu_filtr=None): + replace_query = {} + if menu_filtr: + replace_query = {'operation': menu_filtr} + owns = super(ContextRecord, cls).get_owns(user, + replace_query=replace_query) + return sorted(owns, key=lambda x: x.cached_label) + def full_label(self): return unicode(self) - if not self.operation: - return unicode(self) - return self._real_label() or self._temp_label() def _real_label(self): if not self.operation.code_patriarche: @@ -239,6 +250,9 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): self.operation.year, self.operation.operation_code, self.label] if lbl]) + def _generate_cached_label(self): + return self.full_label() + @property def reference(self): if not self.operation: @@ -317,6 +331,9 @@ class ContextRecord(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): return returned +post_save.connect(cached_label_changed, sender=ContextRecord) + + class RelationType(GeneralRelationType): inverse_relation = models.ForeignKey( 'RelationType', verbose_name=_(u"Inverse relation"), blank=True, |