text: 
  from actions.models import Action
  from django.shortcuts import render
  # from django.http import HttpResponse
  # from django.contrib.auth import authenticate, login
  from django.contrib.auth.decorators import login_required
  from .forms import LoginForm, UserRegistrationForm, \
      UserEditForm, ProfileEditForm
  from django.contrib import messages
  from .models import Profile
  from django.shortcuts import get_object_or_404  # 191
  from django.contrib.auth.models import User  # 191
  from django.http import JsonResponse  # 196
  from django.views.decorators.http import require_POST
  from common.decorators import ajax_required
  from .models import Contact
  from actions.utils import create_action
  
  # Create your views here.
  
  
  # def user_login(request):
  
  #     if request.method == 'POST':
  #         # POST IS THE BODY INFO OF A HTTP REQUEST POST
  #         form = LoginForm(request.POST)
  #         if form.is_valid():
  #             cd = form.cleaned_data
  #             user = authenticate(request,
  #                                 username=cd['username'],
  #                                 password=cd['password'])
  
  #             if user is not None:
  #                 if user.is_active:
  #                     login(request, user)
  #                     return HttpResponse('Aunthenticated succesfully')
  
  #             else:
  #                 return HttpResponse('Disable account')
  
  #         else:
  #             return HttpResponse('Invalid login')
  
  #     else:
  #         form = LoginForm()
  
  #     return render(request, 'account/login.html', {'form': form})
  
  
  @login_required
  def dashboard(request):
      # Display all actions by default
      actions = Action.objects.exclude(user=request.user)
      following_ids = request.user.following.values_list('id',
                                                         flat=True)
      if following_ids:
          # If user is following others, retrieve only their actions
          actions = actions.filter(user_id__in=following_ids)
      actions = actions.select_related('user', 'user__profile')\
                       .prefetch_related('target')[:10]
  
      return render(request,
                    'account/dashboard.html',
                    {'section': 'dashboard',
                     'actions': actions})
  
  
  def register(request):
      if request.method == 'POST':
          user_form = UserRegistrationForm(
              request.POST)  # what the request brings
          if user_form.is_valid():
              # create a new user object but avoid saving it yet
              new_user = user_form.save(commit=False)
              # set the chosen password
              new_user.set_password(user_form.cleaned_data['password'])
              # save the User object
              new_user.save()
              # create the user profile
              Profile.objects.create(user=new_user)
              create_action(new_user, 'has created an account')
  
              return render(request,
                            'account/register_done.html',
                            {'new_user': new_user})
      else:
          user_form = UserRegistrationForm()
  
      return render(request,
                    'account/register.html',
                    {'user_form': user_form})
  
  
  @login_required
  def edit(request):
      if request.method == 'POST':
          user_form = UserEditForm(instance=request.user,
                                   data=request.POST)
          profile_form = ProfileEditForm(instance=request.user.profile,
                                         data=request.POST,
                                         files=request.FILES)
          if user_form.is_valid() and profile_form.is_valid():
              user_form.save()
              profile_form.save()
              messages.success(request, 'Profile updated successfully')
          else:
              messages.error(request, 'Error updating your profile')
      else:
          user_form = UserEditForm(instance=request.user)
          profile_form = ProfileEditForm(instance=request.user.profile)
  
      return render(request,
                    'account/edit.html',
                    {'user_form': user_form,
                     'profile_form': profile_form})
  
  
  @login_required
  def user_list(request):  # 191
      users = User.objects.filter(is_active=True)
  
      return render(request,
                    'account/user/list.html',
                    {'section': 'people',
                     'users': users})
  
  
  @login_required
  def user_detail(request, username):  # 191
      user = get_object_or_404(User,
                               username=username,
                               is_active=True)
  
      return render(request,
                    'account/user/detail.html',
                    {'section': 'people',
                     'user': user})
  
  
  @ajax_required
  @require_POST
  @login_required
  def user_follow(request):  # 196
      """
      That view perform the process to follow/unfollow users
      """
      user_id = request.POST.get('id')
      action = request.POST.get('action')
      if user_id and action:
          try:
              user = User.objects.get(id=user_id)
              if action == 'follow':
                  Contact.objects.get_or_create(user_from=request.user,
                                                user_to=user)
                  create_action(request.user, 'is following', user)
              else:
                  Contact.objects.filter(user_from=request.user,
                                         user_to=user).delete()
              return JsonResponse({'status': 'ok'})
  
          except User.DoesNotExist:
              return JsonResponse({'status': 'error'})
  
      return JsonResponse({'status': 'error'})
  