Пример #1
0
Файл: views.py Проект: p-p-m/ccp
def personal_data_update(request):
    form = PersonalDataForm(request.POST or None, files=request.FILES or None)
    is_saved = False
    if request.is_ajax():
        if form.is_valid():
            is_saved = True
            form.save()
        photo = PersonalData.objects.get(id=1).photo
        return render(
            request, 'form.html', {'form': form, 'is_saved': is_saved, 'photo': photo})
    photo = PersonalData.objects.get(id=1).photo
    return render(
        request, 'personal_data_update.html',
        {'form': form, 'photo': photo})
Пример #2
0
def personal_data(request):
    '''Personal data'''
    context = {}
    context['saved'] = False
    user = request.user

    if request.method == 'POST':
        form = PersonalDataForm(request.POST.copy())
        if form.is_valid():
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']
            user.save()
            context['saved'] = True
    else:
        form = PersonalDataForm( {
            'first_name': user.first_name,
            'last_name': user.last_name,
            'email': user.email } )

    context['form'] = form

    return render_to_response('personal_data.html',
        context, context_instance=RequestContext(request))