##// END OF EJS Templates
Parse global id reflinks
neko259 -
r1515:260716a0 decentral
parent child Browse files
Show More
@@ -1,9 +1,9 b''
1 import re
1 import re
2 from boards.mdx_neboard import get_parser
2 from boards.mdx_neboard import get_parser
3
3
4 from boards.models import Post
4 from boards.models import Post, GlobalId
5 from boards.models.post import REGEX_NOTIFICATION
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 from boards.models.user import Notification
7 from boards.models.user import Notification
8 from django.db.models.signals import post_save, pre_save, pre_delete, \
8 from django.db.models.signals import post_save, pre_save, pre_delete, \
9 post_delete
9 post_delete
@@ -28,6 +28,25 b' def connect_replies(instance, **kwargs):'
28
28
29
29
30 @receiver(post_save, sender=Post)
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 def connect_notifications(instance, **kwargs):
50 def connect_notifications(instance, **kwargs):
32 for reply_number in re.finditer(REGEX_NOTIFICATION, instance.get_raw_text()):
51 for reply_number in re.finditer(REGEX_NOTIFICATION, instance.get_raw_text()):
33 user_name = reply_number.group(1).lower()
52 user_name = reply_number.group(1).lower()
General Comments 0
You need to be logged in to leave comments. Login now