예제 #1
0
def convocation(request, convocation_id):
    conv = get_object_or_404(Convocation.objects.annotate(
        num_mps=Count('mp2convocation', distinct=True),
        num_minions=Count('mp2convocation__minion')),
                             number=int(convocation_id))

    letter = request.GET.get("letter", False)

    mps = MP2Convocation.objects.select_related("mp").filter(
        convocation=conv
    ).order_by("mp__name").extra(
        select={'first_letter': "SUBSTR(core_memberofparliament.name, 1, 1)"})

    alphabet = MP2Convocation.objects.select_related("mp").filter(
        convocation=conv).order_by("mp__name").extra(
            select={
                'first_letter': "SUBSTR(core_memberofparliament.name, 1, 1)"
            }).values_list('first_letter', flat=True)

    if letter not in alphabet:
        letter = False

    if letter:
        mps = mps.filter(mp__name__startswith=letter)

    return render(
        request, "convocation.jinja", {
            "convocation": conv,
            "alphabet": Counter(map(str.upper, alphabet)),
            "current_letter": letter,
            "mps": paginated(request, mps, DjangoPageRangePaginator),
        })
예제 #2
0
def convocation(request, convocation_id):
    conv = get_object_or_404(Convocation.objects.annotate(
        num_mps=Count('mp2convocation', distinct=True),
        num_minions=Count('mp2convocation__minion')),
        number=int(convocation_id))

    letter = request.GET.get("letter", False)

    mps = MP2Convocation.objects.select_related("mp").filter(
        convocation=conv).order_by("mp__name").extra(
        select={'first_letter': "SUBSTR(core_memberofparliament.name, 1, 1)"})

    alphabet = MP2Convocation.objects.select_related("mp").filter(
        convocation=conv).order_by("mp__name").extra(
            select={
                'first_letter': "SUBSTR(core_memberofparliament.name, 1, 1)"
            }
        ).values_list('first_letter', flat=True)

    if letter not in alphabet:
        letter = False

    if letter:
        mps = mps.filter(mp__name__startswith=letter)

    return render(request, "convocation.jinja", {
        "convocation": conv,
        "alphabet": Counter(map(str.upper, alphabet)),
        "current_letter": letter,
        "mps": paginated(request, mps, DjangoPageRangePaginator),
    })
예제 #3
0
def search(request):
    query = request.GET.get("q", "")

    if query:
        persons = ElasticMinion.search().query(
            "multi_match", query=query,
            operator="and",
            fields=["mp.name", "name"])
    else:
        persons = ElasticMinion.search().query('match_all')

    return render(request, "search.jinja", {
        "minions": paginated(
            request, persons.sort('mp.grouper', '-paid', 'name'), cnt=30),
        "q": query
    })
예제 #4
0
def search(request):
    query = request.GET.get("q", "")

    if query:
        persons = ElasticMinion.search().query(
            "multi_match",
            query=query,
            operator="and",
            fields=["mp.name", "name", "persons"])
    else:
        persons = ElasticMinion.search().query('match_all')

    return render(
        request, "search.jinja", {
            "minions":
            paginated(request,
                      persons.sort('mp.grouper', '-paid', 'name.raw'),
                      cnt=30),
            "q":
            query
        })