Display locations of relatives only

This commit is contained in:
Gabriel Augendre 2019-03-03 18:54:16 +01:00
parent 9103545a23
commit 218abab16f
3 changed files with 29 additions and 6 deletions

View file

@ -20,6 +20,24 @@ class Friend(AbstractUser):
return display_name return display_name
@property
def _relatives_set(self):
relative_set = set()
for group in self.location_sharing_groups.all():
for relative in group.friends.all():
relative_set.add(relative)
return relative_set
@property
def relatives(self):
return list(self._relatives_set)
@property
def relatives_with_self(self):
relatives = self._relatives_set
relatives.add(self)
return list(relatives)
class FriendLocation(BaseModel): class FriendLocation(BaseModel):
latitude = CoordinateField() latitude = CoordinateField()

View file

@ -24,9 +24,11 @@
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map); }).addTo(map);
let marker = null; let marker = null;
{% for location in locations %} {% for relative in friend.relatives_with_self %}
{% with relative.location as location %}
marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map); marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map);
marker.bindPopup("{{ location.safe_html|safe }}"); marker.bindPopup("{{ location.safe_html|safe }}");
{% endwith %}
{% endfor %} {% endfor %}
</script> </script>
{% endblock %} {% endblock %}

View file

@ -8,11 +8,14 @@ from map.forms import LocationForm
from map.mixins import QuickActionsMixin from map.mixins import QuickActionsMixin
class MapView(LoginRequiredMixin, QuickActionsMixin, generic.ListView): class MapView(LoginRequiredMixin, QuickActionsMixin, generic.DetailView):
model = models.FriendLocation model = models.Friend
context_object_name = 'locations' context_object_name = 'friend'
template_name = 'map/map.html' template_name = 'map/map.html'
def get_object(self, queryset=None):
return self.request.user
def get_quick_actions(self): def get_quick_actions(self):
if hasattr(self.request.user, 'location'): if hasattr(self.request.user, 'location'):
actions = [{ actions = [{