當前位置: 首頁>>代碼示例>>Python>>正文


Python Comment.get_content_type方法代碼示例

本文整理匯總了Python中comments.models.Comment.get_content_type方法的典型用法代碼示例。如果您正苦於以下問題:Python Comment.get_content_type方法的具體用法?Python Comment.get_content_type怎麽用?Python Comment.get_content_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在comments.models.Comment的用法示例。


在下文中一共展示了Comment.get_content_type方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testReportComment

# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import get_content_type [as 別名]
    def testReportComment(self):
        # Try to view form anonymously
        # (but get redirected because not authenticated)
        url = reverse('report_comment', args=[self.comment.id])
        response = self.client.get(url)
        self.assertEqual(response.status_code, 302)

        # Log in
        self.client.login(username=self.eusa_staff.username, password="")

        # View form
        url = reverse('report_comment', args=[self.comment.id])
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertIn('form', response.context)
        self.assertIn('comment', response.context)
        self.assertEqual(self.comment, response.context['comment'])

        # Report
        post = {'reason': 'Unacceptable'}
        response = self.client.post(url, post)
        self.assertEqual(response.status_code, 302)
        self.assertTrue(Report.objects.filter(
            content_type=Comment.get_content_type(),
            object_id=self.comment.id))
開發者ID:HughMcGrade,項目名稱:eusay,代碼行數:27,代碼來源:tests.py

示例2: moderator_panel

# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import get_content_type [as 別名]
def moderator_panel(request):
    if not request.user.is_authenticated():
        return request_login(request)
    if not request.user.isModerator:
        messages.add_message(request, messages.ERROR,
                             "Only moderators may access the moderator panel.")
        if request.is_ajax():
            return HttpResponseForbidden("")
        else:
            return HttpResponseRedirect(reverse('frontpage'))

    if request.method == "POST":
        report_id = request.POST.get("report")
        report = Report.objects.get(id=report_id)
        action = request.POST.get("action")
        ajax_response_type = HttpResponse
        if action == "Hide":
            try:
                hide_action = HideAction()
                hide_action.moderator = request.user
                hide_action.reason = report.reason
                hide_action.content = report.content
                hide_action.save()
                report.delete()
                messages.add_message(request, messages.INFO, "Content hidden")
            except Report.DoesNotExist:
                messages.add_message(request, messages.ERROR,
                                     "Report not found")
                ajax_response_type = HttpResponseNotFound
        elif action == "Ignore":
            try:
                report.delete()
                messages.add_message(request, messages.INFO,
                                     "Report ignored")
            except Report.DoesNotExist:
                messages.add_message(request, messages.ERROR,
                                     "Report not found")
                ajax_response_type = HttpResponseNotFound
        else:
            messages.add_message(request, messages.ERROR,
                                 "Moderation action type not found")
            ajax_response_type = HttpResponseNotFound
        if request.is_ajax():
            return ajax_response_type("")

    comment_reports = Report.objects.filter(
        content_type=Comment.get_content_type())
    proposal_reports = Report.objects.filter(
        content_type=Proposal.get_content_type())
    return render(request, "moderator_panel.html",
                  {"comment_reports": comment_reports,
                   "proposal_reports": proposal_reports})
開發者ID:HughMcGrade,項目名稱:eusay,代碼行數:54,代碼來源:views.py

示例3: notify_submitter_if_content_hidden

# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import get_content_type [as 別名]
def notify_submitter_if_content_hidden(created, **kwargs):
    hide_action = kwargs.get("instance")
    if created:
        # Don't notify submitter if they hide their own content
        if hide_action.moderator != hide_action.content.user:
            recipient = hide_action.content.user
            if hide_action.content_type == Proposal.get_content_type():
                type = "proposal_hidden"
            elif hide_action.content_type == Comment.get_content_type():
                type = "comment_hidden"
            Notification.objects.create(recipient=recipient,
                                        type=type,
                                        content=hide_action.content)
開發者ID:HughMcGrade,項目名稱:eusay,代碼行數:15,代碼來源:signals.py

示例4: delete_notify_of_vote

# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import get_content_type [as 別名]
def delete_notify_of_vote(**kwargs):
    # TODO: are all these conditions necessary? would it not be enough to just
    # delete any notifications where object_id=vote.id and
    # content_type=vote.content_type?
    vote = kwargs.get("instance")
    recipient = vote.content.user
    # Votes on proposals
    if vote.content_type == Proposal.get_content_type():
        if vote.isVoteUp:
            type = "proposal_vote_up"
        else:
            type = "proposal_vote_down"
    # Votes on comments
    elif vote.content_type == Comment.get_content_type():
        if vote.isVoteUp:
            type = "comment_vote_up"
        else:
            type = "comment_vote_down"
    Notification.objects.filter(recipient=recipient,
                                type=type,
                                content_type=vote.get_content_type(),
                                object_id=vote._id).delete()
開發者ID:HughMcGrade,項目名稱:eusay,代碼行數:24,代碼來源:signals.py

示例5: notify_of_vote

# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import get_content_type [as 別名]
def notify_of_vote(created, **kwargs):
    vote = kwargs.get("instance")
    recipient = vote.content.user
    if created and vote.user != recipient:
        # Votes on proposals
        if vote.content_type == Proposal.get_content_type():
            if vote.isVoteUp:
                type = "proposal_vote_up"
            else:
                type = "proposal_vote_down"

        # Votes on comments
        elif vote.content_type == Comment.get_content_type():
            if vote.isVoteUp:
                type = "comment_vote_up"
            else:
                type = "comment_vote_down"

        Notification.objects.create(recipient=recipient,
                                    type=type,
                                    content_type=Vote.get_content_type(),
                                    object_id=vote.id)
開發者ID:HughMcGrade,項目名稱:eusay,代碼行數:24,代碼來源:signals.py

示例6: testModeratorPanel

# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import get_content_type [as 別名]
    def testModeratorPanel(self):
        url = reverse('moderator_panel')

        # View moderator panel anonymously
        response = self.client.get(url)
        self.assertEqual(response.status_code, 302)

        # Hide from comment report anonymously
        post = {'action': 'Hide', 'report': self.comment_report.id}
        response = self.client.post(url, post)
        self.assertEqual(response.status_code, 302)
        self.assertRaises(HideAction.DoesNotExist, HideAction.objects.get,
                          object_id=self.reported_comment.id,
                          content_type=Comment.get_content_type())
        self.assertTrue(Report.objects.get(id=self.comment_report.id))

        # Hide from proposal report anonymously
        post = {'action': 'Hide', 'report': self.proposal_report.id}
        response = self.client.post(url, post)
        self.assertEqual(response.status_code, 302)
        self.assertRaises(HideAction.DoesNotExist, HideAction.objects.get,
                          object_id=self.reported_proposal.id,
                          content_type=Proposal.get_content_type())
        self.assertTrue(Report.objects.get(id=self.proposal_report.id))

        # Login as non-moderator
        self.assertTrue(self.client.login(username=self.user.username,
                                          password=''))

        # View moderator panel as non-moderator
        response = self.client.get(url)
        self.assertEqual(response.status_code, 302)

        # Hide from comment report as non-moderator
        post = {'action': 'Hide', 'report': self.comment_report.id}
        response = self.client.post(url, post)
        self.assertEqual(response.status_code, 302)
        self.assertRaises(HideAction.DoesNotExist, HideAction.objects.get,
                          object_id=self.reported_comment.id,
                          content_type=Comment.get_content_type())
        self.assertTrue(Report.objects.get(id=self.comment_report.id))

        # Hide from proposal report as non-moderator
        post = {'action': 'Hide', 'report': self.proposal_report.id}
        response = self.client.post(url, post)
        self.assertEqual(response.status_code, 302)
        self.assertRaises(HideAction.DoesNotExist, HideAction.objects.get,
                          object_id=self.reported_proposal.id,
                          content_type=Proposal.get_content_type())
        self.assertTrue(Report.objects.get(id=self.proposal_report.id))

        # Login as moderator
        self.assertTrue(self.client.login(username=self.eusa_staff.username,
                                          password=''))

        # View moderator panel as moderator
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        # Hide from comment report as moderator
        post = {'action': 'Hide', 'report': self.comment_report.id}
        response = self.client.post(url, post)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(HideAction.objects.get(
            object_id=self.reported_comment.id,
            content_type=Comment.get_content_type()))
        self.assertRaises(Report.DoesNotExist, Report.objects.get,
                          id=self.comment_report.id)

        # Hide from proposal report as moderator
        post = {'action': 'Hide', 'report': self.proposal_report.id}
        response = self.client.post(url, post)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(HideAction.objects.get(
            object_id=self.reported_proposal.id,
            content_type=Proposal.get_content_type()))
        self.assertRaises(Report.DoesNotExist, Report.objects.get,
                          id=self.proposal_report.id)
開發者ID:HughMcGrade,項目名稱:eusay,代碼行數:80,代碼來源:tests.py

示例7: comment_hides

# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import get_content_type [as 別名]
def comment_hides(request):
    hiddens = HideAction.objects.all()\
                                .filter(
                                    content_type=Comment.get_content_type())
    return render(request, "hidden_comment_list.html", {"hiddens": hiddens})
開發者ID:HughMcGrade,項目名稱:eusay,代碼行數:7,代碼來源:views.py


注:本文中的comments.models.Comment.get_content_type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。