当前位置: 首页>>代码示例>>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;未经允许,请勿转载。