##// END OF EJS Templates
Parse global id reflinks
neko259 -
r1515:260716a0 decentral
parent child Browse files
Show More
@@ -1,9 +1,9 b''
1 1 import re
2 2 from boards.mdx_neboard import get_parser
3 3
4 from boards.models import Post
4 from boards.models import Post, GlobalId
5 5 from boards.models.post import REGEX_NOTIFICATION
6 from boards.models.post import REGEX_REPLY
6 from boards.models.post import REGEX_REPLY, REGEX_GLOBAL_REPLY
7 7 from boards.models.user import Notification
8 8 from django.db.models.signals import post_save, pre_save, pre_delete, \
9 9 post_delete
@@ -28,6 +28,25 b' def connect_replies(instance, **kwargs):'
28 28
29 29
30 30 @receiver(post_save, sender=Post)
31 def connect_global_replies(instance, **kwargs):
32 for reply_number in re.finditer(REGEX_GLOBAL_REPLY, instance.get_raw_text()):
33 key_type = reply_number.group(1)
34 key = reply_number.group(2)
35 local_id = reply_number.group(3)
36
37 try:
38 global_id = GlobalId.objects.get(key_type=key_type, key=key,
39 local_id=local_id)
40 referenced_post = Post.objects.get(global_id=global_id)
41 referenced_post.referenced_posts.add(instance)
42 referenced_post.last_edit_time = instance.pub_time
43 referenced_post.build_refmap()
44 referenced_post.save(update_fields=['refmap', 'last_edit_time'])
45 except (GlobalId.ObjectDoesNotExist, Post.ObjectDoesNotExist):
46 pass
47
48
49 @receiver(post_save, sender=Post)
31 50 def connect_notifications(instance, **kwargs):
32 51 for reply_number in re.finditer(REGEX_NOTIFICATION, instance.get_raw_text()):
33 52 user_name = reply_number.group(1).lower()
General Comments 0
You need to be logged in to leave comments. Login now