# Path: harnas/userprofile/forms.py
# class UserFieldsForm(forms.ModelForm):
#     class Meta:
#         model = User
#         fields = ('first_name', 'last_name')
# 
# class UserProfileEditForm(forms.ModelForm):
#     class Meta:
#         model = UserProfile
#         fields = ('organization', 'personal_page', 'show_email', 'show_age')


from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render, render_to_response
from django.template import RequestContext
from django.views.decorators.http import require_safe
from harnas.userprofile.forms import UserFieldsForm, UserProfileEditForm


@require_safe
@login_required
def show(request, user_id):
    """
    :return: profile page of a user specified by user_id.
    """
    user = get_object_or_404(User, pk=user_id)
    return render(request, 'profile.html', {
        'user': user,
        'profile': user.userprofile
    })


@login_required
def edit(request):
    user = request.user

    if request.method == 'POST':
        user_form = UserFieldsForm(request.POST or None, instance=user)

# Path: harnas/userprofile/forms.py
# class UserFieldsForm(forms.ModelForm):
#     class Meta:
#         model = User
#         fields = ('first_name', 'last_name')
# 
# class UserProfileEditForm(forms.ModelForm):
#     class Meta:
#         model = UserProfile
#         fields = ('organization', 'personal_page', 'show_email', 'show_age')


# Path: harnas/userprofile/views.py
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render, render_to_response
from django.template import RequestContext
from django.views.decorators.http import require_safe
from harnas.userprofile.forms import UserFieldsForm, UserProfileEditForm



@require_safe
@login_required
def show(request, user_id):
    """
    :return: profile page of a user specified by user_id.
    """
    user = get_object_or_404(User, pk=user_id)
    return render(request, 'profile.html', {
        'user': user,
        'profile': user.userprofile
    })


@login_required
def edit(request):
    user = request.user

    if request.method == 'POST':
        user_form = UserFieldsForm(request.POST or None, instance=user)

        profile_form = UserProfileEditForm(