##// END OF EJS Templates
First add the truncator (if there is none in the text itself), then closing tags
First add the truncator (if there is none in the text itself), then closing tags

File last commit:

r1782:71d3a47e default
r1788:e1bfd1eb default
Show More
statistics.py
36 lines | 1.3 KiB | text/x-python | PythonLexer
from django.core.management import BaseCommand
from django.db.models import Count
from boards.models import Attachment
from boards.utils import get_domain
class Command(BaseCommand):
help = 'Gather board statistics'
def handle(self, *args, **options):
print('* Domains and their usage')
domains = {}
for attachment in Attachment.objects.exclude(url=''):
domain = get_domain(attachment.url)
if domain in domains:
domains[domain] += 1
else:
domains[domain] = 1
domain_list = [(item, domains[item]) for item in domains.keys()]
domain_list = sorted(domain_list, key=lambda domain: -domain[1])
for domain in domain_list:
print('{}: {}'.format(domain[0], domain[1]))
print('* Overall numbers')
print('{} attachments in the system, {} of them as URLs'.format(
Attachment.objects.count(),
Attachment.objects.exclude(url='').count()))
print('* File types')
mimetypes = Attachment.objects.filter(url='')\
.values('mimetype').annotate(count=Count('id'))\
.order_by('-count')
for mimetype in mimetypes:
print('{}: {}'.format(mimetype['mimetype'], mimetype['count']))