# HG changeset patch # User neko259 # Date 2014-08-21 13:28:21 # Node ID b99c5139afbacd6dca5ef5282ba2d9685247011a # Parent 9fc1212ef0ec8c38452a0bd72810cb60769b2064 Added more parameters to the post xml output diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -15,6 +15,7 @@ from markupfield.fields import MarkupFie from boards.models import PostImage, KeyPair, GlobalId from boards.models.base import Viewable from boards.models.thread import Thread +from boards import utils APP_LABEL_BOARDS = 'boards' @@ -48,6 +49,9 @@ TAG_STATUS = 'status' TAG_MODELS = 'models' TAG_TITLE = 'title' TAG_TEXT = 'text' +TAG_THREAD = 'thread' +TAG_PUB_TIME = 'pub-time' +TAG_EDIT_TIME = 'edit-time' TYPE_GET = 'get' @@ -227,7 +231,17 @@ class PostManager(models.Manager): title.text = post.title text = et.SubElement(model, TAG_TEXT) - text.text = post.text.rendered + text.text = post.text.raw + + if not post.is_opening(): + thread = et.SubElement(model, TAG_THREAD) + thread.text = post.get_opening_post_id() + + pub_time = et.SubElement(model, TAG_PUB_TIME) + pub_time.text = str(post.get_pub_time_epoch()) + + edit_time = et.SubElement(model, TAG_EDIT_TIME) + edit_time.text = str(post.get_edit_time_epoch()) return et.tostring(response, 'unicode') @@ -445,3 +459,9 @@ class Post(models.Model, Viewable): self.global_id = global_id self.save(update_fields=['global_id']) + + def get_pub_time_epoch(self): + return utils.datetime_to_epoch(self.pub_time) + + def get_edit_time_epoch(self): + return utils.datetime_to_epoch(self.last_edit_time) 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 @@ -42,10 +42,11 @@ class KeyTest(TestCase): request = Post.objects.generate_request_get([post]) logger.debug(request) - self.assertTrue('' in - request, + self.assertTrue('' + '' + '' + '' + '' in request, 'Wrong XML generated for the GET request.') def test_response_get(self): @@ -54,11 +55,21 @@ class KeyTest(TestCase): response = Post.objects.generate_response_get([post]) logger.debug(response) - self.assertTrue('successtest_title' + self.assertTrue('' + 'success' + '' + '' + '' + 'test_title' 'test_text' - '' in response, + '%s' + '%s' + '' + '' + '' % ( + str(post.get_edit_time_epoch()), + str(post.get_pub_time_epoch()) + ) in response, 'Wrong XML generated for the GET response.') def _create_post_with_key(self):