# HG changeset patch # User neko259 # Date 2015-07-12 08:50:57 # Node ID 4f3aad0060da0e97db84bf57206b183311427bc0 # Parent af86e9af596eb958f7d45461789fcdc6918d5a75 Convert local post IDs to global when generating responses diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -443,6 +443,23 @@ class Post(models.Model, Viewable): def get_raw_text(self) -> str: return self.text + def get_sync_text(self) -> str: + """ + Returns text applicable for sync. It has absolute post reflinks. + """ + + replacements = dict() + for post_id in REGEX_REPLY.findall(self.get_raw_text()): + absolute_post_id = str(Post.objects.get(id=post_id).global_id) + replacements[post_id] = absolute_post_id + + text = self.get_raw_text() + for key in replacements: + text = text.replace('[post]{}[/post]'.format(key), + '[post]{}[/post]'.format(replacements[key])) + + return text + def get_absolute_id(self) -> str: """ If the post has many threads, shows its main thread OP id in the post diff --git a/boards/models/post/sync.py b/boards/models/post/sync.py --- a/boards/models/post/sync.py +++ b/boards/models/post/sync.py @@ -53,8 +53,7 @@ class SyncManager: title.text = post.title text = et.SubElement(content_tag, TAG_TEXT) - # TODO Replace local links by global ones in the text - text.text = post.get_raw_text() + text.text = post.get_sync_text() if not post.is_opening(): thread = et.SubElement(content_tag, TAG_THREAD) diff --git a/boards/tests/test_keys.py b/boards/tests/test_keys.py --- a/boards/tests/test_keys.py +++ b/boards/tests/test_keys.py @@ -66,14 +66,14 @@ class KeyTest(TestCase): '' '' 'test_title' - '[post]%d[/post]' + '[post]%s[/post]' '' '%s' '' % ( key.public_key, reply_post.id, key.key_type, - post.id, + str(post.global_id), key.public_key, post.id, key.key_type,