diff --git a/map/templates/map/change_location.html b/map/templates/map/change_location.html
new file mode 100644
index 0000000..6aa080f
--- /dev/null
+++ b/map/templates/map/change_location.html
@@ -0,0 +1,12 @@
+{% extends 'map/base.html' %}
+{% load crispy_forms_filters %}
+
+{% block h1 %}Change your location{% endblock %}
+
+{% block content %}
+
+{% endblock %}
diff --git a/map/urls.py b/map/urls.py
index 8cf724b..1b91adf 100644
--- a/map/urls.py
+++ b/map/urls.py
@@ -1,6 +1,8 @@
from django.urls import path
+
from map import views
urlpatterns = [
path('', views.MapView.as_view(), name='map'),
+ path('change-location/', views.EditLocationView.as_view(), name='change-location'),
]
diff --git a/map/views.py b/map/views.py
index 407a483..466654a 100644
--- a/map/views.py
+++ b/map/views.py
@@ -1,10 +1,46 @@
+from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
-from django.views.generic import ListView
+from django.shortcuts import redirect
+from django.urls import reverse_lazy
+from django.views import generic
from map import models
+from map.mixins import QuickActionsMixin
-class MapView(LoginRequiredMixin, ListView):
+class MapView(LoginRequiredMixin, QuickActionsMixin, generic.ListView):
model = models.FriendLocation
context_object_name = 'locations'
template_name = 'map/map.html'
+
+ def get_quick_actions(self):
+ return [
+ {
+ 'url': reverse_lazy('change-location', kwargs={'pk': self.request.user.location.pk}),
+ 'category': 'secondary',
+ 'display': f'Change your location'
+ },
+ ]
+
+
+class EditLocationView(LoginRequiredMixin, generic.UpdateView):
+ model = models.FriendLocation
+ context_object_name = 'location'
+ template_name = 'map/change_location.html'
+
+ fields = [
+ 'latitude',
+ 'longitude',
+ 'start_date',
+ 'end_date',
+ ]
+
+ success_url = reverse_lazy('map')
+
+ def dispatch(self, request, *args, **kwargs):
+ obj = self.get_object() # type: models.FriendLocation
+ if obj is None or obj.friend != request.user:
+ messages.warning(request, "This is not your location.")
+ return redirect('map')
+
+ return super().dispatch(request, *args, **kwargs)