Exemplo n.º 1
0
def settings(request):
    """
    User editing their profile preferences
    """
    title = _("Profile Settings")
    form = ProfileForm(instance=request.user)

    if request.method == "POST":

        form = ProfileForm(request.POST, request.FILES, instance=request.user)

        if form.is_valid():
            user = form.save()
            messages.success(request, _("Settings saved"))
            User.refresh_nomail()

            if form.cleaned_data["password1"]:
                request.user.set_password(form.cleaned_data["password1"])
                request.user.save()

            lang = user.activate_locale()
            translation.activate(lang)
            request.session[translation.LANGUAGE_SESSION_KEY] = lang
            request.session["django_timezone"] = user.timezone

            return redirect(settings)
        else:
            messages.error(request, _("Error in profile data"))

    return render(request, "accounts/settings.html", locals())
Exemplo n.º 2
0
def settings(request):
    """
    User editing their profile preferences
    """
    title = _("Profile Settings")
    form = ProfileForm(instance=request.user)

    if request.method == "POST":

        form = ProfileForm(request.POST, request.FILES, instance=request.user)

        if form.is_valid():
            user = form.save()
            messages.success(request, _("Settings saved"))
            User.refresh_nomail()

            if form.cleaned_data['password1']:
                request.user.set_password(form.cleaned_data['password1'])
                request.user.save()

            lang = user.activate_locale()
            translation.activate(lang)
            request.session[translation.LANGUAGE_SESSION_KEY] = lang
            request.session['django_timezone'] = user.timezone

            return redirect(settings)
        else:
            messages.error(request, _("Error in profile data"))

    return render(request, "accounts/settings.html", locals())
Exemplo n.º 3
0
def settings(request):
    if request.method == 'POST':
    	data = request.POST.copy()
    	data['user'] = request.user.id
        profile = request.user.get_profile()
        form = ProfileForm(data, instance=profile)

        if form.is_valid():
        	profile = form.save()
        else:
        	print form.errors
        	return render(request, 'accounts/settings.html', {'form': form})
        
        if request.POST.get('password'):
            request.user.set_password(request.POST['password'])

        request.session['user_profile'] = profile
        msgs.add_message(request, msgs.INFO, _(u'Asetukset tallennettu'))
        return redirect('servo.views.account.settings')
    else:
        form = ProfileForm(instance=request.user.get_profile())
        return render(request, 'accounts/settings.html', {'form': form})