|
@@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|
|
from django.db import models
|
|
|
|
|
|
from .fields import CommaSeparatedCharField
|
|
|
+from .utils import ANGLES, merge_intervals
|
|
|
|
|
|
|
|
|
class Contrib(models.Model):
|
|
@@ -109,12 +110,29 @@ class Contrib(models.Model):
|
|
|
'floor_total': 'privacy_place_details',
|
|
|
'orientations': 'privacy_place_details',
|
|
|
'roof': 'privacy_place_details',
|
|
|
+ 'angles': 'privacy_place_details',
|
|
|
}
|
|
|
+
|
|
|
PUBLIC_FIELDS = set(PRIVACY_MAP.keys())
|
|
|
|
|
|
def __str__(self):
|
|
|
return '#{} {}'.format(self.pk, self.name)
|
|
|
|
|
|
+ def angles(self):
|
|
|
+ """Return a list of (start, stop) angles from cardinal orientations
|
|
|
+ """
|
|
|
+ # Cleanup
|
|
|
+ if self.orientations is None:
|
|
|
+ return []
|
|
|
+ orientations = [o for o in self.orientations if o in ANGLES.keys()]
|
|
|
+ # Hack to make leaflet-semicircle happy (drawing a full circle only
|
|
|
+ # works with (0, 360))
|
|
|
+ if len(orientations) == 8:
|
|
|
+ return [[0, 360]]
|
|
|
+ angles = [ANGLES[orientation] for orientation in self.orientations]
|
|
|
+ angles.sort(key=lambda i: i[0]) # sort by x
|
|
|
+ return merge_intervals(angles)
|
|
|
+
|
|
|
def is_public(self):
|
|
|
return not self.privacy_coordinates
|
|
|
|
|
@@ -131,6 +149,11 @@ class Contrib(models.Model):
|
|
|
:return: the field value, or None, if the field is private
|
|
|
"""
|
|
|
if self._may_be_public(field) and self._is_public(field):
|
|
|
- return getattr(self, field)
|
|
|
+ v = getattr(self, field)
|
|
|
+ if hasattr(v, '__call__'):
|
|
|
+ return v()
|
|
|
+ else:
|
|
|
+ return v
|
|
|
+
|
|
|
else:
|
|
|
return None
|