diff --git a/.gitignore b/.gitignore index a46410c1b3..207eeb2ac3 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ mysite.pid notification_email.sh send_user_notifications.sh shutdown.sh +cscope* diff --git a/seahub/base/context_processors.py b/seahub/base/context_processors.py index 4d8bbc52b3..f1ecec2b5a 100644 --- a/seahub/base/context_processors.py +++ b/seahub/base/context_processors.py @@ -18,7 +18,7 @@ try: except ImportError: SEACLOUD_MODE = False -from seahub.utils import HAS_FILE_SEARCH, EVENTS_ENABLED +from seahub.utils import HAS_FILE_SEARCH, EVENTS_ENABLED, TRAFFIC_STATS_ENABLED try: from seahub.settings import ENABLE_PUBFILE @@ -67,6 +67,7 @@ def base(request): 'show_repo_download_button': SHOW_REPO_DOWNLOAD_BUTTON, 'repo_password_min_length': REPO_PASSWORD_MIN_LENGTH, 'events_enabled': EVENTS_ENABLED, + 'traffic_stats_enabled': TRAFFIC_STATS_ENABLED, 'mods_available': mods_available, 'mods_enabled': mods_enabled, 'grps': grps, diff --git a/seahub/templates/admin_base.html b/seahub/templates/admin_base.html index ccc81facea..7f09fd255c 100644 --- a/seahub/templates/admin_base.html +++ b/seahub/templates/admin_base.html @@ -4,4 +4,3 @@ {% block sys_admin %}{% endblock %} {% block nav %}{% endblock %} - diff --git a/seahub/templates/sysadmin/base.html b/seahub/templates/sysadmin/base.html index b1fc590ffa..d0d5a022d4 100644 --- a/seahub/templates/sysadmin/base.html +++ b/seahub/templates/sysadmin/base.html @@ -19,7 +19,12 @@ + + {% if traffic_stats_enabled %} +
  • + {% trans "Traffic" %} +
  • + {% endif %} {% endblock %} diff --git a/seahub/templates/sysadmin/sys_trafficadmin.html b/seahub/templates/sysadmin/sys_trafficadmin.html new file mode 100644 index 0000000000..d90eb6299e --- /dev/null +++ b/seahub/templates/sysadmin/sys_trafficadmin.html @@ -0,0 +1,68 @@ +{% extends "admin_base.html" %} +{% load seahub_tags i18n %} +{% block nav_trafficadmin_class %}class="cur"{% endblock %} + +{% block main_panel %} + +
    + + +
    + + + + + + + + + + {% for info in traffic_info_list %} + + + + + + + + + {% endfor %} +
    {% trans "User" %}{% trans "Total Usage" %}{% trans "Shared File View" %}{% trans "Shared File Download" %}{% trans "Shared Folder Download" %}
    {{ info.email }}{{ info.total |filesizeformat }}{{ info.file_view |filesizeformat }}{{ info.file_download |filesizeformat }}{{ info.dir_download |filesizeformat }}
    + +
    + {% if current_page != 1 %} + {% trans "Previous" %} + {% endif %} + {% if page_next %} + {% trans "Next" %} + {% endif %} + {% if current_page != 1 or page_next %} + | + {% endif %} + {% trans "Per page: " %} + {% if per_page == 25 %} + 25 + {% else %} + 25 + {% endif %} + {% if per_page == 50 %} + 50 + {% else %} + 50 + {% endif %} + {% if per_page == 100 %} + 100 + {% else %} + 100 + {% endif %} +
    + +{% endblock %} + +{% block extra_script %} + +{% endblock %} diff --git a/seahub/urls.py b/seahub/urls.py index 96bfbd770d..f90203dcc7 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -233,3 +233,9 @@ if HAS_OFFICE_CONVERTER: url(r'^office-convert/status/$', office_convert_query_status, name='office_convert_query_status'), url(r'^office-convert/page-num/$', office_convert_query_page_num, name='office_convert_query_page_num'), ) + +if TRAFFIC_STATS_ENABLED: + from seahub.views.sysadmin import sys_traffic_admin + urlpatterns += patterns('', + url(r'^sys/trafficadmin/$', sys_traffic_admin, name='sys_trafficadmin'), + ) \ No newline at end of file diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 27302bb46f..252e120262 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -864,7 +864,16 @@ if EVENTS_CONFIG_FILE and hasattr(seafevents, 'get_user_traffic_stat'): finally: session.close() return stat + + def get_user_traffic_list(month, start=0, limit=25): + session = SeafEventsSession() + try: + stat = seafevents.get_user_traffic_list(session, month, start, limit) + finally: + session.close() + return stat else: def get_user_traffic_stat(username): pass - + def get_user_traffic_list(): + pass diff --git a/seahub/views/sysadmin.py b/seahub/views/sysadmin.py index 24d7f6b324..8bcdebd0d8 100644 --- a/seahub/views/sysadmin.py +++ b/seahub/views/sysadmin.py @@ -4,6 +4,8 @@ import os from types import FunctionType import logging import simplejson as json +import re +import datetime from django.core.urlresolvers import reverse from django.contrib import messages @@ -32,7 +34,7 @@ from seahub.share.models import FileShare import seahub.settings as settings from seahub.settings import INIT_PASSWD, SITE_NAME, \ SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER, SEND_EMAIL_ON_RESETTING_USER_PASSWD -from seahub.utils import send_html_email +from seahub.utils import send_html_email, get_user_traffic_list logger = logging.getLogger(__name__) @@ -669,3 +671,39 @@ def sys_repo_transfer(request): next = reverse(sys_repo_admin) return HttpResponseRedirect(next) +@login_required +@sys_staff_required +def sys_traffic_admin(request): + """List all users from database. + """ + try: + current_page = int(request.GET.get('page', '1')) + per_page = int(request.GET.get('per_page', '25')) + except ValueError: + current_page = 1 + per_page = 25 + + month = request.GET.get('month', '') + if not re.match(r'[\d]{6}', month): + month = datetime.datetime.now().strftime('%Y%m') + + start = per_page * (current_page -1) + limit = per_page + 1 + traffic_info_list = get_user_traffic_list(month, start, limit) + + page_next = len(traffic_info_list) == limit + + for info in traffic_info_list: + info['total'] = info['file_view'] + info['file_download'] + info['dir_download'] + + return render_to_response( + 'sysadmin/sys_trafficadmin.html', { + 'traffic_info_list': traffic_info_list, + 'month': month, + 'current_page': current_page, + 'prev_page': current_page-1, + 'next_page': current_page+1, + 'per_page': per_page, + 'page_next': page_next, + }, + context_instance=RequestContext(request))