Show More
@@ -276,13 +276,15 b' class Post(models.Model, Viewable):' | |||||
276 |
|
276 | |||
277 | def save(self, force_insert=False, force_update=False, using=None, |
|
277 | def save(self, force_insert=False, force_update=False, using=None, | |
278 | update_fields=None): |
|
278 | update_fields=None): | |
|
279 | new_post = self.id is None | |||
|
280 | ||||
279 | self._text_rendered = Parser().parse(self.get_raw_text()) |
|
281 | self._text_rendered = Parser().parse(self.get_raw_text()) | |
280 |
|
282 | |||
281 | self.uid = str(uuid.uuid4()) |
|
283 | self.uid = str(uuid.uuid4()) | |
282 | if update_fields is not None and 'uid' not in update_fields: |
|
284 | if update_fields is not None and 'uid' not in update_fields: | |
283 | update_fields += ['uid'] |
|
285 | update_fields += ['uid'] | |
284 |
|
286 | |||
285 |
if |
|
287 | if not new_post: | |
286 | for thread in self.get_threads().all(): |
|
288 | for thread in self.get_threads().all(): | |
287 | thread.last_edit_time = self.last_edit_time |
|
289 | thread.last_edit_time = self.last_edit_time | |
288 |
|
290 | |||
@@ -290,6 +292,13 b' class Post(models.Model, Viewable):' | |||||
290 |
|
292 | |||
291 | super().save(force_insert, force_update, using, update_fields) |
|
293 | super().save(force_insert, force_update, using, update_fields) | |
292 |
|
294 | |||
|
295 | # Post save triggers | |||
|
296 | if new_post: | |||
|
297 | self.build_url() | |||
|
298 | ||||
|
299 | self._connect_replies() | |||
|
300 | self._connect_notifications() | |||
|
301 | ||||
293 | def get_text(self) -> str: |
|
302 | def get_text(self) -> str: | |
294 | return self._text_rendered |
|
303 | return self._text_rendered | |
295 |
|
304 | |||
@@ -307,12 +316,12 b' class Post(models.Model, Viewable):' | |||||
307 | else: |
|
316 | else: | |
308 | return str(self.id) |
|
317 | return str(self.id) | |
309 |
|
318 | |||
310 | def connect_notifications(self): |
|
319 | def _connect_notifications(self): | |
311 | for reply_number in re.finditer(REGEX_NOTIFICATION, self.get_raw_text()): |
|
320 | for reply_number in re.finditer(REGEX_NOTIFICATION, self.get_raw_text()): | |
312 | user_name = reply_number.group(1).lower() |
|
321 | user_name = reply_number.group(1).lower() | |
313 | Notification.objects.get_or_create(name=user_name, post=self) |
|
322 | Notification.objects.get_or_create(name=user_name, post=self) | |
314 |
|
323 | |||
315 | def connect_replies(self): |
|
324 | def _connect_replies(self): | |
316 | """ |
|
325 | """ | |
317 | Connects replies to a post to show them as a reflink map |
|
326 | Connects replies to a post to show them as a reflink map | |
318 | """ |
|
327 | """ |
@@ -85,10 +85,7 b' class PostManager(models.Manager):' | |||||
85 | else: |
|
85 | else: | |
86 | post.attachments.add(Attachment.objects.create_with_hash(file)) |
|
86 | post.attachments.add(Attachment.objects.create_with_hash(file)) | |
87 |
|
87 | |||
88 | post.build_url() |
|
|||
89 | post.connect_replies() |
|
|||
90 | post.connect_threads(opening_posts) |
|
88 | post.connect_threads(opening_posts) | |
91 | post.connect_notifications() |
|
|||
92 |
|
89 | |||
93 | # Thread needs to be bumped only when the post is already created |
|
90 | # Thread needs to be bumped only when the post is already created | |
94 | if not new_thread: |
|
91 | if not new_thread: |
General Comments 0
You need to be logged in to leave comments.
Login now