summaryrefslogtreecommitdiff
path: root/meetingtools
diff options
context:
space:
mode:
authorJohan Lundberg <lundberg@nordu.net>2014-04-02 17:25:00 +0200
committerJohan Lundberg <lundberg@nordu.net>2014-04-02 17:25:00 +0200
commit6acc69b519422171eb661edbe192bf2074ce6d8f (patch)
tree7019e88b74a2d38a75d6d3db22f1bad90323ae1e /meetingtools
parent58eae4e6c78bc69c20795da5a96fe2e251e47bf5 (diff)
Added more views for content.
Diffstat (limited to 'meetingtools')
-rw-r--r--meetingtools/apps/content/views.py64
1 files changed, 61 insertions, 3 deletions
diff --git a/meetingtools/apps/content/views.py b/meetingtools/apps/content/views.py
index c830af0..7bc0792 100644
--- a/meetingtools/apps/content/views.py
+++ b/meetingtools/apps/content/views.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
__author__ = 'lundberg'
-from django.contrib.auth.decorators import login_required
-from django.db.models import Sum
+from django.contrib.auth.decorators import login_required, permission_required
+from django.db.models import Sum, Count
+from django.contrib.auth.models import User
from django.contrib.humanize.templatetags.humanize import naturalday
from django.http import HttpResponseForbidden, HttpResponseBadRequest
from meetingtools.apps.stats.models import UserMeetingTransaction
@@ -11,7 +12,9 @@ from time import mktime
from meetingtools.multiresponse import json_response, respond_to
from meetingtools.apps.stats.forms import StatCaledarForm
from django.shortcuts import get_object_or_404
+from tagging.models import Tag, TaggedItem
from meetingtools.apps.content.models import Content
+from meetingtools.apps.cluster.models import ACCluster
@login_required
@@ -21,4 +24,59 @@ def user(request, username=None):
content = Content.objects.filter(creator__username=username)
total_bytecount = content.aggregate(Sum('bytecount'))
return respond_to(request,{'text/html': 'apps/content/user.html'},
- {'username': username, 'content': content, 'total_bytecount': total_bytecount}) \ No newline at end of file
+ {'username': username, 'content': content, 'total_bytecount': total_bytecount})
+
+
+@login_required
+def cluster(request, cluster_name=None):
+
+ if not request.user.is_staff:
+ return HttpResponseForbidden
+
+ clusters = ACCluster.objects.all().values('name')
+ if cluster_name:
+ total_bytecount = 0
+ domains = []
+ acc = get_object_or_404(ACCluster, name=cluster_name)
+ tags = Tag.objects.usage_for_model(Content, filters={'sco__acc': acc})
+ for tag in sorted(tags):
+ if tag.name.startswith('domain:'):
+ qs = TaggedItem.objects.get_by_model(Content, tag)
+ d = {
+ 'domain': tag.name.split('domain:')[1],
+ 'domain_bytes': qs.aggregate(Sum('bytecount'))['bytecount__sum'],
+ 'number_of_files': len(qs)
+ }
+ total_bytecount += d['domain_bytes']
+ domains.append(d)
+ return respond_to(request, {'text/html': 'apps/content/cluster.html'},
+ {'clusters': clusters, 'cluster_name': cluster_name, 'domains': domains,
+ 'total_bytecount': total_bytecount})
+
+ return respond_to(request, {'text/html': 'apps/content/cluster.html'},
+ {'clusters': clusters})
+
+
+@login_required
+def domain(request, domain_name):
+
+ if not request.user.is_staff:
+ return HttpResponseForbidden
+
+ users = []
+ tag = get_object_or_404(Tag, name='domain:%s' % domain_name)
+ qs = TaggedItem.objects.get_by_model(Content, tag)
+ total_files = len(qs)
+ total_bytecount = qs.aggregate(Sum('bytecount'))['bytecount__sum']
+ creators = qs.values('creator').annotate(num_files=Count('creator'))
+ for creator in creators:
+ domain_user = get_object_or_404(User, pk=creator['creator'])
+ d = {
+ 'username': domain_user.username,
+ 'number_of_files': creator['num_files'],
+ 'bytecount': Content.objects.filter(creator=domain_user).aggregate(Sum('bytecount'))['bytecount__sum']
+ }
+ users.append(d)
+ return respond_to(request, {'text/html': 'apps/content/domain.html'},
+ {'domain': domain_name, 'total_bytecount': total_bytecount, 'total_files': total_files,
+ 'users': users})