##// END OF EJS Templates
Image deduplication (BB-53). When an image with the same hash is uploaded, it...
neko259 -
r944:6ed17cb6 default
parent child Browse files
Show More
@@ -22,8 +22,6 b" LAST_LOGIN_TIME = 'last_login_time'"
22 22 TEXT_PLACEHOLDER = _('Type message here. Use formatting panel for more advanced usage.')
23 23 TAGS_PLACEHOLDER = _('tag1 several_words_tag')
24 24
25 ERROR_IMAGE_DUPLICATE = _('Such image was already posted')
26
27 25 LABEL_TITLE = _('Title')
28 26 LABEL_TEXT = _('Text')
29 27 LABEL_TAG = _('Tag')
@@ -149,10 +147,6 b' class PostForm(NeboardForm):'
149 147 _('Image must be less than %s bytes')
150 148 % str(board_settings.MAX_IMAGE_SIZE))
151 149
152 image_hash = PostImage.get_hash(image)
153 if PostImage.objects.filter(hash=image_hash).exists():
154 raise forms.ValidationError(ERROR_IMAGE_DUPLICATE)
155
156 150 return image
157 151
158 152 def clean(self):
@@ -103,10 +103,17 b' class PostManager(models.Manager):'
103 103 post, post.poster_ip))
104 104
105 105 if image:
106 # Try to find existing image. If it exists, assign it to the post
107 # instead of createing the new one
108 image_hash = PostImage.get_hash(image)
109 existing = PostImage.objects.filter(hash=image_hash)
110 if len(existing) > 0:
111 post_image = existing[0]
112 else:
106 113 post_image = PostImage.objects.create(image=image)
114 logger.info('Created new image #{} for post #{}'.format(
115 post_image.id, post.id))
107 116 post.images.add(post_image)
108 logger.info('Created image #{} for post #{}'.format(
109 post_image.id, post.id))
110 117
111 118 thread.replies.add(post)
112 119 list(map(thread.add_tag, tags))
@@ -352,7 +359,10 b' class Post(models.Model, Viewable):'
352 359 thread with all posts is deleted.
353 360 """
354 361
355 self.images.all().delete()
362 for image in self.images.all():
363 image_refs_count = Post.objects.filter(images__in=[image]).count()
364 if image_refs_count == 1:
365 image.delete()
356 366
357 367 if self.is_opening():
358 368 self.get_thread().delete()
General Comments 0
You need to be logged in to leave comments. Login now