Allow sharing location to other users

This commit is contained in:
Gabriel Augendre 2019-03-03 19:56:14 +01:00
parent 7445f0a457
commit 3d83dbc91b
4 changed files with 41 additions and 9 deletions

View file

@ -1,6 +1,6 @@
from django import forms from django import forms
from map.models import FriendLocation from map.models import FriendLocation, Friend
class LocationForm(forms.ModelForm): class LocationForm(forms.ModelForm):
@ -21,3 +21,20 @@ class LocationForm(forms.ModelForm):
def clean_friend(self): def clean_friend(self):
return self.request.user return self.request.user
class ProfileForm(forms.ModelForm):
class Meta:
model = Friend
fields = [
'username',
'first_name',
'last_name',
'email',
'shares_location_to',
]
def __init__(self, request, *args, **kwargs):
super().__init__(*args, **kwargs)
self.request = request
self.fields['shares_location_to'].queryset = Friend.objects.exclude(pk=request.user.pk)

View file

@ -0,0 +1,19 @@
# Generated by Django 2.1.7 on 2019-03-03 18:55
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('map', '0009_auto_20190303_1943'),
]
operations = [
migrations.AlterField(
model_name='friend',
name='shares_location_to',
field=models.ManyToManyField(blank=True, related_name='is_shared_location_by', to=settings.AUTH_USER_MODEL),
),
]

View file

@ -13,7 +13,7 @@ class BaseModel(models.Model):
class Friend(AbstractUser): class Friend(AbstractUser):
shares_location_to = models.ManyToManyField('Friend', related_name='is_shared_location_by') shares_location_to = models.ManyToManyField('Friend', related_name='is_shared_location_by', blank=True)
def get_display_name(self): def get_display_name(self):
display_name = super().get_full_name() display_name = super().get_full_name()

View file

@ -4,7 +4,7 @@ from django.urls import reverse_lazy
from django.views import generic from django.views import generic
from map import models from map import models
from map.forms import LocationForm from map.forms import LocationForm, ProfileForm
from map.mixins import QuickActionsMixin from map.mixins import QuickActionsMixin
@ -99,12 +99,8 @@ class UpdateProfileView(LoginRequiredMixin, generic.UpdateView):
template_name = 'map/change_profile.html' template_name = 'map/change_profile.html'
success_url = reverse_lazy('map') success_url = reverse_lazy('map')
fields = [ def get_form(self, form_class=None):
'username', return ProfileForm(self.request, **self.get_form_kwargs())
'first_name',
'last_name',
'email',
]
def get_object(self, queryset=None): def get_object(self, queryset=None):
return self.request.user return self.request.user