Fix marker redefinition and improve display

This commit is contained in:
Gabriel Augendre 2019-03-02 15:37:18 +01:00
parent ed56def4ea
commit 3277a5292d
2 changed files with 19 additions and 4 deletions

View file

@ -13,7 +13,12 @@ class BaseModel(models.Model):
class Friend(AbstractUser): 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): class FriendLocation(BaseModel):
@ -32,5 +37,14 @@ class FriendLocation(BaseModel):
return str(self.longitude) return str(self.longitude)
def __str__(self): 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'<strong>{self.friend.get_display_name()}</strong>'
if self.start_date:
html += f' from {self.start_date}'
if self.end_date:
html += f' until {self.end_date}'
return html

View file

@ -21,9 +21,10 @@
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
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;
{% for location in locations %} {% for location in locations %}
let marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map); marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map);
marker.bindPopup("<strong>{{ location.friend.get_full_name }}</strong> from {{ location.start_date }} until {{ location.end_date }}"); marker.bindPopup("{{ location.safe_html|safe }}");
{% endfor %} {% endfor %}
</script> </script>
{% endblock %} {% endblock %}