diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -39,7 +39,7 @@ PARAMETER_TRUNCATED = 'truncated' PARAMETER_TAG = 'tag' PARAMETER_OFFSET = 'offset' PARAMETER_DIFF_TYPE = 'type' -PARAMETER_BUMPABLE = 'bumpable' +PARAMETER_CSS_CLASS = 'css_class' PARAMETER_THREAD = 'thread' PARAMETER_IS_OPENING = 'is_opening' PARAMETER_MODERATOR = 'moderator' @@ -230,7 +230,7 @@ class Post(models.Model, Viewable): return self.threads def get_view(self, moderator=False, need_open_link=False, - truncated=False, *args, **kwargs) -> str: + truncated=False, reply_link=False, *args, **kwargs) -> str: """ Renders post's HTML view. Some of the post params can be passed over kwargs for the means of caching (if we view the thread, some params @@ -239,22 +239,28 @@ class Post(models.Model, Viewable): thread = self.get_thread() is_opening = kwargs.get(PARAMETER_IS_OPENING, self.is_opening()) - can_bump = kwargs.get(PARAMETER_BUMPABLE, thread.can_bump()) if is_opening: opening_post_id = self.id else: opening_post_id = thread.get_opening_post_id() + css_class = 'post' + if thread.archived: + css_class += ' archive_post' + elif not thread.can_bump(): + css_class += ' dead_post' + return render_to_string('boards/post.html', { PARAMETER_POST: self, PARAMETER_MODERATOR: moderator, PARAMETER_IS_OPENING: is_opening, PARAMETER_THREAD: thread, - PARAMETER_BUMPABLE: can_bump, + PARAMETER_CSS_CLASS: css_class, PARAMETER_NEED_OPEN_LINK: need_open_link, PARAMETER_TRUNCATED: truncated, PARAMETER_OP_ID: opening_post_id, + PARAMETER_REPLY_LINK: reply_link, }) def get_search_view(self, *args, **kwargs): diff --git a/boards/templatetags/board.py b/boards/templatetags/board.py --- a/boards/templatetags/board.py +++ b/boards/templatetags/board.py @@ -5,16 +5,6 @@ from django import template IMG_ACTION_URL = '[{}]' -PARAM_POST = 'post' -PARAM_MODERATOR = 'moderator' -PARAM_OP = 'is_opening' -PARAM_THREAD = 'thread' -PARAM_CSS_CLASS = 'css_class' -PARAM_OPEN_LINK = 'need_open_link' -PARAM_TRUNCATED = 'truncated' -PARAM_OP_ID = 'opening_post_id' -PARAM_REPLY_LINK = 'reply_link' - register = template.Library() @@ -49,36 +39,7 @@ def image_actions(*args, **kwargs): action['link'] % image_link, action['name'])for action in actions]) -@register.inclusion_tag('boards/post.html', name='post_view') -def post_view(post, moderator=False, need_open_link=False, truncated=False, - reply_link=False, **kwargs): - """ - Get post - """ - - thread = post.get_thread() - is_opening = post.is_opening() - - if is_opening: - opening_post_id = post.id - else: - opening_post_id = thread.get_opening_post_id() +@register.simple_tag(name='post_view') +def post_view(post, *args, **kwargs): + return post.get_view(*args, **kwargs) - css_class = 'post' - if thread.archived: - css_class += ' archive_post' - elif not thread.can_bump(): - css_class += ' dead_post' - - return { - PARAM_POST: post, - PARAM_MODERATOR: moderator, - PARAM_OP: is_opening, - PARAM_THREAD: thread, - PARAM_CSS_CLASS: css_class, - PARAM_OPEN_LINK: need_open_link, - PARAM_TRUNCATED: truncated, - PARAM_OP_ID: opening_post_id, - PARAM_REPLY_LINK: reply_link, - } -