Esempio n. 1
0
def user_profile(request):

    profile = request.user.get_profile()

    if request.method == "POST":
        # Read params
        form = ProfileForm(request.POST, instance=profile)
        subscriptionform = SubscriptionForm(request.POST, instance=profile)
        userform = UserForm(request.POST, instance=request.user)
        if appsettings.DEMO_SERVER and request.user.username == "demo":
            messages.warning(request, _("You can not change demo profile on the demo server."))
            return redirect("profile")

        if form.is_valid() and userform.is_valid() and subscriptionform.is_valid():
            # Save changes
            form.save()
            subscriptionform.save()
            userform.save()

            # Change language
            set_lang(request.user, request=request, user=request.user)

            # Redirect after saving (and possibly changing language)
            response = redirect("profile")

            # Set language cookie and activate new language (for message below)
            lang_code = profile.language
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
            translation.activate(lang_code)

            messages.info(request, _("Your profile has been updated."))

            return response
    else:
        form = ProfileForm(instance=profile)
        subscriptionform = SubscriptionForm(instance=profile)
        userform = UserForm(instance=request.user)

    social = request.user.social_auth.all()
    social_names = [assoc.provider for assoc in social]
    new_backends = [x for x in load_backends(BACKENDS).keys() if x == "email" or x not in social_names]

    response = render_to_response(
        "accounts/profile.html",
        RequestContext(
            request,
            {
                "form": form,
                "userform": userform,
                "subscriptionform": subscriptionform,
                "profile": profile,
                "title": _("User profile"),
                "licenses": Project.objects.exclude(license=""),
                "associated": social,
                "new_backends": new_backends,
            },
        ),
    )
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language)
    return response
Esempio n. 2
0
def user_profile(request):

    profile = request.user.get_profile()

    if request.method == "POST":
        # Read params
        form = ProfileForm(request.POST, instance=profile)
        subscriptionform = SubscriptionForm(request.POST, instance=profile)
        userform = UserForm(request.POST, instance=request.user)
        if form.is_valid() and userform.is_valid() and subscriptionform.is_valid():
            # Save changes
            form.save()
            subscriptionform.save()
            userform.save()

            # Change language
            set_lang(request.user, request=request, user=request.user)

            # Redirect after saving (and possibly changing language)
            response = HttpResponseRedirect(reverse("profile"))

            # Set language cookie and activate new language (for message below)
            lang_code = profile.language
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
            translation.activate(lang_code)

            messages.info(request, _("Your profile has been updated."))

            return response
    else:
        form = ProfileForm(instance=profile)
        subscriptionform = SubscriptionForm(instance=profile)
        userform = UserForm(instance=request.user)

    response = render_to_response(
        "profile.html",
        RequestContext(
            request,
            {
                "form": form,
                "userform": userform,
                "subscriptionform": subscriptionform,
                "profile": profile,
                "title": _("User profile"),
                "licenses": Project.objects.exclude(license=""),
            },
        ),
    )
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language)
    return response
Esempio n. 3
0
def user_profile(request):

    profile = request.user.get_profile()

    if request.method == 'POST':
        # Read params
        form = ProfileForm(request.POST, instance=profile)
        subscriptionform = SubscriptionForm(request.POST, instance=profile)
        userform = UserForm(request.POST, instance=request.user)
        if (form.is_valid() and userform.is_valid()
                and subscriptionform.is_valid()):
            # Save changes
            form.save()
            subscriptionform.save()
            userform.save()

            # Change language
            set_lang(request.user, request=request, user=request.user)

            # Redirect after saving (and possibly changing language)
            response = HttpResponseRedirect(reverse('profile'))

            # Set language cookie and activate new language (for message below)
            lang_code = profile.language
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
            translation.activate(lang_code)

            messages.info(request, _('Your profile has been updated.'))

            return response
    else:
        form = ProfileForm(instance=profile)
        subscriptionform = SubscriptionForm(instance=profile)
        userform = UserForm(instance=request.user)

    response = render_to_response(
        'profile.html',
        RequestContext(
            request, {
                'form': form,
                'userform': userform,
                'subscriptionform': subscriptionform,
                'profile': profile,
                'title': _('User profile'),
            }))
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, profile.language)
    return response
Esempio n. 4
0
def user_profile(request):

    profile = request.user.get_profile()

    if request.method == 'POST':
        # Read params
        form = ProfileForm(
            request.POST,
            instance=profile
        )
        subscriptionform = SubscriptionForm(
            request.POST,
            instance=profile
        )
        userform = UserForm(
            request.POST,
            instance=request.user
        )
        if (form.is_valid()
                and userform.is_valid()
                and subscriptionform.is_valid()):
            # Save changes
            form.save()
            subscriptionform.save()
            userform.save()

            # Change language
            set_lang(request.user, request=request, user=request.user)

            # Redirect after saving (and possibly changing language)
            response = HttpResponseRedirect(reverse('profile'))

            # Set language cookie and activate new language (for message below)
            lang_code = profile.language
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
            translation.activate(lang_code)

            messages.info(request, _('Your profile has been updated.'))

            return response
    else:
        form = ProfileForm(
            instance=profile
        )
        subscriptionform = SubscriptionForm(
            instance=profile
        )
        userform = UserForm(
            instance=request.user
        )

    response = render_to_response('profile.html', RequestContext(request, {
        'form': form,
        'userform': userform,
        'subscriptionform': subscriptionform,
        'profile': profile,
        'title': _('User profile'),
    }))
    response.set_cookie(
        settings.LANGUAGE_COOKIE_NAME,
        profile.language
    )
    return response