Show More
@@ -1,4 +1,11 b'' | |||
|
1 | 1 | import re |
|
2 | import os | |
|
3 | ||
|
4 | from django.db.models.signals import post_save, pre_save, pre_delete, \ | |
|
5 | post_delete | |
|
6 | from django.dispatch import receiver | |
|
7 | from django.utils import timezone | |
|
8 | ||
|
2 | 9 | from boards import thumbs |
|
3 | 10 | from boards.mdx_neboard import get_parser |
|
4 | 11 | |
@@ -8,10 +15,7 b' from boards.models.post import REGEX_NOT' | |||
|
8 | 15 | REGEX_GLOBAL_REPLY |
|
9 | 16 | from boards.models.post.manager import post_import_deps |
|
10 | 17 | from boards.models.user import Notification |
|
11 | from django.db.models.signals import post_save, pre_save, pre_delete, \ | |
|
12 | post_delete | |
|
13 | from django.dispatch import receiver | |
|
14 | from django.utils import timezone | |
|
18 | from neboard.settings import MEDIA_ROOT | |
|
15 | 19 | |
|
16 | 20 | |
|
17 | 21 | THUMB_SIZES = ((200, 150),) |
@@ -113,3 +117,16 b' def rebuild_refmap(instance, **kwargs):' | |||
|
113 | 117 | for referenced_post in instance.refposts.all(): |
|
114 | 118 | referenced_post.build_refmap(excluded_ids=[instance.id]) |
|
115 | 119 | referenced_post.save(update_fields=['refmap']) |
|
120 | ||
|
121 | ||
|
122 | @receiver(post_delete, sender=Attachment) | |
|
123 | def delete_file(instance, **kwargs): | |
|
124 | if instance.is_internal(): | |
|
125 | file = MEDIA_ROOT + instance.file.name | |
|
126 | os.remove(file) | |
|
127 | if instance.mimetype in FILE_TYPES_IMAGE: | |
|
128 | for size in THUMB_SIZES: | |
|
129 | file_name_parts = instance.file.name.split('.') | |
|
130 | thumb_file = MEDIA_ROOT + '{}.{}x{}.{}'.format(file_name_parts[0], *size, file_name_parts[1]) | |
|
131 | os.remove(thumb_file) | |
|
132 |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now