示例#1
0
def dnc_contact_list(request):
    """DNC Contact list for the logged in user

    **Attributes**:

        * ``template`` - dnc/dnc_contact/list.html
        * ``form`` - ContactSearchForm

    **Logic Description**:

        * List all dnc contacts from dnc lists belonging to the logged in user
    """
    sort_col_field_list = ['id', 'dnc', 'phone_number', 'updated_date']
    pag_vars = get_pagination_vars(request, sort_col_field_list, default_sort_field='id')
    form = DNCContactSearchForm(request.user, request.POST or None)
    dnc_id_list = DNC.objects.values_list('id', flat=True).filter(user=request.user)
    phone_number = ''
    dnc = ''
    post_var_with_page = 0
    if form.is_valid():
        request.session['session_phone_number'] = ''
        request.session['session_dnc'] = ''
        post_var_with_page = 1
        phone_number = getvar(request, 'phone_number', setsession=True)
        dnc = getvar(request, 'dnc', setsession=True)

    if request.GET.get('page') or request.GET.get('sort_by'):
        post_var_with_page = 1
        phone_number = request.session.get('session_phone_number')
        dnc = request.session.get('session_dnc')
        form = DNCContactSearchForm(request.user, initial={'phone_number': phone_number, 'dnc': dnc})

    if post_var_with_page == 0:
        # default
        # unset session var
        request.session['session_phone_number'] = ''
        request.session['session_dnc'] = ''

    kwargs = {'dnc__in': dnc_id_list}
    if dnc and dnc != '0':
        kwargs['dnc_id'] = dnc

    phone_number_type = '1'
    phone_number = source_desti_field_chk(phone_number, phone_number_type, 'phone_number')
    for i in phone_number:
        kwargs[i] = phone_number[i]

    phone_number_list = []
    all_phone_number_list = []
    phone_number_count = 0

    if dnc_id_list:
        all_phone_number_list = DNCContact.objects.values(
            'id', 'dnc__name', 'phone_number', 'updated_date').filter(**kwargs).order_by(pag_vars['sort_order'])

        phone_number_list = all_phone_number_list[pag_vars['start_page']:pag_vars['end_page']]
        phone_number_count = all_phone_number_list.count()

    data = {
        'phone_number_list': phone_number_list,
        'all_phone_number_list': all_phone_number_list,
        'total_phone_numbers': phone_number_count,
        'DNC_CONTACT_COLUMN_NAME': DNC_CONTACT_COLUMN_NAME,
        'col_name_with_order': pag_vars['col_name_with_order'],
        'msg': request.session.get('msg'),
        'error_msg': request.session.get('error_msg'),
        'form': form,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response('dnc/dnc_contact/list.html', data, context_instance=RequestContext(request))
示例#2
0
def contact_list(request):
    """Contact list for the logged in user

    **Attributes**:

        * ``template`` - dialer_contact/contact/list.html
        * ``form`` - ContactSearchForm

    **Logic Description**:

        * List all contacts from phonebooks belonging to the logged in user
    """
    sort_col_field_list = ['id', 'phonebook', 'contact', 'status', 'first_name', 'last_name', 'email', 'updated_date']
    pag_vars = get_pagination_vars(request, sort_col_field_list, default_sort_field='id')
    form = ContactSearchForm(request.user, request.POST or None)
    phonebook_id_list = Phonebook.objects.values_list('id', flat=True).filter(user=request.user)

    contact_no = ''
    contact_name = ''
    phonebook = ''
    contact_status = STATUS_CHOICE.ALL
    post_var_with_page = 0
    if form.is_valid():
        field_list = ['contact_no', 'contact_name', 'contact_status', 'phonebook']
        unset_session_var(request, field_list)

        contact_no = getvar(request, 'contact_no', setsession=True)
        contact_name = getvar(request, 'contact_name', setsession=True)
        contact_status = getvar(request, 'contact_status', setsession=True)
        phonebook = getvar(request, 'phonebook', setsession=True)
        post_var_with_page = 1

    if request.GET.get('page') or request.GET.get('sort_by'):
        post_var_with_page = 1
        contact_no = request.session.get('session_contact_no')
        contact_name = request.session.get('session_contact_name')
        contact_status = request.session.get('session_contact_status')
        phonebook = request.session.get('session_phonebook')
        form = ContactSearchForm(request.user,
                                 initial={'contact_no': contact_no,
                                          'contact_name': contact_name,
                                          'status': contact_status,
                                          'phonebook': phonebook})

    if post_var_with_page == 0:
        # default
        # unset session var
        field_list = ['contact_no', 'contact_name', 'contact_status', 'phonebook']
        unset_session_var(request, field_list)

    kwargs = {}
    if phonebook and phonebook != '0':
        kwargs['phonebook'] = phonebook

    if contact_status and int(contact_status) != STATUS_CHOICE.ALL:
        kwargs['status'] = contact_status

    contact_no_type = '1'
    contact_no = source_desti_field_chk(contact_no, contact_no_type, 'contact')
    for i in contact_no:
        kwargs[i] = contact_no[i]

    contact_list = []
    all_contact_list = []
    contact_count = 0

    if phonebook_id_list:
        contact_list = Contact.objects.values('id', 'phonebook__name', 'contact', 'last_name', 'first_name', 'email', 'status', 'updated_date')\
            .filter(phonebook__in=phonebook_id_list)

        if kwargs:
            contact_list = contact_list.filter(**kwargs)

        if contact_name:
            # Search on contact name
            contact_name_filter = (
                Q(last_name__icontains=contact_name) | Q(first_name__icontains=contact_name)
            )
            if contact_name_filter:
                contact_list = contact_list.filter(contact_name_filter)

        all_contact_list = contact_list.order_by(pag_vars['sort_order'])
        contact_list = all_contact_list[pag_vars['start_page']:pag_vars['end_page']]
        contact_count = all_contact_list.count()

    data = {
        'contact_list': contact_list,
        'all_contact_list': all_contact_list,
        'total_contacts': contact_count,
        'CONTACT_COLUMN_NAME': CONTACT_COLUMN_NAME,
        'col_name_with_order': pag_vars['col_name_with_order'],
        'msg': request.session.get('msg'),
        'error_msg': request.session.get('error_msg'),
        'form': form,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response('dialer_contact/contact/list.html', data, context_instance=RequestContext(request))
示例#3
0
def dnc_contact_list(request):
    """DNC Contact list for the logged in user

    **Attributes**:

        * ``template`` - dnc/dnc_contact/list.html
        * ``form`` - ContactSearchForm

    **Logic Description**:

        * List all dnc contacts from dnc lists belonging to the logged in user
    """
    sort_col_field_list = ["id", "dnc", "phone_number", "updated_date"]
    pag_vars = get_pagination_vars(request, sort_col_field_list, default_sort_field="id")
    form = DNCContactSearchForm(request.user, request.POST or None)
    dnc_id_list = DNC.objects.values_list("id", flat=True).filter(user=request.user)
    phone_number = ""
    dnc = ""
    post_var_with_page = 0
    if form.is_valid():
        request.session["session_phone_number"] = ""
        request.session["session_dnc"] = ""
        post_var_with_page = 1
        phone_number = getvar(request, "phone_number", setsession=True)
        dnc = getvar(request, "dnc", setsession=True)

    if request.GET.get("page") or request.GET.get("sort_by"):
        post_var_with_page = 1
        phone_number = request.session.get("session_phone_number")
        dnc = request.session.get("session_dnc")
        form = DNCContactSearchForm(request.user, initial={"phone_number": phone_number, "dnc": dnc})

    if post_var_with_page == 0:
        # default
        # unset session var
        request.session["session_phone_number"] = ""
        request.session["session_dnc"] = ""

    kwargs = {"dnc__in": dnc_id_list}
    if dnc and dnc != "0":
        kwargs["dnc_id"] = dnc

    phone_number_type = "1"
    phone_number = source_desti_field_chk(phone_number, phone_number_type, "phone_number")
    for i in phone_number:
        kwargs[i] = phone_number[i]

    phone_number_list = []
    all_phone_number_list = []
    phone_number_count = 0

    if dnc_id_list:
        all_phone_number_list = (
            DNCContact.objects.values("id", "dnc__name", "phone_number", "updated_date")
            .filter(**kwargs)
            .order_by(pag_vars["sort_order"])
        )

        phone_number_list = all_phone_number_list[pag_vars["start_page"] : pag_vars["end_page"]]
        phone_number_count = all_phone_number_list.count()

    data = {
        "phone_number_list": phone_number_list,
        "all_phone_number_list": all_phone_number_list,
        "total_phone_numbers": phone_number_count,
        "DNC_CONTACT_COLUMN_NAME": DNC_CONTACT_COLUMN_NAME,
        "col_name_with_order": pag_vars["col_name_with_order"],
        "msg": request.session.get("msg"),
        "error_msg": request.session.get("error_msg"),
        "form": form,
    }
    request.session["msg"] = ""
    request.session["error_msg"] = ""
    return render_to_response("dnc/dnc_contact/list.html", data, context_instance=RequestContext(request))