Пример #1
0
def profile(request):

    if request.method == 'POST':
        form = ProfileForm(request.POST, instance = request.user.get_profile())
        subscriptionform = SubscriptionForm(request.POST, instance = request.user.get_profile())
        userform = UserForm(request.POST, instance = request.user)
        if form.is_valid() and userform.is_valid() and subscriptionform.is_valid():
            form.save()
            subscriptionform.save()
            userform.save()
            set_lang(request.user, request = request, user = request.user)
            # Need to redirect to allow language change
            response = HttpResponseRedirect('/accounts/profile/')
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, request.user.get_profile().language)
            return response
    else:
        form = ProfileForm(instance = request.user.get_profile())
        subscriptionform = SubscriptionForm(instance = request.user.get_profile())
        userform = UserForm(instance = request.user)

    response = render_to_response('profile.html', RequestContext(request, {
        'form': form,
        'userform': userform,
        'subscriptionform': subscriptionform,
        'title': _('User profile'),
        }))
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, request.user.get_profile().language)
    return response
Пример #2
0
def profile(request):

    user_profile = request.user.get_profile()

    if request.method == "POST":
        # Read params
        form = ProfileForm(request.POST, instance=user_profile)
        subscriptionform = SubscriptionForm(request.POST, instance=user_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 = user_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=user_profile)
        subscriptionform = SubscriptionForm(instance=user_profile)
        userform = UserForm(instance=request.user)

    response = render_to_response(
        "profile.html",
        RequestContext(
            request,
            {
                "form": form,
                "userform": userform,
                "subscriptionform": subscriptionform,
                "profile": user_profile,
                "title": _("User profile"),
            },
        ),
    )
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_profile.language)
    return response
Пример #3
0
def profile(request):

    if request.method == 'POST':
        # Read params
        form = ProfileForm(request.POST, instance = request.user.get_profile())
        subscriptionform = SubscriptionForm(request.POST, instance = request.user.get_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('/accounts/profile/')

            # Set language cookie and activate new language (for message bellow)
            lang_code = request.user.get_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 = request.user.get_profile())
        subscriptionform = SubscriptionForm(instance = request.user.get_profile())
        userform = UserForm(instance = request.user)

    profile = request.user.get_profile()
    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
Пример #4
0
def profile(request):

    if request.method == 'POST':
        # Read params
        form = ProfileForm(request.POST, instance = request.user.get_profile())
        subscriptionform = SubscriptionForm(request.POST, instance = request.user.get_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('/accounts/profile/')

            # Set language cookie and activate new language (for message below)
            lang_code = request.user.get_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 = request.user.get_profile())
        subscriptionform = SubscriptionForm(instance = request.user.get_profile())
        userform = UserForm(instance = request.user)

    profile = request.user.get_profile()
    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
Пример #5
0
def user_profile(request):

    profile = request.user.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]
    all_backends = set(load_backends(BACKENDS).keys())
    new_backends = [
        x for x in all_backends
        if x == 'email' or x not in social_names
    ]
    license_projects = Project.objects.all_acl(
        request.user
    ).exclude(
        license=''
    )

    response = render(
        request,
        'accounts/profile.html',
        {
            'form': form,
            'userform': userform,
            'subscriptionform': subscriptionform,
            'profile': profile,
            'title': _('User profile'),
            'licenses': license_projects,
            'associated': social,
            'new_backends': new_backends,
        }
    )
    response.set_cookie(
        settings.LANGUAGE_COOKIE_NAME,
        profile.language
    )
    return response