##// END OF EJS Templates
Merged with default branch
neko259 -
r1543:9a0b5221 merge decentral
parent child Browse files
Show More
@@ -10,7 +10,7 b' class PostAdmin(admin.ModelAdmin):'
10 10 list_display = ('id', 'title', 'text', 'poster_ip', 'linked_images')
11 11 list_filter = ('pub_time',)
12 12 search_fields = ('id', 'title', 'text', 'poster_ip')
13 exclude = ('referenced_posts', 'refmap')
13 exclude = ('referenced_posts', 'refmap', 'images')
14 14 readonly_fields = ('poster_ip', 'threads', 'thread', 'linked_images',
15 15 'attachments', 'uid', 'url', 'pub_time', 'opening')
16 16
@@ -38,7 +38,10 b' class PostAdmin(admin.ModelAdmin):'
38 38
39 39 def linked_images(self, obj: Post):
40 40 images = obj.images.all()
41 image_urls = ['<a href="{}">{}</a>'.format(reverse('admin:%s_%s_change' %(image._meta.app_label, image._meta.model_name), args=[image.id]), image.hash) for image in images]
41 image_urls = ['<a href="{}"><img src="{}" /></a>'.format(
42 reverse('admin:%s_%s_change' % (image._meta.app_label,
43 image._meta.model_name),
44 args=[image.id]), image.image.url_200x150) for image in images]
42 45 return ', '.join(image_urls)
43 46 linked_images.allow_tags = True
44 47
@@ -379,3 +379,32 b' class Post(models.Model, Viewable):'
379 379
380 380 def set_hidden(self, hidden):
381 381 self.hidden = hidden
382
383
384 # SIGNALS (Maybe move to other module?)
385 @receiver(post_save, sender=Post)
386 def connect_replies(instance, **kwargs):
387 for reply_number in re.finditer(REGEX_REPLY, instance.get_raw_text()):
388 post_id = reply_number.group(1)
389
390 try:
391 referenced_post = Post.objects.get(id=post_id)
392
393 referenced_post.referenced_posts.add(instance)
394 referenced_post.last_edit_time = instance.pub_time
395 referenced_post.build_refmap()
396 referenced_post.save(update_fields=['refmap', 'last_edit_time'])
397 except ObjectDoesNotExist:
398 pass
399
400
401 @receiver(post_save, sender=Post)
402 def connect_notifications(instance, **kwargs):
403 for reply_number in re.finditer(REGEX_NOTIFICATION, instance.get_raw_text()):
404 user_name = reply_number.group(1).lower()
405 Notification.objects.get_or_create(name=user_name, post=instance)
406
407
408 @receiver(pre_save, sender=Post)
409 def preparse_text(instance, **kwargs):
410 instance._text_rendered = get_parser().parse(instance.get_raw_text())
@@ -19,6 +19,7 b' def connect_replies(instance, **kwargs):'
19 19 try:
20 20 referenced_post = Post.objects.get(id=post_id)
21 21
22 if not referenced_post.referenced_posts.filter(id=instance.id).exists():
22 23 referenced_post.referenced_posts.add(instance)
23 24 referenced_post.last_edit_time = instance.pub_time
24 25 referenced_post.build_refmap()
General Comments 0
You need to be logged in to leave comments. Login now