def comment_card( comment: Comment, request=None, target=None, show_actions=None, **kwargs ): """ Render comment information inside a comment card. """ user = getattr(request, "user", None) is_authenticated = getattr(user, "is_authenticated", False) if is_authenticated: login_anchor = None else: login = reverse("auth:login") login_anchor = a( _("login"), href=f"{login}?next={comment.conversation.get_absolute_url()}" ) buttons = { "disagree": ("fa-times", "text-negative", _("Disagree")), "skip": ("fa-arrow-right", "text-black", _("Skip")), "agree": ("fa-check", "text-positive", _("Agree")), } return { "author": comment.author.username, "comment": comment, "show_actions": is_authenticated, "csrf_input": csrf_input(request), "buttons": buttons, "login_anchor": login_anchor, "target": target, **kwargs, }
def conversation_comment_form( conversation, request=None, content=None, user=None, form=None, target=None ): """ Render comment form for conversation. """ # Check user credentials user = user or getattr(request, "user", None) if not user.is_authenticated: conversation_url = conversation.get_absolute_url() login = reverse("auth:login") return { "user": None, "login_anchor": a(_("login"), href=f"{login}?next={conversation_url}"), } # Check if user still have comments left n_comments = rules.compute("ej.remaining_comments", conversation, user) if conversation.author != user and n_comments <= 0: return {"comments_exceeded": True, "user": user} # Everything is ok, proceed ;) return { "user": user, "csrf_input": csrf_input(request), "n_comments": n_comments, "content": content, "target": target or "main", "form": form or forms.CommentForm(request=request, conversation=conversation), }
def comment_moderate(comment, request=None, **kwargs): """ Render a comment inside a moderation card. """ return { 'comment': comment, 'csrf_input': csrf_input(request), **kwargs, }
def comment_moderate(comment, request=None, **kwargs): """ Render a comment inside a moderation card. """ return { 'comment': comment, 'rejection_reasons': dict(models.Comment.REJECTION_REASON), 'csrf_input': csrf_input(request), **kwargs, }
def comment_form(conversation, request=None, comment_content=None, **kwargs): """ Render comment form for one conversation. """ user = getattr(request, 'user', None) n_comments = rules.compute('ej_conversations.remaining_comments', conversation, user) conversation_url = conversation.get_absolute_url() login = reverse('auth:login') login_anchor = a(_('login'), href=f'{login}?next={conversation_url}') return { 'can_comment': user.is_authenticated, 'comments_left': n_comments, 'user_is_owner': conversation.author == user, 'csrf_input': csrf_input(request), 'comment_content': comment_content, 'login_anchor': login_anchor, }
def conversation_balloon(conversation, request=None, **kwargs): """ Render details of a conversation inside a conversation balloon. """ user = getattr(request, 'user', None) favorites = models.FavoriteConversation.objects is_authenticated = getattr(user, 'is_authenticated', False) is_favorite = is_authenticated and conversation.is_favorite(user) return { 'conversation': conversation, 'tags': conversation.tags.all(), 'comments_count': conversation.comments.count(), 'votes_count': conversation.votes.count(), 'favorites_count': favorites.filter(conversation=conversation).count(), 'user': user, 'csrf_input': csrf_input(request), 'show_user_actions': is_authenticated, 'is_favorite': is_favorite, **kwargs, }
def comment_card(comment, request=None, **kwargs): """ Render comment information inside a comment card. """ user = getattr(request, 'user', None) is_authenticated = getattr(user, 'is_authenticated', False) total = comment.conversation.approved_comments.count() remaining = total - comment.conversation.user_votes(user).count() voted = total - remaining + 1 login = reverse('auth:login') comment_url = comment.conversation.get_absolute_url() login_anchor = a(_('login'), href=f'{login}?next={comment_url}') return { 'comment': comment, 'total': total, 'voted': voted, 'show_user_actions': is_authenticated, 'csrf_input': csrf_input(request), 'login_anchor': login_anchor, **kwargs, }