Show More
@@ -1,35 +1,35 b'' | |||
|
1 | 1 | from django.core.management import BaseCommand |
|
2 | 2 | from django.db.models import Count |
|
3 | 3 | |
|
4 | 4 | from boards.models import Attachment |
|
5 | 5 | from boards.utils import get_domain |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | class Command(BaseCommand): |
|
9 | 9 | help = 'Gather board statistics' |
|
10 | 10 | |
|
11 | 11 | def handle(self, *args, **options): |
|
12 | 12 | print('* Domains and their usage') |
|
13 | 13 | domains = {} |
|
14 | for attachment in Attachment.objects.exclude(url=None): | |
|
14 | for attachment in Attachment.objects.exclude(url=None).exclude(url=''): | |
|
15 | 15 | full_domain = attachment.url.split('/')[2] |
|
16 | 16 | domain = get_domain(full_domain) |
|
17 | 17 | if domain in domains: |
|
18 | 18 | domains[domain] += 1 |
|
19 | 19 | else: |
|
20 | 20 | domains[domain] = 1 |
|
21 | 21 | |
|
22 | 22 | for domain in domains: |
|
23 | 23 | print('{}: {}'.format(domain, domains[domain])) |
|
24 | 24 | |
|
25 | 25 | print('* Overall numbers') |
|
26 | 26 | print('{} attachments in the system, {} of them as URLs'.format( |
|
27 | 27 | Attachment.objects.count(), |
|
28 | 28 | Attachment.objects.exclude(url=None).count())) |
|
29 | 29 | |
|
30 | 30 | print('* File types') |
|
31 | 31 | mimetypes = Attachment.objects.filter(url=None)\ |
|
32 | 32 | .values('mimetype').annotate(count=Count('id'))\ |
|
33 | 33 | .order_by('-count') |
|
34 | 34 | for mimetype in mimetypes: |
|
35 | 35 | print('{}: {}'.format(mimetype['mimetype'], mimetype['count'])) |
General Comments 0
You need to be logged in to leave comments.
Login now