# HG changeset patch # User neko259 # Date 2016-05-18 15:57:04 # Node ID b69fb39690aab5e09de2e8acd05eed0ce2cc4aee # Parent 5262969cc2558455a33b687b7f48f0217ba42219 Added support for partial import: when the reply is imported but the original post is not, the reply will be connected after the original post is ready diff --git a/boards/models/post/manager.py b/boards/models/post/manager.py --- a/boards/models/post/manager.py +++ b/boards/models/post/manager.py @@ -5,6 +5,7 @@ from datetime import time as dtime from django.db import models, transaction from django.utils import timezone +from django.dispatch import Signal import boards @@ -27,6 +28,9 @@ POSTS_PER_DAY_RANGE = 7 NO_IP = '0.0.0.0' +post_import_deps = Signal() + + class PostManager(models.Manager): @transaction.atomic def create_post(self, title: str, text: str, file=None, thread=None, @@ -155,6 +159,11 @@ class PostManager(models.Manager): post.threads.add(thread) + url_to_post = '[post]{}[/post]'.format(str(global_id)) + replies = self.filter(text__contains=url_to_post) + for reply in replies: + post_import_deps.send(reply.__class__) + @transaction.atomic def update_post(self, post, title: str, text: str, pub_time: str, tags=list(), files=list(), tripcode=None, version=1): diff --git a/boards/signals.py b/boards/signals.py --- a/boards/signals.py +++ b/boards/signals.py @@ -2,8 +2,9 @@ import re from boards.mdx_neboard import get_parser from boards.models import Post, GlobalId -from boards.models.post import REGEX_NOTIFICATION -from boards.models.post import REGEX_REPLY, REGEX_GLOBAL_REPLY +from boards.models.post import REGEX_NOTIFICATION, REGEX_REPLY,\ + REGEX_GLOBAL_REPLY +from boards.models.post.manager import post_import_deps from boards.models.user import Notification from django.db.models.signals import post_save, pre_save, pre_delete, \ post_delete @@ -30,6 +31,7 @@ def connect_replies(instance, **kwargs): @receiver(post_save, sender=Post) +@receiver(post_import_deps, 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) @@ -56,7 +58,8 @@ def connect_notifications(instance, **kw @receiver(pre_save, sender=Post) -def preparse_text(instance, **kwargs): +@receiver(post_import_deps, sender=Post) +def parse_text(instance, **kwargs): instance._text_rendered = get_parser().parse(instance.get_raw_text())