friendsmap/map/forms.py

50 lines
1.2 KiB
Python
Raw Normal View History

2019-03-02 17:39:53 +01:00
from django import forms
2019-03-04 18:44:56 +01:00
from django.contrib.auth.forms import UserCreationForm
2019-03-02 17:39:53 +01:00
2019-03-03 19:56:14 +01:00
from map.models import FriendLocation, Friend
2019-03-02 17:39:53 +01:00
class LocationForm(forms.ModelForm):
class Meta:
model = FriendLocation
fields = [
'latitude',
'longitude',
'start_date',
'end_date',
'friend',
]
widgets = {'friend': forms.HiddenInput()}
def __init__(self, request, *args, **kwargs):
super().__init__(*args, **kwargs)
self.request = request
def clean_friend(self):
return self.request.user
2019-03-03 19:56:14 +01:00
class LocationSharingForm(forms.ModelForm):
2019-03-03 19:56:14 +01:00
class Meta:
model = Friend
fields = [
'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)
self.fields['shares_location_to'].label = 'Share location to'
2019-03-04 18:44:56 +01:00
class FriendCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = Friend
2019-03-04 21:07:20 +01:00
fields = UserCreationForm.Meta.fields + (
'first_name',
'last_name',
'email',
)
2019-03-04 18:44:56 +01:00