def observation_search(request):

    form_kwargs = {}
    if request.GET:
        form_kwargs['data'] = request.GET
    form = ObservationSearchForm(**form_kwargs)
    paging_form = PagingForm(prefix='paging', **form_kwargs)
    
    observation_list = tuple()

    if form.is_valid():
        observation_list = form.results()
    
    per_page = 1
    page = 1
    if paging_form.is_valid():
        if 'per_page' in paging_form.cleaned_data:
            per_page = paging_form.cleaned_data['per_page']
        if 'page_num' in paging_form.cleaned_data:
            page = paging_form.cleaned_data['page_num']

    paginator = Paginator(observation_list, per_page)

    try:
        observations = paginator.page(page)
    except (EmptyPage, InvalidPage):
        observations = paginator.page(paginator.num_pages)
    
    template_media = Media(js=(settings.JQUERY_FILE,))

    return render_to_response(
        "incidents/observation_search.html",
        {
            'form': form,
            'paging_form': paging_form,
            'media': form.media,
            'media': template_media + form.media,
            'observations': observations,
            'observation_count': paginator.count,
        },
        context_instance= RequestContext(request),
    )
def animal_search(request):
    form_kwargs = {}
    if request.GET:
        form_kwargs['data'] = request.GET
    form = AnimalSearchForm(**form_kwargs)
    paging_form = PagingForm(prefix='paging', **form_kwargs)
    
    animal_list = tuple()
    
    if form.is_valid():
        animal_list = form.results()

    per_page = 1
    page = 1
    if paging_form.is_valid():
        if 'per_page' in paging_form.cleaned_data:
            per_page = paging_form.cleaned_data['per_page']
        if 'page_num' in paging_form.cleaned_data:
            page = paging_form.cleaned_data['page_num']

    paginator = Paginator(animal_list, per_page)

    try:
        animals = paginator.page(page)
    except (EmptyPage, InvalidPage):
        animals = paginator.page(paginator.num_pages)
    
    template_media = Media(js=(settings.JQUERY_FILE,))
    media = template_media + form.media + paging_form.media

    return render_to_response(
        "incidents/animal_search.html",
        {
            'form': form,
            'paging_form': paging_form,
            'media': media,
            'animals': animals,
            'animal_count': paginator.count,
        },
        RequestContext(request),
    )