Ejemplo n.º 1
0
def index(request):
    if request.GET.get('page'):
        qset = search(*settings.DEFAULT_SEARCH_MODELS, is_parent=False)
        paginator = Paginator(qset, settings.PAGINATE)
        page = request.GET.get('page', 1)
        try:
            page = paginator.page(page)
            page.object_list = [res.object for res in page.object_list]
        except InvalidPage:
            raise Http404

        context = {
            'page': page
        }

        return render(request, 'combined_list.html', context)

    else:
        events = [r.object for r in search(*settings.DEFAULT_SEARCH_MODELS, is_parent=False).order_by('-date')[:3]]
        context = {
            'latest_events': events,
            # 'latest_annotations': Annotation.objects.published().select_related()[:3],
            # 'committees': Committee.objects.all().select_related(),
            # 'featured_photo': hearings[0].photos.all()[0],
            'leaderboard': Person.objects.with_counts(min_tags=1)[:5]
        }

        return render(request, 'index.html', context)
Ejemplo n.º 2
0
def person_detail(request, slug):
    person = get_object_or_404(Person, slug=slug)
    event_ids = [annot.event.id for annot in person.annotations.published(request.user)]
    recent_events = search(pk__in=event_ids).order_by("-date")[:5]
    # recent_hearings = Hearing.objects.published(request.user).filter(pk__in=hearing_ids).order_by('-start_datetime')[:5]

    context = {"person": person, "recent_events": recent_events}
    return render(request, "people/person_detail.html", context)
Ejemplo n.º 3
0
def search_json(request):
    query = request.GET.get("search")
    results = []
    if query:
        for result in search("people", content=query + "*"):
            try:
                results.append(result.object.to_suggest())
            except:
                pass

    return HttpResponse(json.dumps(results), content_type="application/json")