Example #1
0
def edit_profile(request):
    """
        Edit profile (and User details) of logged in user.

        Template: people/edit_profile.html

        Context:
            form          - ``ProfileForm``
            password_form - ``anthill.people.forms.PasswordForm``
    """
    password_form = PasswordForm()

    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            user = request.user
            profile = user.profile
            user.first_name = form.cleaned_data['name']
            user.email = form.cleaned_data['email']
            profile.twitter_id = form.cleaned_data['twitter_id']
            profile.url = form.cleaned_data['url']
            profile.role = form.cleaned_data['position']
            profile.location = form.cleaned_data['location']
            profile.skills = form.cleaned_data['skills']
            profile.about = form.cleaned_data['about']
            user.save()
            profile.save()
            messages.success(request, 'Saved profile changes.')
    else:
        form = _user_to_profileform(request.user)
    return render_to_response('people/edit_profile.html', {
        'form': form,
        'password_form': password_form
    },
                              context_instance=RequestContext(request))
Example #2
0
def edit_profile(request):
    """
        Edit profile (and User details) of logged in user.

        Template: people/edit_profile.html

        Context:
            form          - ``ProfileForm``
            password_form - ``anthill.people.forms.PasswordForm``
    """
    password_form = PasswordForm()

    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            user = request.user
            profile = user.profile
            user.first_name = form.cleaned_data['name']
            user.email = form.cleaned_data['email']
            profile.twitter_id = form.cleaned_data['twitter_id']
            profile.url = form.cleaned_data['url']
            profile.role = form.cleaned_data['position']
            profile.location = form.cleaned_data['location']
            profile.skills = form.cleaned_data['skills']
            profile.about = form.cleaned_data['about']
            user.save()
            profile.save()
            messages.success(request, 'Saved profile changes.')
    else:
        form = _user_to_profileform(request.user)
    return render_to_response('people/edit_profile.html', 
                              {'form':form, 'password_form':password_form},
                              context_instance=RequestContext(request))
Example #3
0
def _user_to_profileform(user):
    """ helper method to convert User/Profile to a populated ProfileForm """
    profile = user.profile
    data = {
        'name': user.first_name,
        'email': user.email,
        'twitter_id': profile.twitter_id,
        'url': profile.url,
        'position': profile.role,
        'location': profile.location,
        'skills': profile.skills,
        'about': profile.about
    }
    return ProfileForm(data)
Example #4
0
def edit_profile(request):
    password_form = PasswordForm()

    if request.method == 'POST':
        form = ProfileForm(request.POST, request.FILES)
        if form.is_valid():
            user = request.user
            profile = user.profile
            user.first_name = form.cleaned_data['name']
            user.email = form.cleaned_data['email']
            profile.twitter_id = form.cleaned_data['twitter_id']
            profile.url = form.cleaned_data['url']
            profile.role = form.cleaned_data['position']
            profile.location = form.cleaned_data['location']
            profile.skills = form.cleaned_data['skills']
            profile.about = form.cleaned_data['about']
            user.save()
            profile.save()
            request.user.message_set.create(message='Saved profile changes.')
    else:
        form = _user_to_profileform(request.user)
    return render_to_response('people/edit_profile.html', 
                              {'form':form, 'password_form':password_form},
                              context_instance=RequestContext(request))