Show More
@@ -443,6 +443,23 b' class Post(models.Model, Viewable):' | |||||
443 | def get_raw_text(self) -> str: |
|
443 | def get_raw_text(self) -> str: | |
444 | return self.text |
|
444 | return self.text | |
445 |
|
445 | |||
|
446 | def get_sync_text(self) -> str: | |||
|
447 | """ | |||
|
448 | Returns text applicable for sync. It has absolute post reflinks. | |||
|
449 | """ | |||
|
450 | ||||
|
451 | replacements = dict() | |||
|
452 | for post_id in REGEX_REPLY.findall(self.get_raw_text()): | |||
|
453 | absolute_post_id = str(Post.objects.get(id=post_id).global_id) | |||
|
454 | replacements[post_id] = absolute_post_id | |||
|
455 | ||||
|
456 | text = self.get_raw_text() | |||
|
457 | for key in replacements: | |||
|
458 | text = text.replace('[post]{}[/post]'.format(key), | |||
|
459 | '[post]{}[/post]'.format(replacements[key])) | |||
|
460 | ||||
|
461 | return text | |||
|
462 | ||||
446 | def get_absolute_id(self) -> str: |
|
463 | def get_absolute_id(self) -> str: | |
447 | """ |
|
464 | """ | |
448 | If the post has many threads, shows its main thread OP id in the post |
|
465 | If the post has many threads, shows its main thread OP id in the post |
@@ -53,8 +53,7 b' class SyncManager:' | |||||
53 | title.text = post.title |
|
53 | title.text = post.title | |
54 |
|
54 | |||
55 | text = et.SubElement(content_tag, TAG_TEXT) |
|
55 | text = et.SubElement(content_tag, TAG_TEXT) | |
56 | # TODO Replace local links by global ones in the text |
|
56 | text.text = post.get_sync_text() | |
57 | text.text = post.get_raw_text() |
|
|||
58 |
|
57 | |||
59 | if not post.is_opening(): |
|
58 | if not post.is_opening(): | |
60 | thread = et.SubElement(content_tag, TAG_THREAD) |
|
59 | thread = et.SubElement(content_tag, TAG_THREAD) |
@@ -66,14 +66,14 b' class KeyTest(TestCase):' | |||||
66 | '<content>' |
|
66 | '<content>' | |
67 | '<id key="%s" local-id="%d" type="%s" />' |
|
67 | '<id key="%s" local-id="%d" type="%s" />' | |
68 | '<title>test_title</title>' |
|
68 | '<title>test_title</title>' | |
69 |
'<text>[post]% |
|
69 | '<text>[post]%s[/post]</text>' | |
70 | '<thread><id key="%s" local-id="%d" type="%s" /></thread>' |
|
70 | '<thread><id key="%s" local-id="%d" type="%s" /></thread>' | |
71 | '<pub-time>%s</pub-time>' |
|
71 | '<pub-time>%s</pub-time>' | |
72 | '</content>' % ( |
|
72 | '</content>' % ( | |
73 | key.public_key, |
|
73 | key.public_key, | |
74 | reply_post.id, |
|
74 | reply_post.id, | |
75 | key.key_type, |
|
75 | key.key_type, | |
76 | post.id, |
|
76 | str(post.global_id), | |
77 | key.public_key, |
|
77 | key.public_key, | |
78 | post.id, |
|
78 | post.id, | |
79 | key.key_type, |
|
79 | key.key_type, |
General Comments 0
You need to be logged in to leave comments.
Login now