Пример #1
0
def edit_profile(request):
    """ Used to allow a user to edit their own profile """
    # Get the user and profile objects.
    user = request.user
    profile = Profile.objects.for_user(user)
    if request.method != "POST":
        # New form needed, set the fields to their current values
        profile_form = ProfileForm(instance=profile)
        user_form = UserForm(instance=user)
    else:
        # Create the form based on the filled out fields.  Include the old instance to get the required fields that we will not be showing, (e.g. the user)
        profile_form = ProfileForm(request.POST, instance=profile)
        user_form = UserForm(request.POST, instance=user)
        # Check to make sure that all the fields were filled out correctly
        if profile_form.is_valid() and user_form.is_valid():
            # Save the profile
            profile_form.save()
            user_form.save()
            return HttpResponseRedirect(reverse("epic.core.views.view_profile", kwargs={}))
        else:
            # Form will have errors which will be displayed by page
            pass
    return render_to_response(
        "core/edit_profile.html",
        {"profile_form": profile_form, "user_form": user_form},
        context_instance=RequestContext(request),
    )
Пример #2
0
def edit_profile(request):
    """ Used to allow a user to edit their own profile.
    """
    
    user = request.user
    profile = Profile.objects.for_user(user)
    
    if request.method != 'POST':
        profile_form = ProfileForm(instance=profile)
        user_form = UserForm(instance=user)
    else:
        profile_form = ProfileForm(request.POST, instance=profile)
        user_form = UserForm(request.POST, instance=user)
        
        if profile_form.is_valid() and user_form.is_valid():
            profile_form.save()
            user_form.save()
            
            return HttpResponseRedirect(reverse(
                'epic.core.views.view_profile', kwargs={}))
    
    return render_to_response(
        'core/edit_profile.html',
        {'profile_form': profile_form, 'user_form': user_form,},
        context_instance=RequestContext(request))