Fix marker redefinition and improve display
This commit is contained in:
parent
ed56def4ea
commit
3277a5292d
2 changed files with 19 additions and 4 deletions
|
@ -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'<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
|
||||
|
||||
|
|
|
@ -21,9 +21,10 @@
|
|||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(map);
|
||||
let marker = null;
|
||||
{% for location in locations %}
|
||||
let 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 = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map);
|
||||
marker.bindPopup("{{ location.safe_html|safe }}");
|
||||
{% endfor %}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue