Exemplo n.º 1
0
def report_abuse(request, model, app_label, pk):
    """Report abusive or irrelavent content."""
    if request.method == 'POST':
        # we only use the form for the csrf middleware. skip validation.
        form = AbuseForm(request.POST)
        content_type_cls = get_object_or_404(ContentType, model=model,
            app_label=app_label).model_class()
        instance = get_object_or_404(content_type_cls, pk=pk)
        try:
            url = request.build_absolute_uri(instance.get_absolute_url())
        except NoReverseMatch:
            url = request.build_absolute_uri(reverse('dashboard'))
        subject_template = 'drumbeat/emails/abuse_report_subject.txt'
        body_template = 'drumbeat/emails/abuse_report.txt'
        context = {
            'user': request.user.get_profile(),
            'url': url, 'model': model,
            'app_label': app_label, 'pk': pk,
        }
        try:
            profile = UserProfile.objects.get(email=settings.ADMINS[0][1])
            send_notifications([profile], subject_template, body_template, context)
        except:
            log.debug("Error sending abuse report: %s" % sys.exc_info()[0])
            pass
        return render_to_response('drumbeat/report_received.html', {},
                                  context_instance=RequestContext(request))
    else:
        form = AbuseForm()
    return render_to_response('drumbeat/report_abuse.html', {
        'form': form,
        'model': model,
        'app_label': app_label,
        'pk': pk,
    }, context_instance=RequestContext(request))
Exemplo n.º 2
0
def report_abuse(request, obj, type):
    """Report abusive or irrelavent content."""
    if request.method == 'POST':
        # we only use the form for the csrf middleware. skip validation.
        form = AbuseForm(request.POST)
        body = """
        User %s has reported the following content as objectionable:

        Model: %s, ID: %s
        """ % (request.user.get_profile().name, type, obj)
        subject = "Abuse Report"
        try:
            profile = UserProfile.objects.get(email=settings.ADMINS[0][1])
            SendUserEmail.apply_async(args=(profile, subject, body))
        except:
            pass
        return render_to_response('drumbeat/report_received.html', {},
                                  context_instance=RequestContext(request))
    else:
        form = AbuseForm()
    return render_to_response('drumbeat/report_abuse.html', {
        'form': form,
        'obj': obj,
        'type': type,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def report_abuse(request, model, app_label, pk):
    """Report abusive or irrelavent content."""
    if request.method == 'POST':
        # we only use the form for the csrf middleware. skip validation.
        form = AbuseForm(request.POST)
        content_type_cls = get_object_or_404(
            ContentType, model=model, app_label=app_label).model_class()
        instance = get_object_or_404(content_type_cls, pk=pk)
        try:
            url = request.build_absolute_uri(instance.get_absolute_url())
        except NoReverseMatch:
            url = request.build_absolute_uri(reverse('dashboard'))
        ulang = get_language()
        try:
            profile = UserProfile.objects.get(email=settings.ADMINS[0][1])
            activate(profile.preflang or settings.LANGUAGE_CODE)
            body = render_to_string(
                "drumbeat/emails/abuse_report.txt", {
                    'user': request.user.get_profile(),
                    'url': url,
                    'model': model,
                    'app_label': app_label,
                    'pk': pk
                }).strip()
            subject = _("Abuse Report")
            SendUserEmail.apply_async(args=(profile, subject, body))
        except:
            log.debug("Error sending abuse report: %s" % sys.exc_info()[0])
            pass
        activate(ulang)
        return render_to_response('drumbeat/report_received.html', {},
                                  context_instance=RequestContext(request))
    else:
        form = AbuseForm()
    return render_to_response('drumbeat/report_abuse.html', {
        'form': form,
        'model': model,
        'app_label': app_label,
        'pk': pk,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 4
0
def report_abuse(request, model, app_label, pk):
    """Report abusive or irrelavent content."""
    if request.method == 'POST':
        # we only use the form for the csrf middleware. skip validation.
        form = AbuseForm(request.POST)
        content_type_cls = get_object_or_404(
            ContentType, model=model, app_label=app_label).model_class()
        instance = get_object_or_404(content_type_cls, pk=pk)
        try:
            url = request.build_absolute_uri(instance.get_absolute_url())
        except NoReverseMatch:
            url = request.build_absolute_uri(reverse('dashboard_index'))
        body = """
        User %s has reported the following content as objectionable:

        %s
        
        (model: %s, app_label: %s, pk: %s)
        """ % (request.user.get_profile().display_name, url, model, app_label,
               pk)
        subject = "Abuse Report"
        try:
            profile = UserProfile.objects.get(email=settings.ADMINS[0][1])
            SendUserEmail.apply_async(args=(profile, subject, body))
        except:
            pass
        return render_to_response('drumbeat/report_received.html', {},
                                  context_instance=RequestContext(request))
    else:
        form = AbuseForm()
    return render_to_response('drumbeat/report_abuse.html', {
        'form': form,
        'model': model,
        'app_label': app_label,
        'pk': pk,
    },
                              context_instance=RequestContext(request))