summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py47
1 files changed, 38 insertions, 9 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index bd18ab5d4..1378463a5 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2012-2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2012-2016 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -26,7 +26,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext, pgettext
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
HistoricalRecords, OwnPerms, ShortMenuItem, Source, GeneralRelationType,\
- GeneralRecordRelations, post_delete_record_relation
+ GeneralRecordRelations, post_delete_record_relation, get_external_id
from archaeological_operations.models import Operation, Period, Parcel
@@ -99,7 +99,7 @@ class IdentificationType(GeneralType):
class Meta:
verbose_name = _(u"Identification Type")
verbose_name_plural = _(u"Identification Types")
- ordering = ('order',)
+ ordering = ('order', 'label')
def __unicode__(self):
return self.label
@@ -112,12 +112,17 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):
'label', 'unit']
if settings.COUNTRY == 'fr':
TABLE_COLS.insert(1, 'operation.code_patriarche')
- TABLE_COLS_FOR_OPE = [
- 'label', ['parcel.section', 'parcel.parcel_number'], 'unit',
- 'datings.period', 'description']
+ TABLE_COLS_FOR_OPE = ['label', 'parcel', 'unit',
+ 'datings.period', 'description']
TABLE_COLS_FOR_OPE_LBL = {'section__parcel_number': _("Parcel")}
- external_id = models.CharField(_(u"External ID"), blank=True, null=True,
- max_length=120)
+ CONTEXTUAL_TABLE_COLS = {
+ 'full': {
+ 'related_context_records': 'detailled_related_context_records'
+ }
+ }
+ external_id = models.TextField(_(u"External ID"), blank=True, null=True)
+ auto_external_id = models.BooleanField(
+ _(u"External ID is set automatically"), default=False)
parcel = models.ForeignKey(Parcel, verbose_name=_(u"Parcel"),
related_name='context_record')
operation = models.ForeignKey(Operation, verbose_name=_(u"Operation"),
@@ -166,6 +171,8 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):
verbose_name=_(u"Activity"),)
related_context_records = models.ManyToManyField(
'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)
history = HistoricalRecords()
class Meta:
@@ -210,6 +217,7 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):
Q(history_creator=user)
def full_label(self):
+ return unicode(self)
if not self.operation:
return unicode(self)
return self._real_label() or self._temp_label()
@@ -280,10 +288,30 @@ class ContextRecord(BaseHistorizedItem, OwnPerms, ShortMenuItem):
q = q.filter(**fltr)
return q.count()
+ def detailled_related_context_records(self):
+ crs = []
+ for cr in self.right_relations.all():
+ crs.append(u"{} ({})".format(cr.right_record,
+ cr.relation_type.get_tiny_label()))
+ return u" ; ".join(crs)
+
def find_docs_q(self):
from archaeological_finds.models import FindSource
return FindSource.objects.filter(find__base_finds__context_record=self)
+ def save(self, *args, **kwargs):
+ returned = super(ContextRecord, self).save(*args, **kwargs)
+ updated = False
+ if not self.external_id or self.auto_external_id:
+ external_id = get_external_id('context_record_external_id', self)
+ if external_id != self.external_id:
+ updated = True
+ self.auto_external_id = True
+ self.external_id = external_id
+ if updated:
+ self.save()
+ return returned
+
class RelationType(GeneralRelationType):
inverse_relation = models.ForeignKey(
@@ -293,7 +321,7 @@ class RelationType(GeneralRelationType):
class Meta:
verbose_name = _(u"Relation type")
verbose_name_plural = _(u"Relation types")
- ordering = ('order',)
+ ordering = ('order', 'label')
class RecordRelations(GeneralRecordRelations, models.Model):
@@ -313,6 +341,7 @@ post_delete.connect(post_delete_record_relation, sender=RecordRelations)
class ContextRecordSource(Source):
SHOW_URL = 'show-contextrecordsource'
+ MODIFY_URL = 'record_source_modify'
class Meta:
verbose_name = _(u"Context record documentation")