1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-11 09:24:38 +00:00

added traffic admin

This commit is contained in:
lins05 2014-02-26 18:24:34 +08:00 committed by llj
parent 3fd69efde1
commit a9f39ab7df
8 changed files with 132 additions and 5 deletions

1
.gitignore vendored
View File

@ -27,3 +27,4 @@ mysite.pid
notification_email.sh
send_user_notifications.sh
shutdown.sh
cscope*

View File

@ -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,

View File

@ -4,4 +4,3 @@
{% block sys_admin %}<a href="{{ SITE_ROOT }}home/my/" title="{% trans "Exit System Admin" %}"><img src="{{ MEDIA_URL }}img/admin_out.png" alt="" /></a>{% endblock %}
{% block nav %}{% endblock %}

View File

@ -19,7 +19,12 @@
</li>
<li class="tab {% block cur_links %}{% endblock %}">
<a href="{{ SITE_ROOT }}sys/publinkadmin/" class="links">{% trans "Links" %}</a>
</li>
</li>
{% if traffic_stats_enabled %}
<li class="tab {% block cur_traffic %}{% endblock %}">
<a href="{{ SITE_ROOT }}sys/trafficadmin/" class="links">{% trans "Traffic" %}</a>
</li>
{% endif %}
</ul>
</div>
{% endblock %}

View File

@ -0,0 +1,68 @@
{% extends "admin_base.html" %}
{% load seahub_tags i18n %}
{% block nav_trafficadmin_class %}class="cur"{% endblock %}
{% block main_panel %}
<form action="{{ sys_traffic_admin }}" method="GET" autocomplete="off">
<label for="month">{% trans "Month (like 201403):" %}</label>
<input type="text" name="month" maxlength="6" value="{{ month }}" />
</form>
<table>
<tr>
<th>{% trans "User" %}</th>
<th>{% trans "Total Usage" %}</th>
<th>{% trans "Shared File View" %}</th>
<th>{% trans "Shared File Download" %}</th>
<th>{% trans "Shared Folder Download" %}</th>
</tr>
{% for info in traffic_info_list %}
<tr>
<td>{{ info.email }}</td>
<td>{{ info.total |filesizeformat }}</td>
<td>{{ info.file_view |filesizeformat }}</td>
<td>{{ info.file_download |filesizeformat }}</td>
<td>{{ info.dir_download |filesizeformat }}</td>
<td></td>
</tr>
{% endfor %}
</table>
<div id="paginator">
{% if current_page != 1 %}
<a href="?page={{ prev_page }}&per_page={{ per_page }}">{% trans "Previous" %}</a>
{% endif %}
{% if page_next %}
<a href="?page={{ next_page }}&per_page={{ per_page }}">{% trans "Next" %}</a>
{% endif %}
{% if current_page != 1 or page_next %}
|
{% endif %}
<span>{% trans "Per page: " %}</span>
{% if per_page == 25 %}
<span> 25 </span>
{% else %}
<a href="?per_page=25" class="per-page">25</a>
{% endif %}
{% if per_page == 50 %}
<span> 50 </span>
{% else %}
<a href="?per_page=50" class="per-page">50</a>
{% endif %}
{% if per_page == 100 %}
<span> 100 </span>
{% else %}
<a href="?per_page=100" class="per-page">100</a>
{% endif %}
</div>
{% endblock %}
{% block extra_script %}
<script type="text/javascript">
$('#paginator a').each(function (index, link) {
link.href = link.href + '&month={{ month }}';
});
</script>
{% endblock %}

View File

@ -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'),
)

View File

@ -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

View File

@ -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))