# HG changeset patch # User neko259 # Date 2016-12-26 08:54:08 # Node ID 2927138ce6bef8f5ccc9dcb920af734e6731cc4b # Parent 8c19026d270e9fca704a7fcb315c925e6483480c Added statistics management command diff --git a/boards/management/commands/statistics.py b/boards/management/commands/statistics.py new file mode 100644 --- /dev/null +++ b/boards/management/commands/statistics.py @@ -0,0 +1,28 @@ +from django.core.management import BaseCommand + +from boards.models import Attachment +from boards.utils import get_domain + + +class Command(BaseCommand): + help = 'Gather board statistics' + + def handle(self, *args, **options): + domains = {} + for attachment in Attachment.objects.exclude(url=None): + full_domain = attachment.url.split('/')[2] + domain = get_domain(full_domain) + if domain in domains: + domains[domain] += 1 + else: + domains[domain] = 1 + + print('* Domains and their usage') + 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=None).count())) + diff --git a/boards/models/attachment/viewers.py b/boards/models/attachment/viewers.py --- a/boards/models/attachment/viewers.py +++ b/boards/models/attachment/viewers.py @@ -11,6 +11,7 @@ from boards.utils import get_domain FILE_STUB_IMAGE = 'images/file.png' FILE_STUB_URL = 'url' + FILE_TYPES_VIDEO = ( 'webm', 'mp4',