Show More
@@ -52,6 +52,8 b" TAG_TEXT = 'text'" | |||||
52 | TAG_THREAD = 'thread' |
|
52 | TAG_THREAD = 'thread' | |
53 | TAG_PUB_TIME = 'pub-time' |
|
53 | TAG_PUB_TIME = 'pub-time' | |
54 | TAG_EDIT_TIME = 'edit-time' |
|
54 | TAG_EDIT_TIME = 'edit-time' | |
|
55 | TAG_PREVIOUS = 'previous' | |||
|
56 | TAG_NEXT = 'next' | |||
55 |
|
57 | |||
56 | TYPE_GET = 'get' |
|
58 | TYPE_GET = 'get' | |
57 |
|
59 | |||
@@ -110,8 +112,8 b' class PostManager(models.Manager):' | |||||
110 | Thread.objects.process_oldest_threads() |
|
112 | Thread.objects.process_oldest_threads() | |
111 | self.connect_replies(post) |
|
113 | self.connect_replies(post) | |
112 |
|
114 | |||
113 |
logger.info('Created post #%d with title %s' |
|
115 | logger.info('Created post #%d with title %s and key %s' | |
114 | post.get_title())) |
|
116 | % (post.id, post.get_title(), post.global_id.key)) | |
115 |
|
117 | |||
116 | return post |
|
118 | return post | |
117 |
|
119 | |||
@@ -148,9 +150,8 b' class PostManager(models.Manager):' | |||||
148 | Connects replies to a post to show them as a reflink map |
|
150 | Connects replies to a post to show them as a reflink map | |
149 | """ |
|
151 | """ | |
150 |
|
152 | |||
151 |
for reply_number in |
|
153 | for reply_number in post.get_replied_ids(): | |
152 |
post |
|
154 | ref_post = self.filter(id=reply_number) | |
153 | ref_post = self.filter(id=post_id) |
|
|||
154 | if ref_post.count() > 0: |
|
155 | if ref_post.count() > 0: | |
155 | referenced_post = ref_post[0] |
|
156 | referenced_post = ref_post[0] | |
156 | referenced_post.referenced_posts.add(post) |
|
157 | referenced_post.referenced_posts.add(post) | |
@@ -235,7 +236,7 b' class PostManager(models.Manager):' | |||||
235 |
|
236 | |||
236 | if not post.is_opening(): |
|
237 | if not post.is_opening(): | |
237 | thread = et.SubElement(model, TAG_THREAD) |
|
238 | thread = et.SubElement(model, TAG_THREAD) | |
238 | thread.text = post.get_opening_post_id() |
|
239 | thread.text = str(post.get_thread().get_opening_post_id()) | |
239 |
|
240 | |||
240 | pub_time = et.SubElement(model, TAG_PUB_TIME) |
|
241 | pub_time = et.SubElement(model, TAG_PUB_TIME) | |
241 | pub_time.text = str(post.get_pub_time_epoch()) |
|
242 | pub_time.text = str(post.get_pub_time_epoch()) | |
@@ -243,6 +244,22 b' class PostManager(models.Manager):' | |||||
243 | edit_time = et.SubElement(model, TAG_EDIT_TIME) |
|
244 | edit_time = et.SubElement(model, TAG_EDIT_TIME) | |
244 | edit_time.text = str(post.get_edit_time_epoch()) |
|
245 | edit_time.text = str(post.get_edit_time_epoch()) | |
245 |
|
246 | |||
|
247 | previous_ids = post.get_replied_ids() | |||
|
248 | if len(previous_ids) > 0: | |||
|
249 | previous = et.SubElement(model, TAG_PREVIOUS) | |||
|
250 | for id in previous_ids: | |||
|
251 | prev_id = et.SubElement(previous, TAG_ID) | |||
|
252 | replied_post = Post.objects.get(id=id) | |||
|
253 | replied_post.global_id.to_xml_element(prev_id) | |||
|
254 | ||||
|
255 | ||||
|
256 | next_ids = post.referenced_posts.order_by('id').all() | |||
|
257 | if len(next_ids) > 0: | |||
|
258 | next_el = et.SubElement(model, TAG_NEXT) | |||
|
259 | for ref_post in next_ids: | |||
|
260 | next_id = et.SubElement(next_el, TAG_ID) | |||
|
261 | ref_post.global_id.to_xml_element(next_id) | |||
|
262 | ||||
246 | return et.tostring(response, 'unicode') |
|
263 | return et.tostring(response, 'unicode') | |
247 |
|
264 | |||
248 |
|
265 | |||
@@ -435,6 +452,9 b' class Post(models.Model, Viewable):' | |||||
435 | """ |
|
452 | """ | |
436 |
|
453 | |||
437 | self.images.all().delete() |
|
454 | self.images.all().delete() | |
|
455 | self.signature.all().delete() | |||
|
456 | if self.global_id: | |||
|
457 | self.global_id.delete() | |||
438 |
|
458 | |||
439 | super(Post, self).delete(using) |
|
459 | super(Post, self).delete(using) | |
440 |
|
460 | |||
@@ -455,6 +475,7 b' class Post(models.Model, Viewable):' | |||||
455 | global_id = GlobalId(key_type=key.key_type, |
|
475 | global_id = GlobalId(key_type=key.key_type, | |
456 | key=key.public_key, |
|
476 | key=key.public_key, | |
457 | local_id = self.id) |
|
477 | local_id = self.id) | |
|
478 | global_id.save() | |||
458 |
|
479 | |||
459 | self.global_id = global_id |
|
480 | self.global_id = global_id | |
460 |
|
481 | |||
@@ -465,3 +486,6 b' class Post(models.Model, Viewable):' | |||||
465 |
|
486 | |||
466 | def get_edit_time_epoch(self): |
|
487 | def get_edit_time_epoch(self): | |
467 | return utils.datetime_to_epoch(self.last_edit_time) |
|
488 | return utils.datetime_to_epoch(self.last_edit_time) | |
|
489 | ||||
|
490 | def get_replied_ids(self): | |||
|
491 | return re.findall(REGEX_REPLY, self.text.raw) |
@@ -51,24 +51,41 b' class KeyTest(TestCase):' | |||||
51 |
|
51 | |||
52 | def test_response_get(self): |
|
52 | def test_response_get(self): | |
53 | post = self._create_post_with_key() |
|
53 | post = self._create_post_with_key() | |
|
54 | reply_post = Post.objects.create_post(title='test_title', | |||
|
55 | text='[post]%d[/post]' % post.id, thread=post.get_thread()) | |||
|
56 | reply_reply_post = Post.objects.create_post(title='', | |||
|
57 | text='[post]%d[/post]' % reply_post.id, | |||
|
58 | thread=post.get_thread()) | |||
54 |
|
59 | |||
55 | response = Post.objects.generate_response_get([post]) |
|
60 | response = Post.objects.generate_response_get([reply_post]) | |
56 | logger.debug(response) |
|
61 | logger.debug(response) | |
57 |
|
62 | |||
58 | self.assertTrue('<response>' |
|
63 | self.assertTrue('<response>' | |
59 | '<status>success</status>' |
|
64 | '<status>success</status>' | |
60 | '<models>' |
|
65 | '<models>' | |
61 | '<model name="post" ref-id="1">' |
|
66 | '<model name="post" ref-id="1">' | |
62 |
'<id key="pubkey" local-id=" |
|
67 | '<id key="pubkey" local-id="%d" type="test_key_type" />' | |
63 | '<title>test_title</title>' |
|
68 | '<title>test_title</title>' | |
64 |
'<text> |
|
69 | '<text>[post]%d[/post]</text>' | |
|
70 | '<thread>%d</thread>' | |||
65 | '<pub-time>%s</pub-time>' |
|
71 | '<pub-time>%s</pub-time>' | |
66 | '<edit-time>%s</edit-time>' |
|
72 | '<edit-time>%s</edit-time>' | |
|
73 | '<previous>' | |||
|
74 | '<id key="pubkey" local-id="%d" type="test_key_type" />' | |||
|
75 | '</previous>' | |||
|
76 | '<next>' | |||
|
77 | '<id key="pubkey" local-id="%d" type="test_key_type" />' | |||
|
78 | '</next>' | |||
67 | '</model>' |
|
79 | '</model>' | |
68 | '</models>' |
|
80 | '</models>' | |
69 | '</response>' % ( |
|
81 | '</response>' % ( | |
70 |
|
|
82 | reply_post.id, | |
71 |
|
|
83 | post.id, | |
|
84 | post.id, | |||
|
85 | str(reply_post.get_edit_time_epoch()), | |||
|
86 | str(reply_post.get_pub_time_epoch()), | |||
|
87 | post.id, | |||
|
88 | reply_reply_post.id, | |||
72 | ) in response, |
|
89 | ) in response, | |
73 | 'Wrong XML generated for the GET response.') |
|
90 | 'Wrong XML generated for the GET response.') | |
74 |
|
91 |
General Comments 0
You need to be logged in to leave comments.
Login now