2016-07-11 19:33:34 +00:00
|
|
|
from django import forms
|
2016-06-11 13:42:40 +00:00
|
|
|
from django.contrib.auth.models import User
|
2016-06-11 13:47:08 +00:00
|
|
|
from django.forms.models import modelform_factory
|
2016-08-07 07:39:53 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-07-09 22:15:08 +00:00
|
|
|
|
2016-07-11 19:33:34 +00:00
|
|
|
from django_select2.forms import Select2Widget
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-25 10:33:04 +00:00
|
|
|
from .models import Participation, Profile
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-12 15:11:11 +00:00
|
|
|
UserForm = modelform_factory(User, fields=['first_name', 'last_name', 'email', 'username'])
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2017-04-29 21:43:28 +00:00
|
|
|
ProfileForm = modelform_factory(Profile, fields=['phone_number', 'biography', 'twitter', 'website', 'linkedin', 'facebook', 'mastodon'])
|
2016-06-25 15:38:01 +00:00
|
|
|
|
2016-08-08 22:55:19 +00:00
|
|
|
ParticipationForm = modelform_factory(Participation,
|
2016-10-13 18:31:51 +00:00
|
|
|
fields=['need_transport', 'transport', 'transport_city_outward', 'transport_city_return',
|
|
|
|
'accommodation',
|
2016-08-08 22:55:19 +00:00
|
|
|
'connector', 'sound', 'videotaped',
|
|
|
|
'video_licence', 'constraints'],
|
2016-07-11 19:33:34 +00:00
|
|
|
widgets={'transport': forms.CheckboxSelectMultiple(),
|
2016-08-07 07:39:53 +00:00
|
|
|
'connector': forms.CheckboxSelectMultiple()},
|
|
|
|
help_texts = {
|
2016-08-08 22:55:19 +00:00
|
|
|
'constraints': _('For example, you need to be back on saturday evening, you cannot eat meat.'),
|
2016-08-07 07:39:53 +00:00
|
|
|
})
|
2016-07-04 23:16:33 +00:00
|
|
|
|
2016-07-12 12:07:23 +00:00
|
|
|
ProfileOrgaForm = modelform_factory(Profile, fields=['biography'])
|
2016-07-04 23:16:33 +00:00
|
|
|
|
|
|
|
ParticipationOrgaForm = modelform_factory(Participation,
|
2016-10-13 18:31:51 +00:00
|
|
|
fields=['need_transport', 'transport', 'transport_city_outward', 'transport_city_return', 'transport_booked',
|
2016-10-06 19:24:52 +00:00
|
|
|
'accommodation', 'accommodation_booked',
|
2016-08-08 23:01:18 +00:00
|
|
|
'connector', 'sound', 'videotaped',
|
|
|
|
'video_licence',
|
2016-07-12 12:07:23 +00:00
|
|
|
'constraints', 'notes', 'orga'],
|
2016-07-11 19:33:34 +00:00
|
|
|
widgets={'transport': forms.CheckboxSelectMultiple(),
|
|
|
|
'connector': forms.CheckboxSelectMultiple()})
|
|
|
|
|
2016-07-09 22:15:08 +00:00
|
|
|
|
|
|
|
class ParticipationField(forms.ModelChoiceField):
|
|
|
|
def label_from_instance(self, obj):
|
|
|
|
return obj.profile.__str__()
|
|
|
|
|
|
|
|
|
|
|
|
class NewParticipationForm(forms.Form):
|
2016-07-23 17:47:09 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
site = kwargs.pop('site')
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
queryset = User.objects.exclude(participation__site=site).all()
|
|
|
|
self.fields['participant'] = ParticipationField(queryset, widget=Select2Widget(),
|
2016-07-11 19:33:34 +00:00
|
|
|
label='Add participant from existing account')
|