diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-22 16:44:40 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:38:56 +0200 | 
| commit | 2af3c31880b78d1b0110a168a9809c2c48111e40 (patch) | |
| tree | 5b24e0c2251385e2237c5fed80d7354dceba2943 /archaeological_operations/models.py | |
| parent | 81a1008c26d0cc7cfdcbea14464746a7106d0e85 (diff) | |
| download | Ishtar-2af3c31880b78d1b0110a168a9809c2c48111e40.tar.bz2 Ishtar-2af3c31880b78d1b0110a168a9809c2c48111e40.zip | |
Manage X, Y, Z fields for context records, operations and sites
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 60 | 
1 files changed, 55 insertions, 5 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 7bb27ab6c..a8f1d4faf 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -22,6 +22,8 @@ from itertools import groupby  from django.conf import settings  from django.contrib.gis.db import models +from django.contrib.gis.db.models.aggregates import Union +from django.contrib.gis.db.models.functions import Centroid  from django.core.urlresolvers import reverse  from django.db import IntegrityError, transaction  from django.db.models import Q, Count, Sum, Max, Avg @@ -36,9 +38,10 @@ from ishtar_common.models import BaseHistorizedItem, Dashboard, \      OperationType, Organization, OwnPerms, Person, PersonType, \      post_delete_record_relation, post_save_cache, RelationItem, \      ShortMenuItem, SourceType, Town, ValueGetter, get_current_profile, \ -    document_attached_changed, HistoryModel, SearchAltName +    document_attached_changed, HistoryModel, SearchAltName, \ +    SpatialReferenceSystem  from ishtar_common.utils import cached_label_changed, \ -    force_cached_label_changed, mode, m2m_historization_changed +    force_cached_label_changed, mode, m2m_historization_changed, post_save_point  class RemainType(GeneralType): @@ -260,7 +263,20 @@ class ArchaeologicalSite(BaseHistorizedItem, OwnPerms, ValueGetter,                                       null=True, blank=True)      # gis -    point = models.PointField(_(u"Point"), blank=True, null=True) +    x = models.FloatField(_(u'X'), blank=True, null=True) +    y = models.FloatField(_(u'Y'), blank=True, null=True) +    z = models.FloatField(_(u'Z'), blank=True, null=True) +    estimated_error_x = models.FloatField(_(u'Estimated error for X'), +                                          blank=True, null=True) +    estimated_error_y = models.FloatField(_(u'Estimated error for Y'), +                                          blank=True, null=True) +    estimated_error_z = models.FloatField(_(u'Estimated error for Z'), +                                          blank=True, null=True) +    spatial_reference_system = models.ForeignKey( +        SpatialReferenceSystem, verbose_name=_(u"Spatial Reference System"), +        blank=True, null=True) +    point = models.PointField(_(u"Point"), blank=True, null=True, dim=3) +    point_2d = models.PointField(_(u"Point (2D)"), blank=True, null=True)      multi_polygon = models.MultiPolygonField(_(u"Multi polygon"), blank=True,                                               null=True) @@ -369,6 +385,13 @@ class ArchaeologicalSite(BaseHistorizedItem, OwnPerms, ValueGetter,      def towns_label(self):          return u" - ".join(self.towns_codes()) +    def get_town_centroid(self): +        q = self.towns.filter(center__isnull=False).annotate( +                centroid=Centroid(Union('center'))).all() +        if not q.count(): +            return None +        return q.all()[0].centroid +      def _get_base_image_path(self):          return u"{}/{}".format(self.SLUG, self.reference) @@ -422,7 +445,12 @@ class ArchaeologicalSite(BaseHistorizedItem, OwnPerms, ValueGetter,              ) -post_save.connect(cached_label_changed, sender=ArchaeologicalSite) +def site_post_save(sender, **kwargs): +    cached_label_changed(sender=sender, **kwargs) +    post_save_point(sender=sender, **kwargs) + + +post_save.connect(site_post_save, sender=ArchaeologicalSite)  m2m_changed.connect(document_attached_changed,                      sender=ArchaeologicalSite.documents.through) @@ -898,7 +926,20 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,                                                 blank=True, null=True)      # gis -    point = models.PointField(_(u"Point"), blank=True, null=True) +    x = models.FloatField(_(u'X'), blank=True, null=True) +    y = models.FloatField(_(u'Y'), blank=True, null=True) +    z = models.FloatField(_(u'Z'), blank=True, null=True) +    estimated_error_x = models.FloatField(_(u'Estimated error for X'), +                                          blank=True, null=True) +    estimated_error_y = models.FloatField(_(u'Estimated error for Y'), +                                          blank=True, null=True) +    estimated_error_z = models.FloatField(_(u'Estimated error for Z'), +                                          blank=True, null=True) +    spatial_reference_system = models.ForeignKey( +        SpatialReferenceSystem, verbose_name=_(u"Spatial Reference System"), +        blank=True, null=True) +    point = models.PointField(_(u"Point"), blank=True, null=True, dim=3) +    point_2d = models.PointField(_(u"Point (2D)"), blank=True, null=True)      multi_polygon = models.MultiPolygonField(_(u"Multi polygon"), blank=True,                                               null=True)      history = HistoricalRecords(bases=[HistoryModel]) @@ -1067,6 +1108,13 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,      def render_parcels(self):          return Parcel.render_parcels(list(self.parcels.all())) +    def get_town_centroid(self): +        q = self.towns.filter(center__isnull=False).annotate( +            centroid=Centroid(Union('center'))).all() +        if not q.count(): +            return None +        return q.all()[0].centroid +      def context_record_relations_q(self):          from archaeological_context_records.models \              import RecordRelations as CRRL @@ -1416,6 +1464,8 @@ for attr in Operation.HISTORICAL_M2M:  def operation_post_save(sender, **kwargs):      if not kwargs['instance']:          return +    post_save_point(sender=sender, **kwargs) +      operation = kwargs['instance']      operation.skip_history_when_saving = True      if operation.fnap_financing and operation.cost: | 
