Display locations of relatives only
This commit is contained in:
parent
9103545a23
commit
218abab16f
3 changed files with 29 additions and 6 deletions
|
@ -20,6 +20,24 @@ class Friend(AbstractUser):
|
|||
|
||||
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):
|
||||
latitude = CoordinateField()
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(map);
|
||||
let marker = null;
|
||||
{% for location in locations %}
|
||||
marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map);
|
||||
marker.bindPopup("{{ location.safe_html|safe }}");
|
||||
{% for relative in friend.relatives_with_self %}
|
||||
{% with relative.location as location %}
|
||||
marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map);
|
||||
marker.bindPopup("{{ location.safe_html|safe }}");
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -8,11 +8,14 @@ from map.forms import LocationForm
|
|||
from map.mixins import QuickActionsMixin
|
||||
|
||||
|
||||
class MapView(LoginRequiredMixin, QuickActionsMixin, generic.ListView):
|
||||
model = models.FriendLocation
|
||||
context_object_name = 'locations'
|
||||
class MapView(LoginRequiredMixin, QuickActionsMixin, generic.DetailView):
|
||||
model = models.Friend
|
||||
context_object_name = 'friend'
|
||||
template_name = 'map/map.html'
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.request.user
|
||||
|
||||
def get_quick_actions(self):
|
||||
if hasattr(self.request.user, 'location'):
|
||||
actions = [{
|
||||
|
|
Loading…
Reference in a new issue