summaryrefslogtreecommitdiff
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
parent58eae4e6c78bc69c20795da5a96fe2e251e47bf5 (diff)
Added more views for content.
-rw-r--r--meetingtools/apps/content/views.py64
-rw-r--r--templates/apps/content/cluster.html59
-rw-r--r--templates/apps/content/domain.html50
-rw-r--r--templates/apps/content/user.html27
-rw-r--r--templates/base.html6
5 files changed, 194 insertions, 12 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})
diff --git a/templates/apps/content/cluster.html b/templates/apps/content/cluster.html
new file mode 100644
index 0000000..6d30690
--- /dev/null
+++ b/templates/apps/content/cluster.html
@@ -0,0 +1,59 @@
+{% extends "base.html" %}
+{% block js %}
+ <link href="{{STATIC_URL}}/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
+ <script type="text/javascript" src="{{STATIC_URL}}/js/jquery.dataTables.min.js"></script>
+ <script type="text/javascript" src="{{STATIC_URL}}/js/dataTables.fileSize.js"></script>
+ <script type="text/javascript" src="{{STATIC_URL}}/js/dataTables.percent.js"></script>
+ <script>
+ $(document).ready(function() {
+ $('#content').dataTable({
+ "aoColumns": [
+ null,
+ null,
+ { "sType": "file-size" },
+ { "sType": "percent" }
+ ]
+ });
+ });
+ </script>
+{% endblock %}
+{% block content %}
+<ul class="nav nav-pills">
+{% for cluster in clusters %}
+ <li class="{% if cluster.name == cluster_name %}active{% else %}{% endif %}">
+ <a href="{{ cluster.name }}">{{ cluster.name }}</a>
+ </li>
+{% endfor %}
+</ul>
+{% if cluster_name %}
+ <h1>Storage for {{cluster_name}}</h1>
+ <div>
+ <strong>Total storage:</strong> {{ total_bytecount|filesizeformat }}
+ </div>
+ <br>
+ <br>
+ <div>
+ <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="content">
+ <thead>
+ <tr>
+ <th>Domain</th><th>Number of files</th><th>Storage used</th><th>Percent</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for domain in domains %}
+ <tr>
+ <td><a href="../domain/{{ domain.domain }}">{{ domain.domain }}</a></td>
+ <td>{{ domain.number_of_files }}</td>
+ <td>{{ domain.domain_bytes|filesizeformat}}</td>
+ <td>{% widthratio domain.domain_bytes total_bytecount 100 %}%</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+{% endif %}
+{% endblock %}
+
+{% block widgets %}
+
+{% endblock %} \ No newline at end of file
diff --git a/templates/apps/content/domain.html b/templates/apps/content/domain.html
new file mode 100644
index 0000000..5efd236
--- /dev/null
+++ b/templates/apps/content/domain.html
@@ -0,0 +1,50 @@
+{% extends "base.html" %}
+{% block js %}
+ <link href="{{STATIC_URL}}/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
+ <script type="text/javascript" src="{{STATIC_URL}}/js/jquery.dataTables.min.js"></script>
+ <script type="text/javascript" src="{{STATIC_URL}}/js/dataTables.fileSize.js"></script>
+ <script type="text/javascript" src="{{STATIC_URL}}/js/dataTables.percent.js"></script>
+ <script>
+ $(document).ready(function() {
+ $('#content').dataTable({
+ "aoColumns": [
+ null,
+ null,
+ { "sType": "file-size" },
+ { "sType": "percent" }
+ ]
+ });
+ });
+ </script>
+{% endblock %}
+{% block content %}
+<h1>Content for {{domain}}</h1>
+<div>
+ <strong>Number of files:</strong> {{ total_files }} | <strong>Total storage:</strong> {{ total_bytecount|filesizeformat }}
+</div>
+ <br>
+ <br>
+<div>
+ <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="content">
+ <thead>
+ <tr>
+ <th>Username</th><th>Number of files</th><th>Storage used</th><th>Percent</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for user in users %}
+ <tr>
+ <td>{{ user.username }}</td>
+ <td>{{ user.number_of_files }}</td>
+ <td>{{ user.bytecount|filesizeformat }}</td>
+ <td>{% widthratio user.bytecount total_bytecount 100 %}%</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+</div>
+{% endblock %}
+
+{% block widgets %}
+
+{% endblock %} \ No newline at end of file
diff --git a/templates/apps/content/user.html b/templates/apps/content/user.html
index b02ad77..697bba7 100644
--- a/templates/apps/content/user.html
+++ b/templates/apps/content/user.html
@@ -2,17 +2,28 @@
{% block js %}
<link href="{{STATIC_URL}}/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="{{STATIC_URL}}/js/jquery.dataTables.min.js"></script>
+ <script type="text/javascript" src="{{STATIC_URL}}/js/dataTables.fileSize.js"></script>
+ <script type="text/javascript" src="{{STATIC_URL}}/js/dataTables.dateEuro.js"></script>
<script>
$(document).ready(function() {
- $('#content').dataTable();
+ $('#content').dataTable({
+ "aoColumns": [
+ { "sType": "date-euro" },
+ null,
+ null,
+ { "sType": "file-size" },
+ { "sType": "date-euro" },
+ null,
+ { "sType": "date-euro" }
+ ]
+ });
});
</script>
{% endblock %}
-{% load content_tags %}
{% block content %}
<h1>Content for {{username}}</h1>
<div>
- <strong>Number of files:</strong> {{ content|length }} | <strong>Total storage:</strong> {{ total_bytecount.bytecount__sum|humanize_bytes }}
+ <strong>Number of files:</strong> {{ content|length }} | <strong>Total storage:</strong> {{ total_bytecount.bytecount__sum|filesizeformat }}
</div>
<br>
<br>
@@ -26,14 +37,14 @@
<tbody>
{% for item in content %}
<tr>
- <td>{{ item.created }}</td>
- <td>{{ item.name }} <a href="{{ item.download_url }}"><i class="icon-download"></i></a></td>
+ <td>{{ item.created|date:"d/m/Y H:i:s" }}</td>
+ <td><a href="{{ item.go_url }}">{{ item.name }}</a> <a href="{{ item.download_url }}"><i class="icon-download"></i></a></td>
<td>{{ item.type }}</td>
- <td>{{ item.bytecount|humanize_bytes }}</td>
- <td>{{ item.modified }}</td>
+ <td>{{ item.bytecount|filesizeformat }}</td>
+ <td>{{ item.modified|date:"d/m/Y H:i:s" }}</td>
<td>{{ item.views }}</td>
- <td>{{ item.lastviewed }}</td>
+ <td>{{ item.lastviewed|date:"d/m/Y H:i:s" }}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/templates/base.html b/templates/base.html
index 90d516e..e0c4695 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -87,8 +87,12 @@
<div class="span3">
<ul class="unstyled">
<li><h3>Users</h3></li>
- <li><a class="tip" title="Your list of meeting resources.." href="/rooms">My Profile</a></li>
+ <li><a class="tip" title="Your list of meeting resources..." href="/rooms">My Profile</a></li>
+ <li><a class="tip" title="Your list of uploaded files and recordings..." href="/content">My Files</a></li>
<li><a class="tip" title="Find out how much you use e-meetings..." href="/stats">Usage Statistics</a></li>
+ {% if user.is_staff %}
+ <li><a class="tip" title="Find out how much data each cluster stores..." href="/content/cluster">Cluster Storage</a></li>
+ {% endif %}
<li><a class="tip" title="Logout" id="logout" href="/accounts/logout">Logout</a></li>
</ul>
</div>