##// END OF EJS Templates
Rebuild refmap after post from it was deleted
neko259 -
r1619:9c0a2b69 default
parent child Browse files
Show More
@@ -116,14 +116,19 b' class Post(models.Model, Viewable):'
116
116
117 return title
117 return title
118
118
119 def build_refmap(self) -> None:
119 def build_refmap(self, excluded_ids=None) -> None:
120 """
120 """
121 Builds a replies map string from replies list. This is a cache to stop
121 Builds a replies map string from replies list. This is a cache to stop
122 the server from recalculating the map on every post show.
122 the server from recalculating the map on every post show.
123 """
123 """
124
124
125 post_urls = [refpost.get_link_view()
125 replies = self.referenced_posts
126 for refpost in self.referenced_posts.all()]
126 if excluded_ids is not None:
127 replies = replies.exclude(id__in=excluded_ids)
128 else:
129 replies = replies.all()
130
131 post_urls = [refpost.get_link_view() for refpost in replies]
127
132
128 self.refmap = ', '.join(post_urls)
133 self.refmap = ', '.join(post_urls)
129
134
@@ -106,3 +106,10 b' def generate_thumb(instance, **kwargs):'
106 if not thumb_name == thumb_name_:
106 if not thumb_name == thumb_name_:
107 raise ValueError(
107 raise ValueError(
108 'There is already a file named %s' % thumb_name_)
108 'There is already a file named %s' % thumb_name_)
109
110
111 @receiver(pre_delete, sender=Post)
112 def rebuild_refmap(instance, **kwargs):
113 for referenced_post in instance.refposts.all():
114 referenced_post.build_refmap(excluded_ids=[instance.id])
115 referenced_post.save(update_fields=['refmap'])
General Comments 0
You need to be logged in to leave comments. Login now