예제 #1
0
파일: views.py 프로젝트: SEJeff/snowy
def accounts_preferences(request, template_name='accounts/preferences.html'):
    user = request.user
    profile = user.get_profile()

    if 'password_form' in request.POST:
        password_form = PasswordChangeForm(user, data=request.POST)
        if password_form.is_valid():
            password_form.save()
    else:
        password_form = PasswordChangeForm(user)

    if 'email_form' in request.POST:
        email_form = EmailChangeForm(request.POST, instance=user)
        if email_form.is_valid():
            email_form.save()
    else:
        email_form = EmailChangeForm(instance=user)

    if 'i18n_form' in request.POST:
        i18n_form = InternationalizationForm(request.POST, instance=profile)
        if i18n_form.is_valid():
            i18n_form.save()
    else:
        i18n_form = InternationalizationForm(instance=profile)

    return render_to_response(template_name,
                              {'user': user, 'i18n_form': i18n_form,
                               'password_form': password_form,
                               'email_form' : email_form},
                              context_instance=RequestContext(request))
예제 #2
0
def accounts_preferences(request, template_name='accounts/preferences.html'):
    user = request.user
    profile = user.get_profile()
    open_ids = UserOpenID.objects.filter(user=user)

    if 'password_form' in request.POST:
        password_form = PasswordChangeForm(user, data=request.POST)
        if password_form.is_valid():
            password_form.save()
            messages.add_message(request, messages.SUCCESS, _("Password changed"))
    else:
        password_form = PasswordChangeForm(user)

    if 'email_form' in request.POST:
        email_form = EmailChangeForm(request.POST, instance=user)
        if email_form.is_valid():
            email_form.save()
    else:
        email_form = EmailChangeForm(instance=user)

    if 'i18n_form' in request.POST:
        i18n_form = InternationalizationForm(request.POST, instance=profile)
        if i18n_form.is_valid():
            i18n_form.save()
    else:
        i18n_form = InternationalizationForm(instance=profile)

    if 'openid_form' in request.POST:
        openid_form = RemoveUserOpenIDForm(request.POST, open_ids=open_ids)
        if openid_form.is_valid():
            if len(open_ids) == 1 and not user.has_usable_password():
                openid_form.errors['openid'] = [_('Cannot delete the last OpenID account')]
            else:
                openid_form.cleaned_data['openid'].delete()
    else:
        openid_form = RemoveUserOpenIDForm(open_ids=open_ids)

    return render_to_response(template_name,
                              {'user': user, 'i18n_form': i18n_form,
                               'password_form': password_form,
                               'email_form' : email_form,
                               'open_ids' : open_ids,
                               'openid_form' : openid_form},
                              context_instance=RequestContext(request))
예제 #3
0
def accounts_preferences(request, template_name='accounts/preferences.html'):
    user = request.user
    profile = user.get_profile()
    open_ids = UserOpenID.objects.filter(user=user)

    if 'password_form' in request.POST:
        password_form = PasswordChangeForm(user, data=request.POST)
        if password_form.is_valid():
            password_form.save()
            messages.add_message(request, messages.SUCCESS,
                                 _("Password changed"))
    else:
        password_form = PasswordChangeForm(user)

    if 'email_form' in request.POST:
        email_form = EmailChangeForm(request.POST, instance=user)
        if email_form.is_valid():
            email_form.save()
    else:
        email_form = EmailChangeForm(instance=user)

    if 'i18n_form' in request.POST:
        i18n_form = InternationalizationForm(request.POST, instance=profile)
        if i18n_form.is_valid():
            i18n_form.save()
    else:
        i18n_form = InternationalizationForm(instance=profile)

    if 'openid_form' in request.POST:
        openid_form = RemoveUserOpenIDForm(request.POST, open_ids=open_ids)
        if openid_form.is_valid():
            if len(open_ids) == 1 and not user.has_usable_password():
                openid_form.errors['openid'] = [
                    _('Cannot delete the last OpenID account')
                ]
            else:
                openid_form.cleaned_data['openid'].delete()
    else:
        openid_form = RemoveUserOpenIDForm(open_ids=open_ids)

    return render_to_response(template_name, {
        'user': user,
        'i18n_form': i18n_form,
        'password_form': password_form,
        'email_form': email_form,
        'open_ids': open_ids,
        'openid_form': openid_form
    },
                              context_instance=RequestContext(request))