示例#1
0
文件: views.py 项目: MechanisM/froide
def list_requests(request, status=None, topic=None, tag=None, jurisdiction=None):
    context = {
        'filtered': True
    }
    topic_list = PublicBodyTopic.objects.get_list()
    if status is not None:
        status = FoiRequest.STATUS_URLS_DICT[status]
        foi_requests = FoiRequest.published.for_list_view().filter(status=status)
        context.update({
            'status': FoiRequest.get_readable_status(status),
            'status_description': FoiRequest.get_status_description(status)
        })
    elif topic is not None:
        topic = get_object_or_404(PublicBodyTopic, slug=topic)
        foi_requests = FoiRequest.published.for_list_view().filter(public_body__topic=topic)
        context.update({
            'topic': topic,
            })
    elif tag is not None:
        tag_object = get_object_or_404(Tag, slug=tag)
        foi_requests = FoiRequest.published.for_list_view().filter(tags=tag_object)
        context.update({
            'tag': tag_object
        })
    else:
        foi_requests = FoiRequest.published.for_list_view()
        context['filtered'] = False

    if jurisdiction is not None:
        jurisdiction_object = get_object_or_404(Jurisdiction, slug=jurisdiction)
        foi_requests = foi_requests.filter(jurisdiction=jurisdiction_object)
        context.update({
            'jurisdiction': jurisdiction_object
        })
    else:
        context['jurisdiction_list'] = Jurisdiction.objects.get_visible()

    context.update({
        'page_title': _("FoI Requests"),
        'count': foi_requests.count(),
        'object_list': foi_requests,
        'status_list': [(x[0],
            FoiRequest.get_readable_status(x[1]), x[1]) for x in FoiRequest.STATUS_URLS],
        'topic_list': topic_list
    })

    return render(request, 'foirequest/list.html', context)