diff options
| -rw-r--r-- | meetingtools/apps/content/templatetags/__init__.py | 2 | ||||
| -rw-r--r-- | meetingtools/apps/content/templatetags/content_tags.py | 21 | ||||
| -rw-r--r-- | meetingtools/apps/content/views.py | 24 | ||||
| -rw-r--r-- | meetingtools/urls.py | 1 | ||||
| -rw-r--r-- | templates/apps/content/user.html | 46 | 
5 files changed, 94 insertions, 0 deletions
| diff --git a/meetingtools/apps/content/templatetags/__init__.py b/meetingtools/apps/content/templatetags/__init__.py new file mode 100644 index 0000000..3250cb8 --- /dev/null +++ b/meetingtools/apps/content/templatetags/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +__author__ = 'lundberg' diff --git a/meetingtools/apps/content/templatetags/content_tags.py b/meetingtools/apps/content/templatetags/content_tags.py new file mode 100644 index 0000000..29cb98e --- /dev/null +++ b/meetingtools/apps/content/templatetags/content_tags.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +__author__ = 'lundberg' + +from django import template +import math + +register = template.Library() + + +def humanize_bytes(b): +    try: +        size_name = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') +        i = int(math.floor(math.log(b, 1024))) +        p = math.pow(1024, i) +        s = round(b / p, 2) +        if s > 0: +            return '%s %s' % (s, size_name[i]) +    except TypeError: +        return 'TypeError' + +register.filter('humanize_bytes', humanize_bytes)
\ No newline at end of file diff --git a/meetingtools/apps/content/views.py b/meetingtools/apps/content/views.py new file mode 100644 index 0000000..c830af0 --- /dev/null +++ b/meetingtools/apps/content/views.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +__author__ = 'lundberg' + +from django.contrib.auth.decorators import login_required +from django.db.models import Sum +from django.contrib.humanize.templatetags.humanize import naturalday +from django.http import HttpResponseForbidden, HttpResponseBadRequest +from meetingtools.apps.stats.models import UserMeetingTransaction +from iso8601 import iso8601 +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 meetingtools.apps.content.models import Content + + +@login_required +def user(request, username=None): +    if username is None: +        username = request.user.username +    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 diff --git a/meetingtools/urls.py b/meetingtools/urls.py index 762114a..6db9934 100644 --- a/meetingtools/urls.py +++ b/meetingtools/urls.py @@ -61,4 +61,5 @@ urlpatterns = patterns('',      (r'^stats/user/(.+)$','meetingtools.apps.stats.views.user'),      (r'^stats/domain/(.+)$','meetingtools.apps.stats.views.domain'),      (r'^stats/room/(\d+)$','meetingtools.apps.stats.views.room'), +    (r'^content$', 'meetingtools.apps.content.views.user'),  ) diff --git a/templates/apps/content/user.html b/templates/apps/content/user.html new file mode 100644 index 0000000..b02ad77 --- /dev/null +++ b/templates/apps/content/user.html @@ -0,0 +1,46 @@ +{% 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> +        $(document).ready(function() { +            $('#content').dataTable(); +        }); +    </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 }} +</div> + <br> + <br> +<div> +    <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="content"> +        <thead> +            <tr> +                <th>Created</th><th>Name</th><th>Type</th><th>Filesize</th><th>Modified</th><th>Views</th><th>Last viewed</th> +            </tr> +        </thead> +        <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.type }}</td> + +                <td>{{ item.bytecount|humanize_bytes }}</td> +                <td>{{ item.modified }}</td> +                <td>{{ item.views }}</td> +                <td>{{ item.lastviewed }}</td> +            </tr> +        {% endfor %} +        </tbody> +    </table> +</div> +{% endblock %} + +{% block widgets %} + +{% endblock %}
\ No newline at end of file | 
