diff options
Diffstat (limited to 'meetingtools/apps')
-rw-r--r-- | meetingtools/apps/auth/utils.py | 14 | ||||
-rw-r--r-- | meetingtools/apps/content/views.py | 44 |
2 files changed, 56 insertions, 2 deletions
diff --git a/meetingtools/apps/auth/utils.py b/meetingtools/apps/auth/utils.py index 0651eba..c792b4a 100644 --- a/meetingtools/apps/auth/utils.py +++ b/meetingtools/apps/auth/utils.py @@ -5,6 +5,8 @@ Created on Jul 7, 2010 """ from uuid import uuid4 +from django.conf import settings as django_settings + def nonce(): return uuid4().hex @@ -19,4 +21,14 @@ def groups(request): if request.user.is_authenticated(): groups = request.user.groups - return groups
\ No newline at end of file + return groups + + +def report_auth(request): + auth_data = request.META.get('HTTP_X_REPORT_AUTH', None) + if auth_data and ':' in auth_data: + report_users = getattr(django_settings, 'REPORT_USERS') + requester, key = auth_data.split(':') + if report_users[requester]['key'] == key: + return report_users[requester] + return False
\ No newline at end of file diff --git a/meetingtools/apps/content/views.py b/meetingtools/apps/content/views.py index bc8abb3..ceec589 100644 --- a/meetingtools/apps/content/views.py +++ b/meetingtools/apps/content/views.py @@ -5,12 +5,14 @@ from django.contrib.auth.decorators import login_required from django.db.models import Sum from django.http import HttpResponseForbidden from django.core.cache import cache -from meetingtools.multiresponse import respond_to +from django.template.defaultfilters import filesizeformat from django.shortcuts import get_object_or_404 from tagging.models import Tag +from meetingtools.multiresponse import respond_to, dicts_to_csv_response from meetingtools.apps.content.models import Content from meetingtools.apps.cluster.models import ACCluster from meetingtools.apps.content import tasks +from meetingtools.apps.auth.utils import report_auth @login_required @@ -66,3 +68,43 @@ def domain(request, domain_name): return respond_to(request, {'text/html': 'apps/content/domain.html'}, {'domain': domain_name, 'total_bytecount': total_bytecount, 'total_files': total_files, 'users': users}) + + +def cluster_report(request, cluster_name): + requester = report_auth(request) + if requester and cluster_name in requester['clusters']: + data = [] + acc = get_object_or_404(ACCluster, name=cluster_name) + domains, total_bytecount = tasks.get_cluster_content(acc) + for item in domains: + value = float(item['domain_bytes']) + max_value = float(total_bytecount) + percent = (value / max_value) * 100 + data.append({ + 'domain': item['domain'], + 'number_of_files': item['number_of_files'], + 'storage_used': filesizeformat(item['domain_bytes']), + 'percent': '{:0.2g}%'.format(percent) + }) + return dicts_to_csv_response(data, header=['domain', 'number_of_files', 'storage_used', 'percent']) + return HttpResponseForbidden() + + +def domain_report(request, domain_name): + requester = report_auth(request) + if requester and (domain_name in requester['domains'] or '*' in requester['domains']): + data = [] + domain_tag = get_object_or_404(Tag, name='domain:%s' % domain_name) + users, total_files, total_bytecount = tasks.get_domain_content(domain_tag) + for item in users: + value = float(item['bytecount']) + max_value = float(total_bytecount) + percent = (value / max_value) * 100 + data.append({ + 'username': item['username'], + 'number_of_files': item['number_of_files'], + 'storage_used': filesizeformat(item['bytecount']), + 'percent': '{:0.2g}%'.format(percent) + }) + return dicts_to_csv_response(data, header=['username', 'number_of_files', 'storage_used', 'percent']) + return HttpResponseForbidden()
\ No newline at end of file |