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 @@ -18,6 +18,7 @@ from boards import settings from boards.models import PostImage from boards.models.base import Viewable from boards import utils +from boards.models.post.export import get_exporter, DIFF_TYPE_JSON from boards.models.user import Notification, Ban import boards.models.thread @@ -354,9 +355,13 @@ class Post(models.Model, Viewable): return self.get_thread().get_opening_post_id() == self.id + # TODO Remove this and use get_absolute_url method def get_url(self): return self.url + def get_absolute_url(self): + return self.url + def get_thread(self): return self.thread @@ -488,37 +493,15 @@ class Post(models.Model, Viewable): API. """ - if format_type == DIFF_TYPE_HTML: - if request is not None and PARAMETER_TRUNCATED in request.GET: - truncated = True - reply_link = False - else: - truncated = False - reply_link = True - - return self.get_view(truncated=truncated, reply_link=reply_link, - moderator=utils.is_moderator(request)) - elif format_type == DIFF_TYPE_JSON: - post_json = { - 'id': self.id, - 'title': self.title, - 'text': self._text_rendered, - } - if self.images.exists(): - post_image = self.get_first_image() - post_json['image'] = post_image.image.url - post_json['image_preview'] = post_image.image.url_200x150 - if include_last_update: - post_json['bump_time'] = utils.datetime_to_epoch( - self.get_thread().bump_time) - return post_json + return get_exporter(format_type).export(self, request, + include_last_update) def notify_clients(self, recursive=True): """ Sends post HTML data to the thread web socket. """ - if not settings.WEBSOCKETS_ENABLED: + if not settings.get_bool('External', 'WebsocketsEnabled'): return thread_ids = list()