示例#1
0
def flag(request):
    
    content_type = request.POST.get("content_type")
    object_id = request.POST.get("object_id")
    creator_field = request.POST.get("creator_field")
    comment = request.POST.get("comment")
    next = request.POST.get("next")
    
    content_type = get_object_or_404(ContentType, id = int(content_type))
    object_id = int(object_id)
    
    content_object = content_type.get_object_for_this_type(id=object_id)
    
    if creator_field and hasattr(content_object, creator_field):
        creator = getattr(content_object, creator_field)
    else:
        creator = None
    
    add_flag(request.user, content_type, object_id, creator, comment)
    messages.success(request, _("You have added a flag. A moderator will review your submission shortly."), fail_silently=True)
    
    if next:
        return HttpResponseRedirect(next)
    else:
        return HttpResponseRedirect(reverse('flag-reported'))
示例#2
0
def flag(request):

    content_type = request.POST.get("content_type")
    object_id = request.POST.get("object_id")
    creator_field = request.POST.get("creator_field")
    comment = request.POST.get("comment")
    next = request.POST.get("next")

    content_type = get_object_or_404(ContentType, id=int(content_type))
    object_id = int(object_id)

    content_object = content_type.get_object_for_this_type(id=object_id)

    if creator_field and hasattr(content_object, creator_field):
        creator = getattr(content_object, creator_field)
    else:
        creator = None

    add_flag(request.user, content_type, object_id, creator, comment)
    messages.success(
        request,
        _("You have added a flag. A moderator will review your submission shortly."
          ),
        fail_silently=True)

    if next:
        return HttpResponseRedirect(next)
    else:
        return HttpResponseRedirect(reverse('flag-reported'))
示例#3
0
def flag(request):
    
    content_type = request.POST.get("content_type")
    object_id = request.POST.get("object_id")
    creator_field = request.POST.get("creator_field")
    comment = request.POST.get("comment")
    next = request.POST.get("next")
    
    content_type = get_object_or_404(ContentType, id = int(content_type))
    object_id = int(object_id)
    
    content_object = content_type.get_object_for_this_type(id=object_id)
    
    if creator_field and hasattr(content_object, creator_field):
        creator = getattr(content_object, creator_field)
    else:
        creator = None
    
    add_flag(request.user, content_type, object_id, creator, comment)
    request.user.message_set.create(
        message = _("You have added a flag. A moderator will review your "
            "submission shortly.")
    )
    
    if next:
        return HttpResponseRedirect(next)
    else:
        return Http404
示例#4
0
def flag(request):
    if request.method!="POST":
        raise Http404
    category_id = request.POST.get("id_comment")
    content_type = request.POST.get("content_type")
    object_id = request.POST.get("object_id")
    creator_field = request.POST.get("creator_field")
    comment = request.POST.get("comment")
    next = request.POST.get("next")
    
    content_type = get_object_or_404(ContentType, id = int(content_type))
    object_id = int(object_id)
    
    content_object = content_type.get_object_for_this_type(id=object_id)
    
    category=None
    if category_id:
        try:
            category = FlagCategory.objects.get(pk=category_id)
        except FlagCategory.DoesNotExist:
            category = None
    
    if creator_field and hasattr(content_object, creator_field):
        creator = getattr(content_object, creator_field)
    else:
        creator = None
    
    add_flag(request.user, content_type, object_id, creator, comment, category)
    messages.add_message(request, messages.INFO, _("You have added a flag. A "
        "moderator will review your submission shortly."))
    
    if next:
        return HttpResponseRedirect(next)
    else:
        return Http404
示例#5
0
def flag(request):

    content_type = request.POST.get("content_type")
    object_id = request.POST.get("object_id")
    creator_field = request.POST.get("creator_field")
    comment = request.POST.get("comment")
    next = request.POST.get("next")

    content_type = get_object_or_404(ContentType, id=int(content_type))
    object_id = int(object_id)

    content_object = content_type.get_object_for_this_type(id=object_id)

    if creator_field and hasattr(content_object, creator_field):
        creator = getattr(content_object, creator_field)
    else:
        creator = None

    add_flag(request.user, content_type, object_id, creator, comment)
    request.user.message_set.create(
        message=
        "You have added a flag. A moderator will review your submission shortly."
    )

    if next:
        return HttpResponseRedirect(next)
    else:
        return Http404
示例#6
0
 def flag(self, what, comment, flag_type):
     ct = ContentType.objects.get_for_model(what)
     add_flag(self.bobby,
              ct,
              what.pk,
              self.bobby,
              comment,
              status=None,
              flag_type=flag_type)
示例#7
0
    def test_add_flag_compatibility(self):
        """
        Test the old "add_flag" function, kept for compatibility
        """
        flag_instance = add_flag(
            self.user,
            ContentType.objects.get_for_model(self.model_with_author),
            self.model_with_author.id,
            None,
            'comment')

        self.assertTrue(isinstance(flag_instance, FlagInstance))
        self.assertEqual(flag_instance.flagged_content.content_object,
                         self.model_with_author)
示例#8
0
def flag(request):

    content_type = request.POST.get("content_type")
    object_id = request.POST.get("object_id")
    creator_field = request.POST.get("creator_field")
    comment = request.POST.get("comment")
    next = request.POST.get("next")

    content_type = get_object_or_404(ContentType, id=int(content_type))
    object_id = int(object_id)

    content_object = content_type.get_object_for_this_type(id=object_id)

    if creator_field and hasattr(content_object, creator_field):
        creator = getattr(content_object, creator_field)
    else:
        creator = None

    add_flag(content_type, object_id, creator, comment)

    if next:
        return HttpResponseRedirect(next)
    else:
        return Http404
示例#9
0
def flagplugin(request, pluginid):
    '''Flag a plugin as inappropriate content.'''
    try:
        plugin = BiogpsPlugin.objects.get(id=pluginid)
    except BiogpsPlugin.DoesNotExist:
        return ExtError('Plugin does not exist (id "%s").' % pluginid)
    try:
        content_type = ContentType.objects.get(
            app_label=plugin._meta.app_label, model=plugin._meta.model_name)
    except BiogpsPlugin.DoesNotExist:
        return ExtError('ContenType for "BiogpsPlugin" does not exist.')

    reason = "Reason: " + request.POST.get("reason")
    comment = smart_unicode(reason + ".\nComment: " + request.POST.get("comment", ''))

    user_agent = request.META.get('HTTP_USER_AGENT', '')

    #apply flag
    from flag.models import add_flag
    flaginstance = add_flag(request.user, content_type, plugin.id, plugin.owner, comment)
    site = Site.objects.get_current()
    #notify moderator
    from django.core.mail import mail_managers
    mail_managers(subject='Plugin was flagged by a user',
                  message=render_to_string('plugin/plugin_flagged_notification.txt', {'flagger': request.user,
                                                                                'plugin': plugin,
                                                                                'flaginstance': flaginstance,
                                                                                'user_agent': user_agent,
                                                                                'site': site}),
                  fail_silently=True)
    #notify plugin owner
    if plugin.owner and plugin.owner.email:
        from django.core.mail import send_mail
        send_mail('Your plugin was flagged by a user',
                  render_to_string('plugin/plugin_flagged_notification.txt', {'flagger': request.user,
                                                                        'plugin': plugin,
                                                                        'flaginstance': flaginstance,
                                                                        'site': site,
                                                                        'user_agent': user_agent,
                                                                        'for_plugin_owner': True}),
                  settings.DEFAULT_FROM_EMAIL,
                  [plugin.owner.email])

    json_response = {'success': True,
                     'msg': 'You have added a flag. A moderator will review your submission shortly.'}
    return JSONResponse(json_response)
示例#10
0
文件: tests.py 项目: Geocent/mapstory
 def flag(self, what, comment, flag_type):
     ct = ContentType.objects.get_for_model(what)
     add_flag(self.bobby, ct, what.pk, self.bobby, comment, status=None,
              flag_type=flag_type)