def conversation_create_comment(conversation, request=None, **kwargs): """ Render "create comment" button for one conversation. """ conversation.set_request(request) n_comments = conversation.n_user_total_comments n_moderation = conversation.n_pending_comments fn = rules.get_value("ej.max_comments_per_conversation") user = getattr(request, "user", None) max_comments = fn(conversation, user) moderation_msg = _("{n} awaiting moderation").format(n=n_moderation) comments_count = _("{n} of {m} comments").format(n=n_comments, m=max_comments) # FIXME: Reactivate when full UI for the comment form is implemented # return extra_content( # _("Create comment"), # Blob(f"{comments_count}" f'<div class="text-7 strong">{moderation_msg}</div>'), # icon="plus", # id="create-comment", # ) return div( Blob(f"{comments_count}" f'<div class="text-7 strong">{moderation_msg}</div>'), id="create-comment", class_="extra-content", )
def remaining_comments(conversation, user): """ The number of comments user still have in a conversation. """ if user is None or user.id is None: return 0 fn = rules.get_value("ej.max_comments_per_conversation") max_comments = fn(conversation, user) minimum = 1 if user.has_perm("ej.can_edit_conversation", conversation) else 0 comments = user.comments.filter(conversation=conversation).count() return max(max_comments - comments, minimum)
def profile(self): profile = rules.get_value('auth.profile') return profile(self)