Example #1
0
def campaign_list(request):
    """List all campaigns for the logged in user

    **Attributes**:

        * ``template`` - frontend/campaign/list.html

    **Logic Description**:

        * List all campaigns belonging to the logged in user
    """
    form = CampaignSearchForm(request.user)
    request.session["pagination_path"] = request.META["PATH_INFO"] + "?" + request.META["QUERY_STRING"]
    sort_col_field_list = ["id", "name", "startingdate", "status", "totalcontact"]
    default_sort_field = "id"
    pagination_data = get_pagination_vars(request, sort_col_field_list, default_sort_field)

    PAGE_SIZE = pagination_data["PAGE_SIZE"]
    sort_order = pagination_data["sort_order"]
    start_page = pagination_data["start_page"]
    end_page = pagination_data["end_page"]

    phonebook_id = ""
    status = "all"
    search_tag = 1
    if request.method == "POST":
        form = CampaignSearchForm(request.user, request.POST)
        if form.is_valid():
            field_list = ["phonebook_id", "status"]
            unset_session_var(request, field_list)

            phonebook_id = getvar(request, "phonebook_id", setsession=True)
            status = getvar(request, "status", setsession=True)

    post_var_with_page = 0
    try:
        if request.GET.get("page") or request.GET.get("sort_by"):
            post_var_with_page = 1
            phonebook_id = request.session.get("session_phonebook_id")
            status = request.session.get("session_status")
            form = CampaignSearchForm(request.user, initial={"status": status, "phonebook_id": phonebook_id})
        else:
            post_var_with_page = 1
            if request.method == "GET":
                post_var_with_page = 0
    except:
        pass

    if post_var_with_page == 0:
        # default
        # unset session var
        field_list = ["status", "phonebook_id"]
        unset_session_var(request, field_list)

    kwargs = {}
    if phonebook_id and phonebook_id != "0":
        kwargs["phonebook__id__in"] = [int(phonebook_id)]

    if status and status != "all":
        kwargs["status"] = status

    campaign_list = Campaign.objects.filter(user=request.user).order_by(sort_order)
    campaign_count = campaign_list.count()
    if kwargs:
        all_campaign_list = campaign_list.filter(**kwargs).order_by(sort_order)
        campaign_list = all_campaign_list[start_page:end_page]
        campaign_count = all_campaign_list.count()

    template = "frontend/campaign/list.html"
    data = {
        "form": form,
        "search_tag": search_tag,
        "campaign_list": campaign_list,
        "total_campaign": campaign_count,
        "PAGE_SIZE": PAGE_SIZE,
        "CAMPAIGN_COLUMN_NAME": CAMPAIGN_COLUMN_NAME,
        "CAMPAIGN_STATUS": CAMPAIGN_STATUS,
        "col_name_with_order": pagination_data["col_name_with_order"],
        "msg": request.session.get("msg"),
        "error_msg": request.session.get("error_msg"),
        "info_msg": request.session.get("info_msg"),
        "dialer_setting_msg": user_dialer_setting_msg(request.user),
    }
    request.session["msg"] = ""
    request.session["error_msg"] = ""
    request.session["info_msg"] = ""
    return render_to_response(template, data, context_instance=RequestContext(request))
Example #2
0
def campaign_list(request):
    """List all campaigns for the logged in user

    **Attributes**:

        * ``template`` - dialer_campaign/campaign/list.html

    **Logic Description**:

        * List all campaigns belonging to the logged in user
    """
    form = CampaignSearchForm(request.user, request.POST or None)
    request.session['pagination_path'] = request.META['PATH_INFO'] + '?' + request.META['QUERY_STRING']
    sort_col_field_list = ['id', 'name', 'startingdate', 'status', 'totalcontact']
    pag_vars = get_pagination_vars(request, sort_col_field_list, default_sort_field='id')
    phonebook_id = ''
    status = 'all'
    post_var_with_page = 0

    if form.is_valid():
        field_list = ['phonebook_id', 'status']
        unset_session_var(request, field_list)
        phonebook_id = getvar(request, 'phonebook_id', setsession=True)
        status = getvar(request, 'status', setsession=True)
        post_var_with_page = 1

    # This logic to retain searched result set while accessing pagination or sorting on column
    # post_var_with_page will check following thing
    # 1) if page has previously searched value, then post_var_with_page become 1
    # 2) if not then post_var_with_page remain 0 & flush the session variables' value
    if request.GET.get('page') or request.GET.get('sort_by'):
        post_var_with_page = 1
        phonebook_id = request.session.get('session_phonebook_id')
        status = request.session.get('session_status')
        form = CampaignSearchForm(request.user, initial={'status': status, 'phonebook_id': phonebook_id})

    if post_var_with_page == 0:
        # default / unset session var
        field_list = ['status', 'phonebook_id']
        unset_session_var(request, field_list)

    #Set search on user as default
    kwargs = {'user': request.user}
    if phonebook_id and phonebook_id != '0':
        kwargs['phonebook__id__in'] = [int(phonebook_id)]
    if status and status != 'all':
        kwargs['status'] = status

    all_campaign_list = Campaign.objects.filter(**kwargs).order_by(pag_vars['sort_order'])
    campaign_list = all_campaign_list[pag_vars['start_page']:pag_vars['end_page']]
    campaign_count = all_campaign_list.count()

    data = {
        'form': form,
        'all_campaign_list': all_campaign_list,
        'campaign_list': campaign_list,
        'total_campaign': campaign_count,
        'CAMPAIGN_COLUMN_NAME': CAMPAIGN_COLUMN_NAME,
        'col_name_with_order': pag_vars['col_name_with_order'],
        'msg': request.session.get('msg'),
        'error_msg': request.session.get('error_msg'),
        'info_msg': request.session.get('info_msg'),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    request.session['info_msg'] = ''
    return render_to_response('dialer_campaign/campaign/list.html', data, context_instance=RequestContext(request))