/
0003_attachment_types.py
101 lines (92 loc) · 2.48 KB
/
0003_attachment_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-10-04 21:41
from __future__ import unicode_literals
from django.db import migrations
ATTACHMENTS = [
{
'name': 'GIF',
'extensions': ('gif', ),
'mimetypes': ('image/gif', ),
'size_limit': 5 * 1024
},
{
'name': 'JPG',
'extensions': ('jpg', 'jpeg', ),
'mimetypes': ('image/jpeg', ),
'size_limit': 3 * 1024
},
{
'name': 'PNG',
'extensions': ('png', ),
'mimetypes': ('image/png', ),
'size_limit': 3 * 1024
},
{
'name': 'PDF',
'extensions': ('pdf', ),
'mimetypes': ('application/pdf', 'application/x-pdf', 'application/x-bzpdf', 'application/x-gzpdf',),
'size_limit': 4 * 1024
},
{
'name': 'Text',
'extensions': ('txt', ),
'mimetypes': ('text/plain', ),
'size_limit': 4 * 1024
},
{
'name': 'Markdown',
'extensions': ('md', ),
'mimetypes': ('text/markdown', ),
'size_limit': 4 * 1024
},
{
'name': 'reStructuredText',
'extensions': ('rst', ),
'mimetypes': ('text/x-rst', ),
'size_limit': 4 * 1024
},
{
'name': '7Z',
'extensions': ('7z', ),
'mimetypes': ('application/x-7z-compressed', ),
'size_limit': 4 * 1024
},
{
'name': 'RAR',
'extensions': ('rar', ),
'mimetypes': ('application/vnd.rar', ),
'size_limit': 4 * 1024
},
{
'name': 'TAR',
'extensions': ('tar', ),
'mimetypes': ('application/x-tar', ),
'size_limit': 4 * 1024
},
{
'name': 'GZ',
'extensions': ('gz', ),
'mimetypes': ('application/gzip', ),
'size_limit': 4 * 1024
},
{
'name': 'ZIP',
'extensions': ('zip', 'zipx', ),
'mimetypes': ('application/zip', ),
'size_limit': 4 * 1024
},
]
def create_attachment_types(apps, schema_editor):
AttachmentType = apps.get_model('misago_threads', 'AttachmentType')
for attachment in ATTACHMENTS:
kwargs = attachment
kwargs['extensions'] = ','.join(kwargs['extensions'])
kwargs['mimetypes'] = ','.join(kwargs['mimetypes'])
AttachmentType.objects.create(**kwargs)
class Migration(migrations.Migration):
dependencies = [
('misago_threads', '0002_threads_settings'),
]
operations = [
migrations.RunPython(create_attachment_types),
]