def profile(request): c = get_common_context(request) user = request.user participant_form = None expert_form = None profile = user.get_profile() profile_form = None if request.method == 'GET': if Participant.exist(user): participant = Participant.objects.get(user=user) participant_form = ParticipantForm(instance=participant) elif Expert.exist(user): expert = Expert.objects.get(user=user) expert_form = ExpertForm(instance=expert) profile_form = ProfileForm(instance=profile, initial={'name': user.first_name, 'last_name': user.last_name}) if not (request.user.first_name or request.user.last_name): c['pr_msg'] = u'Необходимо заполнить поля: Имя и Фамилия.' else: if Expert.exist(user): expert = Expert.objects.get(user=user) expert_form = ExpertForm(request.POST, request.FILES) else: if Participant.exist(user): participant = Participant.objects.get(user=user) participant_form = ParticipantForm(request.POST, request.FILES) if participant_form.is_valid(): participant.about = participant_form.data['about'] participant.save() profile_form = ProfileForm(request.POST, request.FILES) if profile_form.is_valid(): user.first_name = profile_form.data['name'] user.last_name = profile_form.data['last_name'] user.save() if 'photo' in request.FILES: profile.photo = request.FILES.get('photo', '') profile.sex = profile_form.data.get('sex', '') profile.date_birth = profile_form.data['date_birth'] profile.school = profile_form.data['school'] profile.save() c['participant_form'] = participant_form c['expert_form'] = expert_form c['profile_form'] = profile_form c['user_photo'] = profile.photo return render_to_response('profile.html', c, context_instance=RequestContext(request))
def participant(request): if request.method == 'POST': #Bind ParticipantForm with the request form = ParticipantForm(request.POST) if form.is_valid(): #Save the Participant information participant = Participant( name = form.cleaned_data['name'], email = form.cleaned_data['email'], student_status = form.cleaned_data['student_status'], submitted_time = datetime.now() ) if not (form.cleaned_data['student_status'] == 'FA' or form.cleaned_data['student_status'] == 'ST'): exp_year = '20'+form.cleaned_data['expected_grad_year'] exp_month = form.cleaned_data['expected_grad_month'] expected_grad = exp_year+'-'+exp_month+'-01' participant.expected_grad = expected_grad participant.save() return render_to_response ( 'participant_interest_form.html', { 'success': True }, context_instance=RequestContext(request) ) else: #if form is invalid form = ParticipantForm(request.POST) return render_to_response( 'participant_interest_form.html', {'form': form}, context_instance=RequestContext(request) ) else: form = ParticipantForm() return render_to_response( 'participant_interest_form.html', {'form': form}, context_instance=RequestContext(request) )