示例#1
0
def detail(request, jurisdiction, jidx, slug, idx):
    """Details for an agency"""

    agency = get_object_or_404(Agency.objects.select_related(
        'jurisdiction', 'jurisdiction__parent',
        'jurisdiction__parent__parent'),
                               jurisdiction__slug=jurisdiction,
                               jurisdiction__pk=jidx,
                               slug=slug,
                               pk=idx,
                               status='approved')

    foia_requests = agency.get_requests()
    foia_requests = (foia_requests.get_viewable(
        request.user).filter(agency=agency).select_related(
            'agency__jurisdiction__parent__parent', ).order_by(
                '-composer__datetime_submitted')[:10])

    if request.method == 'POST':
        action = request.POST.get('action')
        form = FlagForm(request.POST)
        if action == 'flag':
            if form.is_valid() and request.user.is_authenticated():
                FlaggedTask.objects.create(
                    user=request.user,
                    text=form.cleaned_data.get('reason'),
                    agency=agency)
                messages.success(request, 'Correction submitted. Thanks!')
                return redirect(agency)
        elif action == 'review' and request.user.is_staff:
            task = ReviewAgencyTask.objects.ensure_one_created(
                agency=agency,
                resolved=False,
            )
            messages.success(request, 'Agency marked for review.')
            return redirect(
                reverse('review-agency-task', kwargs={'pk': task.pk}))
    else:
        form = FlagForm()

    context = {
        'agency':
        agency,
        'foia_requests':
        foia_requests,
        'form':
        form,
        'sidebar_admin_url':
        reverse('admin:agency_agency_change', args=(agency.pk, )),
    }

    collect_stats(agency, context)

    return render(
        request,
        'profile/agency.html',
        context,
    )
示例#2
0
文件: views.py 项目: WPMedia/muckrock
def detail(request, jurisdiction, jidx, slug, idx):
    """Details for an agency"""

    agency = get_object_or_404(
        Agency.objects.select_related("jurisdiction", "jurisdiction__parent",
                                      "jurisdiction__parent__parent"),
        jurisdiction__slug=jurisdiction,
        jurisdiction__pk=jidx,
        slug=slug,
        pk=idx,
        status="approved",
    )

    foia_requests = agency.get_requests()
    foia_requests = (foia_requests.get_viewable(request.user).filter(
        agency=agency).select_related("agency__jurisdiction__parent__parent").
                     order_by("-composer__datetime_submitted")[:10])

    if request.method == "POST":
        action = request.POST.get("action")
        form = FlagForm(request.POST)
        if action == "flag":
            if form.is_valid() and request.user.is_authenticated:
                FlaggedTask.objects.create(
                    user=request.user,
                    text=form.cleaned_data.get("reason"),
                    agency=agency,
                )
                messages.success(request, "Correction submitted. Thanks!")
                return redirect(agency)
        elif action == "review" and request.user.is_staff:
            task = ReviewAgencyTask.objects.ensure_one_created(agency=agency,
                                                               resolved=False)
            messages.success(request, "Agency marked for review.")
            return redirect(
                reverse("review-agency-task", kwargs={"pk": task.pk}))
    else:
        form = FlagForm()

    context = {
        "agency":
        agency,
        "foia_requests":
        foia_requests,
        "form":
        form,
        "sidebar_admin_url":
        reverse("admin:agency_agency_change", args=(agency.pk, )),
    }

    collect_stats(agency, context)

    return render(request, "profile/agency.html", context)