# -*- coding: utf-8 -*-

#
# Copyright 2016 edX PDR Lab, National Central University, Taiwan.
#
#     http://edxpdrlab.ncu.cc/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Created By: yrchen@ATCity.org
# Maintained By: yrchen@ATCity.org
#

from __future__ import absolute_import, unicode_literals

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
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
        if self.request.user.is_staff:
            context['elos_total_count'] = ELO.objects.all().count()
        # only staff can check all ELOs
        else:
            context['elos_total_count'] = ELO.objects.filter(
                is_public=1).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).order_by(
            '-update_date')[:settings.DASHBOARD_MAX_ELOS_MY_PER_PAGE]

        if self.request.user.is_staff:
            context['elos_all_list'] = ELO.objects.all().order_by(
                '-update_date')[:settings.DASHBOARD_MAX_ELOS_ALL_PER_PAGE]
        else:
            context['elos_all_list'] = ELO.objects.filter(is_public=1).order_by(
                '-update_date')[:settings.DASHBOARD_MAX_ELOS_ALL_PER_PAGE]

        return context

@@ -738,16 +738,88 @@
 .org%0A#%0A%0A
+%22%22%22%0AView configurations for Main app in Common Repository project.%0A%22%22%22%0A%0A
 from __f
@@ -1182,16 +1182,87 @@
 teView):
+%0A    %22%22%22%0A    View of dashboard.%0A%0A    * Requires authentication.%0A    %22%22%22
 %0A%0A    te
@@ -1635,16 +1635,23 @@
        #
+ Common
  informa
@@ -1655,16 +1655,56 @@
 rmation%0A
+        # Only staff can check all ELOs%0A
         
@@ -1806,48 +1806,8 @@
 t()%0A
-        # only staff can check all ELOs%0A
     
@@ -2256,32 +2256,72 @@
 S_MY_PER_PAGE%5D%0A%0A
+        # Only staff can check all ELOs%0A
         if self.

更新 modules Main 中的 views.py, 新增函式功能宣告註解