##// END OF EJS Templates
Allow deleting aliases
neko259 -
r1750:867beeae default
parent child Browse files
Show More
@@ -0,0 +1,25 b''
1 # -*- coding: utf-8 -*-
2 # Generated by Django 1.10.4 on 2016-12-28 20:44
3 from __future__ import unicode_literals
4
5 from django.db import migrations, models
6
7
8 class Migration(migrations.Migration):
9
10 dependencies = [
11 ('boards', '0053_auto_20161127_1541'),
12 ]
13
14 operations = [
15 migrations.AlterField(
16 model_name='attachment',
17 name='alias',
18 field=models.TextField(null=True, unique=True),
19 ),
20 migrations.AlterField(
21 model_name='attachment',
22 name='url',
23 field=models.TextField(blank=True, default=''),
24 ),
25 ]
@@ -148,9 +148,17 b' class BannerAdmin(admin.ModelAdmin):'
148
148
149 @admin.register(Attachment)
149 @admin.register(Attachment)
150 class AttachmentAdmin(admin.ModelAdmin):
150 class AttachmentAdmin(admin.ModelAdmin):
151 list_display = ('mimetype', 'file', 'url', 'alias')
151 list_display = ('__str__', 'mimetype', 'file', 'url', 'alias')
152 search_fields = ('alias',)
152 search_fields = ('alias',)
153
153
154 def delete_alias(self, request, queryset):
155 for attachment in queryset:
156 attachment.alias = None
157 attachment.save(update_fields=['alias'])
158 self.message_user(request, _('Aliases removed'))
159
160 actions = ['delete_alias']
161
154
162
155 @admin.register(GlobalId)
163 @admin.register(GlobalId)
156 class GlobalIdAdmin(admin.ModelAdmin):
164 class GlobalIdAdmin(admin.ModelAdmin):
@@ -11,7 +11,7 b' class Command(BaseCommand):'
11 def handle(self, *args, **options):
11 def handle(self, *args, **options):
12 print('* Domains and their usage')
12 print('* Domains and their usage')
13 domains = {}
13 domains = {}
14 for attachment in Attachment.objects.exclude(url=None).exclude(url=''):
14 for attachment in Attachment.objects.exclude(url=''):
15 full_domain = attachment.url.split('/')[2]
15 full_domain = attachment.url.split('/')[2]
16 domain = get_domain(full_domain)
16 domain = get_domain(full_domain)
17 if domain in domains:
17 if domain in domains:
@@ -25,10 +25,10 b' class Command(BaseCommand):'
25 print('* Overall numbers')
25 print('* Overall numbers')
26 print('{} attachments in the system, {} of them as URLs'.format(
26 print('{} attachments in the system, {} of them as URLs'.format(
27 Attachment.objects.count(),
27 Attachment.objects.count(),
28 Attachment.objects.exclude(url=None).count()))
28 Attachment.objects.exclude(url='').count()))
29
29
30 print('* File types')
30 print('* File types')
31 mimetypes = Attachment.objects.filter(url=None)\
31 mimetypes = Attachment.objects.filter(url='')\
32 .values('mimetype').annotate(count=Count('id'))\
32 .values('mimetype').annotate(count=Count('id'))\
33 .order_by('-count')
33 .order_by('-count')
34 for mimetype in mimetypes:
34 for mimetype in mimetypes:
@@ -45,8 +45,8 b' class Attachment(models.Model):'
45 file = models.FileField(upload_to=get_upload_filename, null=True)
45 file = models.FileField(upload_to=get_upload_filename, null=True)
46 mimetype = models.CharField(max_length=50, null=True)
46 mimetype = models.CharField(max_length=50, null=True)
47 hash = models.CharField(max_length=36, null=True)
47 hash = models.CharField(max_length=36, null=True)
48 alias = models.TextField(unique=True, null=True, blank=True)
48 alias = models.TextField(unique=True, null=True)
49 url = models.TextField(null=True, blank=True)
49 url = models.TextField(blank=True, default='')
50
50
51 def get_view(self):
51 def get_view(self):
52 file_viewer = None
52 file_viewer = None
General Comments 0
You need to be logged in to leave comments. Login now