mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
refactor: add map marker to context on update
This commit is contained in:
@@ -2,27 +2,12 @@
|
|||||||
|
|
||||||
{% block extra_head %}
|
{% block extra_head %}
|
||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
<script type="application/javascript">
|
{{ map_markers|json_script:'map-markers' }}
|
||||||
const data = [
|
|
||||||
{
|
|
||||||
name: '{{ organisation.name }}',
|
|
||||||
lat: '{{ organisation.latitude }}',
|
|
||||||
lng: '{{ organisation.longitude }}'
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const settings = {
|
|
||||||
zoom: 2,
|
|
||||||
centre_lat: '{{ organisation.latitude }}',
|
|
||||||
centre_lng: '{{ organisation.longitude }}',
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- {{ map_markers|json_script:'map-markers' }} -->
|
|
||||||
|
|
||||||
|
<script src="{% static 'js/map.js' %}"></script>
|
||||||
<script src="{% static 'js/location_picker.js' %}"></script>
|
<script src="{% static 'js/location_picker.js' %}"></script>
|
||||||
|
|
||||||
<script async defer src="https://maps.googleapis.com/maps/api/js?key={{ settings.GOOGLE_MAPS_API_KEY }}&callback=initMap&libraries=places"
|
<script async defer src="https://maps.googleapis.com/maps/api/js?key={{ settings.GOOGLE_MAPS_API_KEY }}&callback=initPicker&libraries=places"
|
||||||
type="text/javascript"></script>
|
type="text/javascript"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -2,25 +2,12 @@
|
|||||||
|
|
||||||
{% block extra_head %}
|
{% block extra_head %}
|
||||||
{% load staticfiles %}
|
{% load staticfiles %}
|
||||||
<script type="application/javascript">
|
{{ map_markers|json_script:'map-markers' }}
|
||||||
const data = [
|
|
||||||
{
|
|
||||||
name: '{{ person.name }}',
|
|
||||||
lat: '{{ answer_set.latitude }}',
|
|
||||||
lng: '{{ answer_set.longitude }}'
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const settings = {
|
|
||||||
zoom: 2,
|
|
||||||
centre_lat: '{{ answer_set.latitude }}',
|
|
||||||
centre_lng: '{{ answer_set.longitude }}',
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
<script src="{% static 'js/map.js' %}"></script>
|
||||||
<script src="{% static 'js/location_picker.js' %}"></script>
|
<script src="{% static 'js/location_picker.js' %}"></script>
|
||||||
|
|
||||||
<script async defer src="https://maps.googleapis.com/maps/api/js?key={{ settings.GOOGLE_MAPS_API_KEY }}&callback=initMap&libraries=places"
|
<script async defer src="https://maps.googleapis.com/maps/api/js?key={{ settings.GOOGLE_MAPS_API_KEY }}&callback=initPicker&libraries=places"
|
||||||
type="text/javascript"></script>
|
type="text/javascript"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@@ -45,3 +45,16 @@ class OrganisationUpdateView(LoginRequiredMixin, UpdateView):
|
|||||||
context_object_name = 'organisation'
|
context_object_name = 'organisation'
|
||||||
template_name = 'people/organisation/update.html'
|
template_name = 'people/organisation/update.html'
|
||||||
form_class = forms.OrganisationForm
|
form_class = forms.OrganisationForm
|
||||||
|
|
||||||
|
def get_context_data(self,
|
||||||
|
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||||
|
"""Add map marker to context."""
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
context['map_markers'] = [{
|
||||||
|
'name': self.object.name,
|
||||||
|
'lat': self.object.latitude,
|
||||||
|
'lng': self.object.longitude,
|
||||||
|
}]
|
||||||
|
|
||||||
|
return context
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ class ProfileView(permissions.UserIsLinkedPersonMixin, DetailView):
|
|||||||
# pk was not provided in URL
|
# pk was not provided in URL
|
||||||
return self.request.user.person
|
return self.request.user.person
|
||||||
|
|
||||||
def get_context_data(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
def get_context_data(self,
|
||||||
|
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||||
"""Add current :class:`PersonAnswerSet` to context."""
|
"""Add current :class:`PersonAnswerSet` to context."""
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
@@ -74,6 +75,14 @@ class PersonUpdateView(permissions.UserIsLinkedPersonMixin, UpdateView):
|
|||||||
template_name = 'people/person/update.html'
|
template_name = 'people/person/update.html'
|
||||||
form_class = forms.PersonAnswerSetForm
|
form_class = forms.PersonAnswerSetForm
|
||||||
|
|
||||||
|
def get_context_data(self,
|
||||||
|
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
|
context['map_markers'] = [get_map_data(self.object)]
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
def get_initial(self) -> typing.Dict[str, typing.Any]:
|
def get_initial(self) -> typing.Dict[str, typing.Any]:
|
||||||
return {
|
return {
|
||||||
'person_id': self.object.id,
|
'person_id': self.object.id,
|
||||||
@@ -129,7 +138,8 @@ class PersonMapView(LoginRequiredMixin, ListView):
|
|||||||
model = models.Person
|
model = models.Person
|
||||||
template_name = 'people/person/map.html'
|
template_name = 'people/person/map.html'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
def get_context_data(self,
|
||||||
|
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
context['map_markers'] = [
|
context['map_markers'] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user