diff options
Diffstat (limited to 'archaeological_warehouse/models.py')
| -rw-r--r-- | archaeological_warehouse/models.py | 30 | 
1 files changed, 25 insertions, 5 deletions
| diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index c80b4476b..795c879e4 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -31,8 +31,8 @@ from ishtar_common.data_importer import post_importer_action  from ishtar_common.models import Document, GeneralType, get_external_id, \      LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \      DashboardFormItem, ExternalIdManager, ShortMenuItem, \ -    document_attached_changed, SearchAltName, DynamicRequest -from ishtar_common.utils import cached_label_changed +    document_attached_changed, SearchAltName, DynamicRequest, GeoItem +from ishtar_common.utils import cached_label_changed, post_save_geo  class WarehouseType(GeneralType): @@ -46,7 +46,7 @@ post_save.connect(post_save_cache, sender=WarehouseType)  post_delete.connect(post_save_cache, sender=WarehouseType) -class Warehouse(Address, DashboardFormItem, OwnPerms, +class Warehouse(Address, GeoItem, DashboardFormItem, OwnPerms,                  ShortMenuItem):      SLUG = 'warehouse'      SHOW_URL = 'show-warehouse' @@ -69,6 +69,7 @@ class Warehouse(Address, DashboardFormItem, OwnPerms,              'warehouse_type__label__iexact'          ),      } +    GEO_LABEL = "name"      objects = ExternalIdManager() @@ -258,6 +259,8 @@ class Warehouse(Address, DashboardFormItem, OwnPerms,  m2m_changed.connect(document_attached_changed,                      sender=Warehouse.documents.through) +post_save.connect(post_save_geo, sender=Warehouse) +  class Collection(LightHistorizedItem):      name = models.CharField(_(u"Name"), max_length=200, @@ -319,7 +322,7 @@ post_save.connect(post_save_cache, sender=ContainerType)  post_delete.connect(post_save_cache, sender=ContainerType) -class Container(LightHistorizedItem, OwnPerms): +class Container(LightHistorizedItem, GeoItem, OwnPerms):      SLUG = 'container'      SHOW_URL = 'show-container'      TABLE_COLS = ['reference', 'container_type__label', 'cached_location', @@ -350,6 +353,7 @@ class Container(LightHistorizedItem, OwnPerms):          'cached_division': _(u"Precise localisation"),          'container_type__label': _(u"Type")      } +    GEO_LABEL = "cached_label"      CACHED_LABELS = ['cached_division', 'cached_label', 'cached_location', ]      # alternative names of fields for searches @@ -555,6 +559,18 @@ class Container(LightHistorizedItem, OwnPerms):              Q(location__person_in_charge__ishtaruser=ishtaruser) | \              Q(responsible__person_in_charge__ishtaruser=ishtaruser) +    def get_precise_points(self): +        precise_points = super(Container, self).get_precise_points() +        if precise_points: +            return precise_points +        return self.location.get_precise_points() + +    def get_town_centroid(self): +        return self.location.get_town_centroid() + +    def get_town_polygons(self): +        return self.location.get_town_polygons() +      @property      def associated_filename(self):          filename = datetime.date.today().strftime('%Y-%m-%d') @@ -747,8 +763,12 @@ class Container(LightHistorizedItem, OwnPerms):              loca.delete() -post_save.connect(cached_label_changed, sender=Container) +def container_post_save(sender, **kwargs): +    cached_label_changed(sender=sender, **kwargs) +    post_save_geo(sender=sender, **kwargs) + +post_save.connect(container_post_save, sender=Container)  m2m_changed.connect(document_attached_changed,                      sender=Container.documents.through) | 
