diff --git a/map/forms.py b/map/forms.py index c3c9b22..b62b4ee 100644 --- a/map/forms.py +++ b/map/forms.py @@ -23,14 +23,10 @@ class LocationForm(forms.ModelForm): return self.request.user -class ProfileForm(forms.ModelForm): +class LocationSharingForm(forms.ModelForm): class Meta: model = Friend fields = [ - 'username', - 'first_name', - 'last_name', - 'email', 'shares_location_to', ] @@ -38,3 +34,4 @@ class ProfileForm(forms.ModelForm): super().__init__(*args, **kwargs) self.request = request self.fields['shares_location_to'].queryset = Friend.objects.exclude(pk=request.user.pk) + self.fields['shares_location_to'].label = 'Share location to' diff --git a/map/templates/map/base_change.html b/map/templates/map/base_change.html new file mode 100644 index 0000000..ff5bc51 --- /dev/null +++ b/map/templates/map/base_change.html @@ -0,0 +1,14 @@ +{% extends 'map/base.html' %} +{% load crispy_forms_filters %} + +{% block content %} + {% block notice %} + {% endblock %} +
+ {% csrf_token %} + {{ form|crispy }} + {% block form-buttons %} + + {% endblock %} +
+{% endblock %} diff --git a/map/templates/map/change_location.html b/map/templates/map/change_location.html index d3ea3fc..ed02ce6 100644 --- a/map/templates/map/change_location.html +++ b/map/templates/map/change_location.html @@ -1,10 +1,10 @@ -{% extends 'map/base.html' %} +{% extends 'map/base_change.html' %} {% load crispy_forms_filters %} {% block title %}Change your location{% endblock %} {% block h1 %}Change your location{% endblock %} -{% block content %} +{% block notice %}

Notice

@@ -20,9 +20,4 @@ you.
-
- {% csrf_token %} - {{ form|crispy }} - -
{% endblock %} diff --git a/map/templates/map/change_profile.html b/map/templates/map/change_profile.html index 33c4c81..0c5ac44 100644 --- a/map/templates/map/change_profile.html +++ b/map/templates/map/change_profile.html @@ -1,10 +1,10 @@ -{% extends 'map/base.html' %} +{% extends 'map/base_change.html' %} {% load crispy_forms_filters %} {% block title %}Change your profile{% endblock %} {% block h1 %}Change your profile{% endblock %} -{% block content %} +{% block notice %}

Notice

@@ -23,11 +23,9 @@ your data if you change your mind.
-
- {% csrf_token %} - {{ form|crispy }} - - Change your password - Permanently delete your profile -
+{% endblock %} + +{% block form-buttons %} + Change your password + Permanently delete your profile {% endblock %} diff --git a/map/templates/map/share_location.html b/map/templates/map/share_location.html new file mode 100644 index 0000000..82b80a0 --- /dev/null +++ b/map/templates/map/share_location.html @@ -0,0 +1,15 @@ +{% extends 'map/base_change.html' %} +{% load crispy_forms_filters %} + +{% block title %}Share your location{% endblock %} +{% block h1 %}Share your location{% endblock %} + +{% block notice %} +
+

Notice

+
+ Select here who you want to share your location to. + Only selected users will be able to see your marker on the map. +
+
+{% endblock %} diff --git a/map/urls.py b/map/urls.py index b28ea51..2bdfd4d 100644 --- a/map/urls.py +++ b/map/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ path('change-location', views.EditLocationView.as_view(), name='change-location'), path('add-location', views.AddLocationView.as_view(), name='add-location'), path('delete-location', views.DeleteLocationView.as_view(), name='delete-location'), + path('share-location', views.LocationSharingView.as_view(), name='share-location'), path('accounts/profile', views.UpdateProfileView.as_view(), name='change-profile'), path('accounts/profile/delete', views.DeleteProfileView.as_view(), name='delete-profile'), ] diff --git a/map/views.py b/map/views.py index 57ef3d1..4e2289d 100644 --- a/map/views.py +++ b/map/views.py @@ -4,7 +4,7 @@ from django.urls import reverse_lazy from django.views import generic from map import models -from map.forms import LocationForm, ProfileForm +from map.forms import LocationForm, LocationSharingForm from map.mixins import QuickActionsMixin @@ -34,14 +34,20 @@ class MapView(LoginRequiredMixin, QuickActionsMixin, generic.DetailView): 'display': f'Add your location' }] + actions.append({ + 'url': reverse_lazy('share-location'), + 'category': 'secondary', + 'display': 'Share your location' + }) + return actions -class EditLocationView(LoginRequiredMixin, generic.UpdateView): +class EditLocationView(LoginRequiredMixin, QuickActionsMixin, generic.UpdateView): model = models.FriendLocation context_object_name = 'location' template_name = 'map/change_location.html' - + success_url = reverse_lazy('map') fields = [ 'latitude', 'longitude', @@ -49,7 +55,12 @@ class EditLocationView(LoginRequiredMixin, generic.UpdateView): 'end_date', ] - success_url = reverse_lazy('map') + def get_quick_actions(self): + return [{ + 'url': reverse_lazy('map'), + 'category': 'secondary', + 'display': 'Back to map' + }] def get_object(self, queryset=None): return self.request.user.location @@ -59,12 +70,19 @@ class EditLocationView(LoginRequiredMixin, generic.UpdateView): return super().get_success_url() -class AddLocationView(LoginRequiredMixin, generic.CreateView): +class AddLocationView(LoginRequiredMixin, QuickActionsMixin, generic.CreateView): model = models.FriendLocation context_object_name = 'location' template_name = 'map/change_location.html' success_url = reverse_lazy('map') + def get_quick_actions(self): + return [{ + 'url': reverse_lazy('map'), + 'category': 'secondary', + 'display': 'Back to map' + }] + def get_initial(self): initial = super().get_initial() initial = initial.copy() @@ -93,14 +111,24 @@ class DeleteLocationView(LoginRequiredMixin, generic.DeleteView): return super().get_success_url() -class UpdateProfileView(LoginRequiredMixin, generic.UpdateView): +class UpdateProfileView(LoginRequiredMixin, QuickActionsMixin, generic.UpdateView): model = models.Friend context_object_name = 'friend' template_name = 'map/change_profile.html' success_url = reverse_lazy('map') + fields = [ + 'username', + 'first_name', + 'last_name', + 'email', + ] - def get_form(self, form_class=None): - return ProfileForm(self.request, **self.get_form_kwargs()) + def get_quick_actions(self): + return [{ + 'url': reverse_lazy('map'), + 'category': 'secondary', + 'display': 'Back to map' + }] def get_object(self, queryset=None): return self.request.user @@ -110,6 +138,26 @@ class UpdateProfileView(LoginRequiredMixin, generic.UpdateView): return super().get_success_url() +class LocationSharingView(LoginRequiredMixin, QuickActionsMixin, generic.UpdateView): + model = models.Friend + context_object_name = 'friend' + template_name = 'map/share_location.html' + success_url = reverse_lazy('map') + + def get_quick_actions(self): + return [{ + 'url': reverse_lazy('map'), + 'category': 'secondary', + 'display': 'Back to map' + }] + + def get_object(self, queryset=None): + return self.request.user + + def get_form(self, form_class=None): + return LocationSharingForm(self.request, **self.get_form_kwargs()) + + class DeleteProfileView(LoginRequiredMixin, generic.DeleteView): model = models.Friend context_object_name = 'friend'