##// END OF EJS Templates
Updated placeholder for the URL input to be more user-friendly
Updated placeholder for the URL input to be more user-friendly

File last commit:

r1750:867beeae default
r1764:ae6e7d4c default
Show More
statistics.py
35 lines | 1.2 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=''):
full_domain = attachment.url.split('/')[2]
domain = get_domain(full_domain)
if domain in domains:
domains[domain] += 1
else:
domains[domain] = 1
for domain in domains:
print('{}: {}'.format(domain, domains[domain]))
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']))