# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

from django.conf import settings
from django.shortcuts import redirect, render
from django.views.generic.base import TemplateView

from commonrepo.elos.models import ELO
from commonrepo.users.models import User as User

class DashboardView(TemplateView):

    template_name='main/dashboard.html'

    def dispatch(self, request, *args, **kwargs):
        if not request.user.is_authenticated():
            return redirect('home')

        return super(DashboardView, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(DashboardView, self).get_context_data(**kwargs)

        # information
        context['elos_total_count'] = ELO.objects.all().count()
        context['elos_my_total_count'] = ELO.objects.filter(author=self.request.user).count()
        context['users_total_count'] = User.objects.all().count()

        # ELOs
        context['elos_my_list'] = ELO.objects.filter(author=self.request.user)[:settings.DASHBOARD_MAX_ELOS_MY_PER_PAGE]
        context['elos_all_list'] = ELO.objects.all()[:settings.DASHBOARD_MAX_ELOS_ALL_PER_PAGE]

        return context

@@ -124,41 +124,230 @@
 ngo.
-shortcuts import redirect, render
+contrib.auth.decorators import login_required%0Afrom django.contrib.contenttypes.models import ContentType%0Afrom django.shortcuts import redirect, render, get_object_or_404%0Afrom django.views.decorators.csrf import csrf_exempt
 %0Afro
@@ -395,16 +395,47 @@
 teView%0A%0A
+from actstream import actions%0A%0A
 from com
@@ -1423,8 +1423,390 @@
 context%0A
+%0A@login_required%0A@csrf_exempt%0Adef follow_user(request, username):%0A    %22%22%22%0A    Creates or deletes the follow relationship between %60%60request.user%60%60 and the %60%60user%60%60%0A    %22%22%22%0A    user = get_object_or_404(User, username=username)%0A%0A    actions.follow(request.user, user, actor_only=actor_only)%0A    user.userprofile.follower.add(request.user)%0A%0A    return respond(request, 201)   # CREATED%0A

更新 views main, 新增 follow_user() 用來讓使用者追蹤特定使用者