# HG changeset patch # User neko259 # Date 2016-05-04 13:33:38 # Node ID 260716a03425b5097bfd946c3da3a8dbe80e398c # Parent 2edb321f314f6ece1054829cd21a86800f45666f Parse global id reflinks diff --git a/boards/signals.py b/boards/signals.py --- a/boards/signals.py +++ b/boards/signals.py @@ -1,9 +1,9 @@ import re from boards.mdx_neboard import get_parser -from boards.models import Post +from boards.models import Post, GlobalId from boards.models.post import REGEX_NOTIFICATION -from boards.models.post import REGEX_REPLY +from boards.models.post import REGEX_REPLY, REGEX_GLOBAL_REPLY from boards.models.user import Notification from django.db.models.signals import post_save, pre_save, pre_delete, \ post_delete @@ -28,6 +28,25 @@ def connect_replies(instance, **kwargs): @receiver(post_save, sender=Post) +def connect_global_replies(instance, **kwargs): + for reply_number in re.finditer(REGEX_GLOBAL_REPLY, instance.get_raw_text()): + key_type = reply_number.group(1) + key = reply_number.group(2) + local_id = reply_number.group(3) + + try: + global_id = GlobalId.objects.get(key_type=key_type, key=key, + local_id=local_id) + referenced_post = Post.objects.get(global_id=global_id) + referenced_post.referenced_posts.add(instance) + referenced_post.last_edit_time = instance.pub_time + referenced_post.build_refmap() + referenced_post.save(update_fields=['refmap', 'last_edit_time']) + except (GlobalId.ObjectDoesNotExist, Post.ObjectDoesNotExist): + pass + + +@receiver(post_save, sender=Post) def connect_notifications(instance, **kwargs): for reply_number in re.finditer(REGEX_NOTIFICATION, instance.get_raw_text()): user_name = reply_number.group(1).lower()