new proposal with logged user: use form initial
This commit is contained in:
parent
c7c41cfb3d
commit
ebec3575c4
21
cfp/views.py
21
cfp/views.py
|
@ -168,20 +168,19 @@ def proposal_home(request):
|
||||||
categories = request.conference.opened_categories
|
categories = request.conference.opened_categories
|
||||||
if not categories.exists():
|
if not categories.exists():
|
||||||
return render(request, 'cfp/closed.html')
|
return render(request, 'cfp/closed.html')
|
||||||
|
initial = {}
|
||||||
|
fields = ['name', 'email', 'biography']
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
if Participant.objects.filter(site=request.conference.site, email=request.user.email).exists():
|
if Participant.objects.filter(site=request.conference.site, email=request.user.email).exists():
|
||||||
return redirect(reverse('proposal-dashboard'))
|
return redirect(reverse('proposal-dashboard'))
|
||||||
else:
|
elif not request.POST:
|
||||||
NewSpeakerForm = modelform_factory(Participant, form=ParticipantForm, fields=['name', 'biography'])
|
# TODO: import biography from User profile
|
||||||
if request.POST:
|
initial.update({
|
||||||
data = request.POST
|
'name': request.user.get_full_name(),
|
||||||
else:
|
})
|
||||||
# TODO: import biography from User profile
|
fields.remove('email')
|
||||||
data = dict(name=request.user.get_full_name())
|
NewSpeakerForm = modelform_factory(Participant, form=ParticipantForm, fields=fields)
|
||||||
else:
|
speaker_form = NewSpeakerForm(request.POST or None, initial=initial, conference=request.conference)
|
||||||
NewSpeakerForm = modelform_factory(Participant, form=ParticipantForm, fields=['name', 'email', 'biography'])
|
|
||||||
data = request.POST or None
|
|
||||||
speaker_form = NewSpeakerForm(data, conference=request.conference)
|
|
||||||
talk_form = TalkForm(request.POST or None, categories=categories)
|
talk_form = TalkForm(request.POST or None, categories=categories)
|
||||||
if request.method == 'POST' and all(map(lambda f: f.is_valid(), [speaker_form, talk_form])):
|
if request.method == 'POST' and all(map(lambda f: f.is_valid(), [speaker_form, talk_form])):
|
||||||
speaker = speaker_form.save(commit=False)
|
speaker = speaker_form.save(commit=False)
|
||||||
|
|
Loading…
Reference in New Issue