diff --git a/map/admin.py b/map/admin.py index 29f7bea..070662a 100644 --- a/map/admin.py +++ b/map/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin from django.contrib.admin import register from django.contrib.auth.admin import UserAdmin -from .models import Friend, FriendLocation, LocationSharingGroup +from .models import Friend, FriendLocation admin.site.register(Friend, UserAdmin) @@ -14,10 +14,3 @@ class FriendLocationAdmin(admin.ModelAdmin): ('Place', {'fields': ('latitude', 'longitude')}), ('Dates', {'fields': ('start_date', 'end_date')}), ] - - -@register(LocationSharingGroup) -class LocationSharingGroupAdmin(admin.ModelAdmin): - list_display = [ - 'name', - ] diff --git a/map/migrations/0009_auto_20190303_1943.py b/map/migrations/0009_auto_20190303_1943.py new file mode 100644 index 0000000..33da9d8 --- /dev/null +++ b/map/migrations/0009_auto_20190303_1943.py @@ -0,0 +1,26 @@ +# Generated by Django 2.1.7 on 2019-03-03 18:43 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('map', '0008_auto_20190303_1834'), + ] + + operations = [ + migrations.RemoveField( + model_name='locationsharinggroup', + name='friends', + ), + migrations.AddField( + model_name='friend', + name='shares_location_to', + field=models.ManyToManyField(related_name='is_shared_location_by', to=settings.AUTH_USER_MODEL), + ), + migrations.DeleteModel( + name='LocationSharingGroup', + ), + ] diff --git a/map/models.py b/map/models.py index 54037ae..1ee939c 100644 --- a/map/models.py +++ b/map/models.py @@ -13,6 +13,8 @@ class BaseModel(models.Model): class Friend(AbstractUser): + shares_location_to = models.ManyToManyField('Friend', related_name='is_shared_location_by') + def get_display_name(self): display_name = super().get_full_name() if not display_name: @@ -20,24 +22,6 @@ class Friend(AbstractUser): return display_name - @property - def _relatives_set(self): - relative_set = set() - for group in self.location_sharing_groups.all(): - for relative in group.friends.all(): - relative_set.add(relative) - return relative_set - - @property - def relatives(self): - return list(self._relatives_set) - - @property - def relatives_with_self(self): - relatives = self._relatives_set - relatives.add(self) - return list(relatives) - class FriendLocation(BaseModel): latitude = CoordinateField() @@ -70,9 +54,3 @@ class FriendLocation(BaseModel): if self.end_date: html += f' until {self.end_date}' return html - - -class LocationSharingGroup(models.Model): - name = models.CharField(max_length=250) - friends = models.ManyToManyField(Friend, related_name='location_sharing_groups', blank=True) - diff --git a/map/templates/map/change_group.html b/map/templates/map/change_group.html deleted file mode 100644 index 60e39f0..0000000 --- a/map/templates/map/change_group.html +++ /dev/null @@ -1,19 +0,0 @@ -{% extends 'map/base.html' %} -{% load crispy_forms_filters %} - -{% block title %}Create a group{% endblock %} -{% block h1 %}Create a group{% endblock %} - -{% block content %} -
-

Notice

-
- All members in this group can see your location. -
-
-
- {% csrf_token %} - {{ form|crispy }} - -
-{% endblock %} diff --git a/map/templates/map/leave_group.html b/map/templates/map/leave_group.html deleted file mode 100644 index 24ddfea..0000000 --- a/map/templates/map/leave_group.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'map/base.html' %} -{% load crispy_forms_filters %} - -{% block title %}Leave a group{% endblock %} -{% block h1 %}Leave a group{% endblock %} - -{% block content %} -
-

Are you sure?

-
- If you leave this group you will not be able to see the location of people in the group. - If you're the last member of the group, it will be deleted. -
-
-
- {% csrf_token %} - - No, cancel -
-{% endblock %} diff --git a/map/templates/map/list_groups.html b/map/templates/map/list_groups.html deleted file mode 100644 index cea13d5..0000000 --- a/map/templates/map/list_groups.html +++ /dev/null @@ -1,27 +0,0 @@ -{% extends 'map/base.html' %} -{% load crispy_forms_filters %} - -{% block title %}Manage your groups{% endblock %} -{% block h1 %}Manage your groups{% endblock %} - -{% block content %} -
-

Notice

-
- Here you can list and manage groups you belong to. All members in these groups can see your location. -
-
- - - -{% endblock %} diff --git a/map/templates/map/map.html b/map/templates/map/map.html index e939842..258f421 100644 --- a/map/templates/map/map.html +++ b/map/templates/map/map.html @@ -24,11 +24,15 @@ attribution: '© OpenStreetMap contributors' }).addTo(map); let marker = null; - {% for relative in friend.relatives_with_self %} + {% for relative in friend.is_shared_location_by.all %} {% with relative.location as location %} marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map); marker.bindPopup("{{ location.safe_html|safe }}"); {% endwith %} {% endfor %} + {% with friend.location as location %} + marker = L.marker([{{ location.latitude_str }}, {{ location.longitude_str }}]).addTo(map); + marker.bindPopup("{{ location.safe_html|safe }}"); + {% endwith %} {% endblock %} diff --git a/map/urls.py b/map/urls.py index 845184d..b28ea51 100644 --- a/map/urls.py +++ b/map/urls.py @@ -7,9 +7,6 @@ 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('manage-groups', views.ManageGroupsView.as_view(), name='manage-groups'), - path('add-group', views.CreateGroupView.as_view(), name='add-group'), - path('leave-group/', views.LeaveGroupView.as_view(), name='leave-group'), 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 ccf731b..f05463a 100644 --- a/map/views.py +++ b/map/views.py @@ -34,12 +34,6 @@ class MapView(LoginRequiredMixin, QuickActionsMixin, generic.DetailView): 'display': f'Add your location' }] - actions.append({ - 'url': reverse_lazy('manage-groups'), - 'category': 'secondary', - 'display': f'Manage your groups' - }) - return actions @@ -132,50 +126,3 @@ class DeleteProfileView(LoginRequiredMixin, generic.DeleteView): def get_success_url(self): messages.success(self.request, 'Your profile has been successfully and permanently deleted') return super().get_success_url() - - -class ManageGroupsView(LoginRequiredMixin, QuickActionsMixin, generic.ListView): - model = models.LocationSharingGroup - context_object_name = 'groups' - template_name = 'map/list_groups.html' - - def get_queryset(self): - return self.request.user.location_sharing_groups.all() - - def get_quick_actions(self): - return [{ - 'url': reverse_lazy('add-group'), - 'category': 'primary', - 'display': 'Create a group' - }] - - -class CreateGroupView(LoginRequiredMixin, QuickActionsMixin, generic.CreateView): - model = models.LocationSharingGroup - context_object_name = 'group' - template_name = 'map/change_group.html' - success_url = reverse_lazy('manage-groups') - - fields = [ - 'name' - ] - - def get_success_url(self): - self.object.friends.add(self.request.user) - messages.success(self.request, 'The group has been successfully created') - return super().get_success_url() - - -class LeaveGroupView(LoginRequiredMixin, generic.UpdateView): - model = models.LocationSharingGroup - context_object_name = 'group' - template_name = 'map/leave_group.html' - fields = [] - success_url = reverse_lazy('manage-groups') - - def get_success_url(self): - self.object.friends.remove(self.request.user) - if self.object.friends.count() == 0: - self.object.delete() - messages.success(self.request, 'You successfully left the group') - return super().get_success_url()