# HG changeset patch # User neko259 # Date 2015-01-13 09:36:31 # Node ID 114b6f2e0ed6a3c21104723935436cd565227c91 # Parent e8a92ba0ade504076a121166428e2bf80b0cfc16 Fixed connecting replies to posts diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -170,9 +170,8 @@ class PostManager(models.Manager): Connects replies to a post to show them as a reflink map """ - for reply_number in re.finditer(REGEX_REPLY, post.get_raw_text()): - post_id = reply_number.group(1) - ref_post = self.filter(id=post_id) + for reply_number in post.get_replied_ids(): + ref_post = self.filter(id=reply_number) if ref_post.count() > 0: referenced_post = ref_post[0] referenced_post.referenced_posts.add(post) @@ -234,7 +233,7 @@ class PostManager(models.Manager): text = et.SubElement(content_tag, TAG_TEXT) # TODO Replace local links by global ones in the text - text.text = post.text.raw + text.text = post.get_raw_text() if not post.is_opening(): thread = et.SubElement(content_tag, TAG_THREAD) @@ -523,17 +522,16 @@ class Post(models.Model, Viewable): def get_pub_time_epoch(self): return utils.datetime_to_epoch(self.pub_time) - # TODO Use this to connect replies def get_replied_ids(self): """ Gets ID list of the posts that this post replies. """ - local_replied = REGEX_REPLY.findall(self.text.raw) + raw_text = self.get_raw_text() + + local_replied = REGEX_REPLY.findall(raw_text) global_replied = [] - # TODO Similar code is used in mdx_neboard, maybe it can be extracted - # into a method? - for match in REGEX_GLOBAL_REPLY.findall(self.text.raw): + for match in REGEX_GLOBAL_REPLY.findall(raw_text): key_type = match[0] key = match[1] local_id = match[2] diff --git a/boards/tests/test_sync.py b/boards/tests/test_sync.py --- a/boards/tests/test_sync.py +++ b/boards/tests/test_sync.py @@ -42,7 +42,7 @@ class SyncTest(TestCase): post.id, post.global_id.key_type, post.title, - post.text.raw, + post.get_raw_text(), post.get_pub_time_epoch(), ) in respond_get(request).content.decode(), - 'Wrong response generated for the GET request.') \ No newline at end of file + 'Wrong response generated for the GET request.')