##// END OF EJS Templates
Added more parameters to the post xml output
neko259 -
r828:b99c5139 decentral
parent child Browse files
Show More
@@ -15,6 +15,7 b' from markupfield.fields import MarkupFie'
15 from boards.models import PostImage, KeyPair, GlobalId
15 from boards.models import PostImage, KeyPair, GlobalId
16 from boards.models.base import Viewable
16 from boards.models.base import Viewable
17 from boards.models.thread import Thread
17 from boards.models.thread import Thread
18 from boards import utils
18
19
19
20
20 APP_LABEL_BOARDS = 'boards'
21 APP_LABEL_BOARDS = 'boards'
@@ -48,6 +49,9 b" TAG_STATUS = 'status'"
48 TAG_MODELS = 'models'
49 TAG_MODELS = 'models'
49 TAG_TITLE = 'title'
50 TAG_TITLE = 'title'
50 TAG_TEXT = 'text'
51 TAG_TEXT = 'text'
52 TAG_THREAD = 'thread'
53 TAG_PUB_TIME = 'pub-time'
54 TAG_EDIT_TIME = 'edit-time'
51
55
52 TYPE_GET = 'get'
56 TYPE_GET = 'get'
53
57
@@ -227,7 +231,17 b' class PostManager(models.Manager):'
227 title.text = post.title
231 title.text = post.title
228
232
229 text = et.SubElement(model, TAG_TEXT)
233 text = et.SubElement(model, TAG_TEXT)
230 text.text = post.text.rendered
234 text.text = post.text.raw
235
236 if not post.is_opening():
237 thread = et.SubElement(model, TAG_THREAD)
238 thread.text = post.get_opening_post_id()
239
240 pub_time = et.SubElement(model, TAG_PUB_TIME)
241 pub_time.text = str(post.get_pub_time_epoch())
242
243 edit_time = et.SubElement(model, TAG_EDIT_TIME)
244 edit_time.text = str(post.get_edit_time_epoch())
231
245
232 return et.tostring(response, 'unicode')
246 return et.tostring(response, 'unicode')
233
247
@@ -445,3 +459,9 b' class Post(models.Model, Viewable):'
445 self.global_id = global_id
459 self.global_id = global_id
446
460
447 self.save(update_fields=['global_id'])
461 self.save(update_fields=['global_id'])
462
463 def get_pub_time_epoch(self):
464 return utils.datetime_to_epoch(self.pub_time)
465
466 def get_edit_time_epoch(self):
467 return utils.datetime_to_epoch(self.last_edit_time)
@@ -42,10 +42,11 b' class KeyTest(TestCase):'
42 request = Post.objects.generate_request_get([post])
42 request = Post.objects.generate_request_get([post])
43 logger.debug(request)
43 logger.debug(request)
44
44
45 self.assertTrue('<request type="get" version="1.0"><model '
45 self.assertTrue('<request type="get" version="1.0">'
46 'name="post" version="1.0"><id key="pubkey" '
46 '<model name="post" version="1.0">'
47 'local-id="1" type="test_key_type" /></model></request>' in
47 '<id key="pubkey" local-id="1" type="test_key_type" />'
48 request,
48 '</model>'
49 '</request>' in request,
49 'Wrong XML generated for the GET request.')
50 'Wrong XML generated for the GET request.')
50
51
51 def test_response_get(self):
52 def test_response_get(self):
@@ -54,11 +55,21 b' class KeyTest(TestCase):'
54 response = Post.objects.generate_response_get([post])
55 response = Post.objects.generate_response_get([post])
55 logger.debug(response)
56 logger.debug(response)
56
57
57 self.assertTrue('<response><status>success</status><models><model '
58 self.assertTrue('<response>'
58 'name="post" ref-id="1"><id key="pubkey" local-id="1"'
59 '<status>success</status>'
59 ' type="test_key_type" /><title>test_title</title>'
60 '<models>'
61 '<model name="post" ref-id="1">'
62 '<id key="pubkey" local-id="1" type="test_key_type" />'
63 '<title>test_title</title>'
60 '<text>test_text</text>'
64 '<text>test_text</text>'
61 '</model></models></response>' in response,
65 '<pub-time>%s</pub-time>'
66 '<edit-time>%s</edit-time>'
67 '</model>'
68 '</models>'
69 '</response>' % (
70 str(post.get_edit_time_epoch()),
71 str(post.get_pub_time_epoch())
72 ) in response,
62 'Wrong XML generated for the GET response.')
73 'Wrong XML generated for the GET response.')
63
74
64 def _create_post_with_key(self):
75 def _create_post_with_key(self):
General Comments 0
You need to be logged in to leave comments. Login now