diff --git a/map/models.py b/map/models.py
index bc4e6e7..48a157d 100644
--- a/map/models.py
+++ b/map/models.py
@@ -13,7 +13,12 @@ class BaseModel(models.Model):
class Friend(AbstractUser):
- pass
+ def get_display_name(self):
+ display_name = super().get_full_name()
+ if not display_name:
+ display_name = self.username
+
+ return display_name
class FriendLocation(BaseModel):
@@ -32,5 +37,14 @@ class FriendLocation(BaseModel):
return str(self.longitude)
def __str__(self):
- return f'{self.friend.get_full_name()} from {self.start_date} to {self.end_date}'
+ return f'{self.friend.get_display_name()} from {self.start_date} to {self.end_date}'
+
+ @property
+ def safe_html(self):
+ html = f'{self.friend.get_display_name()}'
+ if self.start_date:
+ html += f' from {self.start_date}'
+ if self.end_date:
+ html += f' until {self.end_date}'
+ return html
diff --git a/map/templates/map/map.html b/map/templates/map/map.html
index 3adeb67..5cf3ec7 100644
--- a/map/templates/map/map.html
+++ b/map/templates/map/map.html
@@ -21,9 +21,10 @@
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
+ let marker = null;
{% for location in locations %}
- let marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map);
- marker.bindPopup("{{ location.friend.get_full_name }} from {{ location.start_date }} until {{ location.end_date }}");
+ marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map);
+ marker.bindPopup("{{ location.safe_html|safe }}");
{% endfor %}
{% endblock %}