volunteers: handle logged users
This commit is contained in:
parent
4acc32221a
commit
5da508d2d0
15
cfp/views.py
15
cfp/views.py
|
@ -44,10 +44,23 @@ def home(request):
|
||||||
def volunteer_enrole(request):
|
def volunteer_enrole(request):
|
||||||
if not request.conference.volunteers_enrollment_is_open():
|
if not request.conference.volunteers_enrollment_is_open():
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
form = VolunteerForm(request.POST or None, conference=request.conference)
|
initial = {}
|
||||||
|
if request.user.is_authenticated():
|
||||||
|
if Volunteer.objects.filter(site=request.conference.site, email=request.user.email).exists():
|
||||||
|
return redirect(reverse('volunteer-home'))
|
||||||
|
elif not request.POST:
|
||||||
|
# TODO: import biography, phone number and sms_prefered from User profile
|
||||||
|
initial.update({
|
||||||
|
'name': request.user.get_full_name(),
|
||||||
|
})
|
||||||
|
form = VolunteerForm(request.POST or None, initial=initial, conference=request.conference)
|
||||||
|
if request.user.is_authenticated():
|
||||||
|
form.fields.pop('email')
|
||||||
if request.method == 'POST' and form.is_valid():
|
if request.method == 'POST' and form.is_valid():
|
||||||
volunteer = form.save(commit=False)
|
volunteer = form.save(commit=False)
|
||||||
volunteer.language = request.LANGUAGE_CODE
|
volunteer.language = request.LANGUAGE_CODE
|
||||||
|
if request.user.is_authenticated():
|
||||||
|
volunteer.email = request.user.email
|
||||||
volunteer.save()
|
volunteer.save()
|
||||||
body = _("""Hi {},
|
body = _("""Hi {},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue