Show More
@@ -5,6 +5,7 from datetime import time as dtime | |||||
5 |
|
5 | |||
6 | from django.db import models, transaction |
|
6 | from django.db import models, transaction | |
7 | from django.utils import timezone |
|
7 | from django.utils import timezone | |
|
8 | from django.dispatch import Signal | |||
8 |
|
9 | |||
9 | import boards |
|
10 | import boards | |
10 |
|
11 | |||
@@ -27,6 +28,9 POSTS_PER_DAY_RANGE = 7 | |||||
27 | NO_IP = '0.0.0.0' |
|
28 | NO_IP = '0.0.0.0' | |
28 |
|
29 | |||
29 |
|
30 | |||
|
31 | post_import_deps = Signal() | |||
|
32 | ||||
|
33 | ||||
30 | class PostManager(models.Manager): |
|
34 | class PostManager(models.Manager): | |
31 | @transaction.atomic |
|
35 | @transaction.atomic | |
32 | def create_post(self, title: str, text: str, file=None, thread=None, |
|
36 | def create_post(self, title: str, text: str, file=None, thread=None, | |
@@ -155,6 +159,11 class PostManager(models.Manager): | |||||
155 |
|
159 | |||
156 | post.threads.add(thread) |
|
160 | post.threads.add(thread) | |
157 |
|
161 | |||
|
162 | url_to_post = '[post]{}[/post]'.format(str(global_id)) | |||
|
163 | replies = self.filter(text__contains=url_to_post) | |||
|
164 | for reply in replies: | |||
|
165 | post_import_deps.send(reply.__class__) | |||
|
166 | ||||
158 | @transaction.atomic |
|
167 | @transaction.atomic | |
159 | def update_post(self, post, title: str, text: str, pub_time: str, |
|
168 | def update_post(self, post, title: str, text: str, pub_time: str, | |
160 | tags=list(), files=list(), tripcode=None, version=1): |
|
169 | tags=list(), files=list(), tripcode=None, version=1): |
@@ -2,8 +2,9 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, GlobalId |
|
4 | from boards.models import Post, GlobalId | |
5 | from boards.models.post import REGEX_NOTIFICATION |
|
5 | from boards.models.post import REGEX_NOTIFICATION, REGEX_REPLY,\ | |
6 | from boards.models.post import REGEX_REPLY, REGEX_GLOBAL_REPLY |
|
6 | REGEX_GLOBAL_REPLY | |
|
7 | from boards.models.post.manager import post_import_deps | |||
7 | from boards.models.user import Notification |
|
8 | from boards.models.user import Notification | |
8 | from django.db.models.signals import post_save, pre_save, pre_delete, \ |
|
9 | from django.db.models.signals import post_save, pre_save, pre_delete, \ | |
9 | post_delete |
|
10 | post_delete | |
@@ -30,6 +31,7 def connect_replies(instance, **kwargs): | |||||
30 |
|
31 | |||
31 |
|
32 | |||
32 | @receiver(post_save, sender=Post) |
|
33 | @receiver(post_save, sender=Post) | |
|
34 | @receiver(post_import_deps, sender=Post) | |||
33 | def connect_global_replies(instance, **kwargs): |
|
35 | def connect_global_replies(instance, **kwargs): | |
34 | for reply_number in re.finditer(REGEX_GLOBAL_REPLY, instance.get_raw_text()): |
|
36 | for reply_number in re.finditer(REGEX_GLOBAL_REPLY, instance.get_raw_text()): | |
35 | key_type = reply_number.group(1) |
|
37 | key_type = reply_number.group(1) | |
@@ -56,7 +58,8 def connect_notifications(instance, **kw | |||||
56 |
|
58 | |||
57 |
|
59 | |||
58 | @receiver(pre_save, sender=Post) |
|
60 | @receiver(pre_save, sender=Post) | |
59 | def preparse_text(instance, **kwargs): |
|
61 | @receiver(post_import_deps, sender=Post) | |
|
62 | def parse_text(instance, **kwargs): | |||
60 | instance._text_rendered = get_parser().parse(instance.get_raw_text()) |
|
63 | instance._text_rendered = get_parser().parse(instance.get_raw_text()) | |
61 |
|
64 | |||
62 |
|
65 |
General Comments 0
You need to be logged in to leave comments.
Login now