summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index a70399ba7..a03f9f387 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -93,7 +93,13 @@ from ishtar_common.utils import get_cache, disable_for_loaddata, create_slug, \
__all__ = [
'ImporterModel', 'ImporterType', 'ImporterDefault', 'ImporterDefaultValues',
'ImporterColumn', 'ImporterDuplicateField', 'Regexp', 'ImportTarget',
- 'TargetKey', 'FormaterType', 'Import', 'TargetKeyGroup', 'ValueFormater'
+ 'TargetKey', 'FormaterType', 'Import', 'TargetKeyGroup', 'ValueFormater',
+ 'Organization', 'Person', 'valid_id', 'Town', 'SpatialReferenceSystem',
+ 'OrganizationType', 'Document', 'GeneralType', 'get_external_id',
+ 'LightHistorizedItem', 'OwnPerms', 'Address', 'post_save_cache',
+ 'DashboardFormItem', 'ShortMenuItem', 'document_attached_changed',
+ 'SearchAltName', 'DynamicRequest', 'GeoItem', 'QRCodeItem',
+ 'SearchVectorConfig', 'DocumentItem'
]
logger = logging.getLogger(__name__)
@@ -3565,6 +3571,14 @@ class Area(HierarchicalType):
class Address(BaseHistorizedItem):
+ FIELDS = (
+ "address", "address_complement", "postal_code", "town",
+ "precise_town", "country",
+ "alt_address", "alt_address_complement", "alt_postal_code", "alt_town",
+ "alt_country",
+ "phone", "phone_desc", "phone2", "phone_desc2", "phone3", "phone_desc3",
+ "raw_phone", "mobile_phone", "email", "alt_address_is_prefered"
+ )
address = models.TextField(_("Address"), null=True, blank=True)
address_complement = models.TextField(_("Address complement"), null=True,
blank=True)
@@ -3605,6 +3619,7 @@ class Address(BaseHistorizedItem):
alt_address_is_prefered = models.BooleanField(
_("Alternative address is prefered"), default=False)
history = HistoricalRecords()
+ SUB_ADDRESSES = []
class Meta:
abstract = True
@@ -3612,10 +3627,47 @@ class Address(BaseHistorizedItem):
def get_town_centroid(self):
if self.precise_town:
return self.precise_town.center, self._meta.verbose_name
+ for sub_address in self.SUB_ADDRESSES:
+ sub_item = getattr(self, sub_address)
+ if sub_item and sub_item.precise_town:
+ return sub_item.precise_town.center, sub_item._meta.verbose_name
def get_town_polygons(self):
if self.precise_town:
return self.precise_town.limit, self._meta.verbose_name
+ for sub_address in self.SUB_ADDRESSES:
+ sub_item = getattr(self, sub_address)
+ if sub_item and sub_item.precise_town:
+ return sub_item.precise_town.limit, sub_item._meta.verbose_name
+
+ def get_attribute(self, attr):
+ if self.town or self.precise_town:
+ return getattr(self, attr)
+ for sub_address in self.SUB_ADDRESSES:
+ sub_item = getattr(self, sub_address)
+ if not sub_item:
+ continue
+ if sub_item.town or sub_item.precise_town:
+ return getattr(sub_item, attr)
+ return getattr(self, attr)
+
+ def get_address(self):
+ return self.get_attribute("address")
+
+ def get_address_complement(self):
+ return self.get_attribute("address_complement")
+
+ def get_postal_code(self):
+ return self.get_attribute("postal_code")
+
+ def get_town(self):
+ return self.get_attribute("town")
+
+ def get_precise_town(self):
+ return self.get_attribute("precise_town")
+
+ def get_country(self):
+ return self.get_attribute("country")
def simple_lbl(self):
return str(self)