Show More
@@ -23,47 +23,50 b' THUMB_SIZES = ((200, 150),)' | |||||
23 |
|
23 | |||
24 | @receiver(post_save, sender=Post) |
|
24 | @receiver(post_save, sender=Post) | |
25 | def connect_replies(instance, **kwargs): |
|
25 | def connect_replies(instance, **kwargs): | |
26 | for reply_number in re.finditer(REGEX_REPLY, instance.get_raw_text()): |
|
26 | if not kwargs['update_fields']: | |
27 | post_id = reply_number.group(1) |
|
27 | for reply_number in re.finditer(REGEX_REPLY, instance.get_raw_text()): | |
|
28 | post_id = reply_number.group(1) | |||
28 |
|
29 | |||
29 | try: |
|
30 | try: | |
30 | referenced_post = Post.objects.get(id=post_id) |
|
31 | referenced_post = Post.objects.get(id=post_id) | |
31 |
|
32 | |||
32 | if not referenced_post.referenced_posts.filter( |
|
33 | if not referenced_post.referenced_posts.filter( | |
33 | id=instance.id).exists(): |
|
34 | id=instance.id).exists(): | |
34 | referenced_post.referenced_posts.add(instance) |
|
35 | referenced_post.referenced_posts.add(instance) | |
35 | referenced_post.last_edit_time = instance.pub_time |
|
36 | referenced_post.last_edit_time = instance.pub_time | |
36 | referenced_post.build_refmap() |
|
37 | referenced_post.build_refmap() | |
37 | referenced_post.save(update_fields=['refmap', 'last_edit_time']) |
|
38 | referenced_post.save(update_fields=['refmap', 'last_edit_time']) | |
38 | except Post.DoesNotExist: |
|
39 | except Post.DoesNotExist: | |
39 | pass |
|
40 | pass | |
40 |
|
41 | |||
41 |
|
42 | |||
42 | @receiver(post_save, sender=Post) |
|
43 | @receiver(post_save, sender=Post) | |
43 | @receiver(post_import_deps, sender=Post) |
|
44 | @receiver(post_import_deps, sender=Post) | |
44 | def connect_global_replies(instance, **kwargs): |
|
45 | def connect_global_replies(instance, **kwargs): | |
45 | for reply_number in re.finditer(REGEX_GLOBAL_REPLY, instance.get_raw_text()): |
|
46 | if not kwargs['update_fields']: | |
46 | key_type = reply_number.group(1) |
|
47 | for reply_number in re.finditer(REGEX_GLOBAL_REPLY, instance.get_raw_text()): | |
47 |
key = reply_number.group( |
|
48 | key_type = reply_number.group(1) | |
48 |
|
|
49 | key = reply_number.group(2) | |
|
50 | local_id = reply_number.group(3) | |||
49 |
|
51 | |||
50 | try: |
|
52 | try: | |
51 | global_id = GlobalId.objects.get(key_type=key_type, key=key, |
|
53 | global_id = GlobalId.objects.get(key_type=key_type, key=key, | |
52 | local_id=local_id) |
|
54 | local_id=local_id) | |
53 | referenced_post = Post.objects.get(global_id=global_id) |
|
55 | referenced_post = Post.objects.get(global_id=global_id) | |
54 | referenced_post.referenced_posts.add(instance) |
|
56 | referenced_post.referenced_posts.add(instance) | |
55 | referenced_post.last_edit_time = instance.pub_time |
|
57 | referenced_post.last_edit_time = instance.pub_time | |
56 | referenced_post.build_refmap() |
|
58 | referenced_post.build_refmap() | |
57 | referenced_post.save(update_fields=['refmap', 'last_edit_time']) |
|
59 | referenced_post.save(update_fields=['refmap', 'last_edit_time']) | |
58 | except (GlobalId.DoesNotExist, Post.DoesNotExist): |
|
60 | except (GlobalId.DoesNotExist, Post.DoesNotExist): | |
59 | pass |
|
61 | pass | |
60 |
|
62 | |||
61 |
|
63 | |||
62 | @receiver(post_save, sender=Post) |
|
64 | @receiver(post_save, sender=Post) | |
63 | def connect_notifications(instance, **kwargs): |
|
65 | def connect_notifications(instance, **kwargs): | |
64 | for reply_number in re.finditer(REGEX_NOTIFICATION, instance.get_raw_text()): |
|
66 | if not kwargs['update_fields']: | |
65 | user_name = reply_number.group(1).lower() |
|
67 | for reply_number in re.finditer(REGEX_NOTIFICATION, instance.get_raw_text()): | |
66 | Notification.objects.get_or_create(name=user_name, post=instance) |
|
68 | user_name = reply_number.group(1).lower() | |
|
69 | Notification.objects.get_or_create(name=user_name, post=instance) | |||
67 |
|
70 | |||
68 |
|
71 | |||
69 | @receiver(pre_save, sender=Post) |
|
72 | @receiver(pre_save, sender=Post) |
General Comments 0
You need to be logged in to leave comments.
Login now