def contact_search(request):

    form_kwargs = {}
    if request.GET:
        form_kwargs['data'] = request.GET
    form = ContactSearchForm(**form_kwargs)
    paging_form = PagingForm(prefix='paging', **form_kwargs)
        
    contact_list = tuple()
    
    if form.is_valid():
        contact_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(contact_list, per_page)

    try:
        contacts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        contacts = paginator.page(paginator.num_pages)
    
    template_media = Media(js=(settings.JQUERY_FILE,))
    
    return render_to_response(
        "contacts/contact_search.html",
        {
            'form': form,
            'paging_form': paging_form,
            'media': template_media + form.media,
            'contacts': contacts,
            'contact_count': paginator.count,
        },
        context_instance= RequestContext(request),
    )
Exemple #2
0
def main():
    search = ContactSearchForm(request.form)
    if request.method == 'POST':
        if request.form['submit'] == 'Search':
            selected, search_term = search.data['select'], search.data[
                'search']
            final_results = get_results(selected, search_term)
            return render_template(
                'results.html',
                form=search,
                final_results=final_results,
                selected=selected,
                search_term=search_term,
                display_job_history=display_job_history_as_a_string)

    return render_template('index.html', form=search)
Exemple #3
0
def search_contact_export(request):
    response = HttpResponse(mimetype="application/ms-excel")
    response['Content-Disposition'] = 'attachment; filename=esportazione_ricerca_contatti.xls'
    wb = xlwt.Workbook()
    ws = wb.add_sheet('Foglio 1')
    ws.write(0, 0, 'Identificativo')
    ws.write(0,1,'Username')
    ws.write(0, 2, 'Cognome')
    ws.write(0, 3, 'Nome')
    ws.write(0, 4, 'Sesso')
    ws.write(0, 5, 'Data Di nascita')
    ws.write(0, 6, 'Indirizzo')
    ws.write(0, 7, 'CAP')
    ws.write(0, 8, 'Citta\'')
    ws.write(0, 9, 'Prov')
    ws.write(0, 10, 'Regione')
    ws.write(0, 11, 'Email')
    ws.write(0, 12, 'Qualifica')
    ws.write(0, 13, 'Categoria')
    ws.write(0,14,'Ranking Aziendale')
    ws.write(0,15,'Ranking Partecipazione')
    ws.write(0,16,'Status')

    form = ContactSearchForm(request.GET)
    results = []
    if request.GET.has_key('q'):
        results = form.search()
        # if request.GET.has_key('max_results'):
        #     results = form.search()[:request.GET.get('max_results')]
        # else:
        #     results = form.search()
    contacts = []
    if len(results) > 0:
        max_results = int(request.GET.get('max_results', 10000))
        for r in results:
            if r is not None and r.model_name == 'contact':
                contacts.append(r.object)
                if len(contacts) >= max_results:
                    break
        row = 1
        for c in contacts:
            ws.write(row,0,c.code)
            if c.owner != None:
                ws.write(row,1,c.owner.username)

            ws.write(row,2,c.surname)
            ws.write(row,3,c.name)
            ws.write(row,4,c.sex)
            if c.birthdate:
                ws.write(row,5,c.birthdate.strftime("%d/%m/%Y"))

            ws.write(row,6,c.street+" "+c.civic)
            ws.write(row,7,c.zip)
            ws.write(row,8,c.city)

            if c.province:
                ws.write(row,9,c.province.code)
                ws.write(row,10,c.province.region.name)

            ws.write(row,11,c.email)
            if c.work:
                ws.write(row,12,c.work.name.capitalize())
                ws.write(row,13,c.work.sector.name.capitalize())

            ws.write(row,14,c.company_ranking)
            ws.write(row,15,c.participation_ranking)
            if c.status == 'A':
                ws.write(row,16,"Attivo")
            if c.status == 'N':
                ws.write(row,16,"Non Attivo")
            if c.status == 'I':
                ws.write(row,16,"Inerte")
            if c.status == 'C':
                ws.write(row,16,"Cancellato")
            if c.status == 'D':
                ws.write(row,16,"Non Interessato")
            row +=1
    wb.save(response)
    return response
Exemple #4
0
def search_contact(request):
    provinces = Province.objects.all()
    companies = Company.objects.all()
    works = Work.objects.all()

    form = ContactSearchForm(request.GET)
    search_query = request.GET.get("q", None)
    contacts = None
    ranking_args = {}

    if 'q' in request.GET:
        results = form.search()

        comp_rank_from = request.GET.get("comp_rank_from", None)
        comp_rank_to = request.GET.get("comp_rank_to", None)
        part_rank_from = request.GET.get("part_rank_from", None)
        part_rank_to = request.GET.get("part_rank_to", None)

        ranking_args = {
            "comp_rank_from": comp_rank_from,
            "comp_rank_to": comp_rank_to,
            "part_rank_from": part_rank_from,
            "part_rank_to": part_rank_to
        }

        if comp_rank_from and comp_rank_to:
            # print "### comp range: %s, %s" % (comp_rank_from, comp_rank_to)
            results = results.filter(company_ranking__range=[comp_rank_from, comp_rank_to])
        elif comp_rank_from:
            # print "### comp from: %s" % comp_rank_from
            results = results.filter(company_ranking__gte=comp_rank_from)
        elif comp_rank_to:
            # print "### comp to: %s" % comp_rank_to
            results = results.filter(company_ranking__lte=comp_rank_to)


        if part_rank_from and part_rank_to:
            # print "### part range: %s, %s" % (part_rank_from, part_rank_to)
            results = results.filter(participation_ranking__range=[part_rank_from, part_rank_to])
        elif part_rank_from:
            # print "### part from: %s" % part_rank_from
            results = results.filter(participation_ranking__gte=part_rank_from)
        elif part_rank_to:
            # print "### part to: %s" % part_rank_to
            results = results.filter(participation_ranking__lte=part_rank_to)


        if len(results) > 0:
            # contacts = Contact.objects.filter(pk__in=[r.pk for r in results])
            contacts = []
            max_results = int(request.GET.get('max_results', 10000))
            for r in results:
                # print "### r: %s" % r
                if r is not None and r.model_name == 'contact':
                    contacts.append(r.object)
                    if len(contacts) >= max_results:
                        break

    return render_to_response('admin/search/search_contact.html', {
        'search_query' : search_query,
        'ranking_args': ranking_args,
        'contacts': contacts,
        'form' : form,
        'provinces' : provinces,
        'companies' : companies,
        'works' : works,
    }, context_instance=RequestContext(request))