Example #1
0
def settings(request):
    profile = UserProfile.for_user(request.user)
    if request.method == 'POST':
        form = UserProfileForm(instance=profile, data=request.POST)
        if form.is_valid():
            form.save()

    else:
        form = UserProfileForm(instance=profile)
    return render(request, "people/settings.html", locals())
Example #2
0
def user_profile_crud(request):
    python_groups = None
    if request.user.is_authenticated():

        profile, created = UserProfile.objects.get_or_create(user=request.user)
        profile.name = profile.name or request.user.first_name

        form = UserProfileForm(request.POST or None, instance=profile)

        python_groups = profile.user.pythongroup_set.all()

        if request.POST:
            if form.is_valid():
                form.save()
    else:
        form = None
        messages.add_message(request, messages.INFO, 'You may sign in to update your profile.')
    return render(request,
        "people/userprofile_form.html",
        {'form': form,
        'python_groups': python_groups},
        )