Exemplo n.º 1
0
def voipapp_add(request):
    """Add new VoIP App for logged in user

    **Attributes**:

        * ``form`` - VoipAppForm
        * ``template`` - frontend/voipapp/change.html

    **Logic Description**:

        * Add new voip app which will belong to logged in user
          via VoipAppForm form & get redirect to voipapp list
    """
    form = VoipAppForm()
    if request.method == 'POST':
        form = VoipAppForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = User.objects.get(username=request.user)
            obj.save()
            request.session["msg"] = _('"%(name)s" is added successfully.') %\
            request.POST
            return HttpResponseRedirect('/voipapp/')
    template = 'frontend/voipapp/change.html'
    data = {
       'module': current_view(request),
       'form': form,
       'action': 'add',
       'notice_count': notice_count(request),
       'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 2
0
def survey_change(request, object_id):
    """Update/Delete Survey for the logged in user

    **Attributes**:

        * ``object_id`` - Selected survey object
        * ``form`` - SurveyForm
        * ``template`` - frontend/survey/change.html

    **Logic Description**:

        * Update/delete selected survey from the survey list
          via SurveyForm & get redirected to survey list
    """
    survey = SurveyApp.objects.get(pk=object_id)
    survey_que_list = SurveyQuestion.objects\
        .filter(surveyapp=survey).order_by('order')

    survey_response_list = {}
    for survey_que in survey_que_list:
        res_list = SurveyResponse.objects\
                    .filter(surveyquestion=survey_que).order_by('key')
        if res_list:
            # survey question response
            survey_response_list['%s' % survey_que.id] = res_list

    form = SurveyForm(instance=survey)

    if request.method == 'POST':
        if request.POST.get('delete'):
            survey_del(request, object_id)
            return HttpResponseRedirect('/survey/')
        else:
            form = SurveyForm(request.POST, request.user, instance=survey)
            if form.is_valid():
                form.save()
                request.session["msg"] = _('"%(name)s" is updated.')\
                    % {'name': request.POST['name']}
                return HttpResponseRedirect('/survey/')

    template = 'frontend/survey/survey_change.html'

    data = {
        'survey_obj_id': object_id,
        'survey_que_list': survey_que_list,
        'survey_response_list': survey_response_list,
        'module': current_view(request),
        'action': 'update',
        'form': form,
        'msg': request.session.get('msg'),
        'notice_count': notice_count(request),
        }
    request.session['msg'] = ''
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Exemplo n.º 3
0
def survey_list(request):
    """SurveyApp list for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all surveys which belong to the logged in user.
    """
    template = 'frontend/survey/survey_list.html'
    data = {
        'module': current_view(request),
        'msg': request.session.get('msg'),
        'notice_count': notice_count(request),
    }
    request.session['msg'] = ''
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 4
0
def voipapp_list(request):
    """VoIP App list for logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all voip app which are belong to logged in user
    """
    template = 'frontend/voipapp/list.html'
    data = {
        'module': current_view(request),        
        'msg': request.session.get('msg'),
        'notice_count': notice_count(request),
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 5
0
def survey_report(request):
    """AudioFile list for the logged in user

    **Attributes**:

        * ``template`` - frontend/survey/survey_report.html

    **Logic Description**:

        * List all survey_report which belong to the logged in user.
    """
    form = SurveyReportForm(request.user)
    survey_result = ''
    if request.method == 'POST':
        form = SurveyReportForm(request.user, request.POST)
        if form.is_valid():
            try:
                campaign_obj = Campaign.objects.get(id=int(request.POST['campaign']))
                survey_result = SurveyCampaignResult.objects.filter(campaign=campaign_obj)\
                .values('question', 'response').annotate(Count('response')).distinct().order_by('question')

                if not survey_result:
                    request.session["err_msg"] = _('No record found!.')

            except:
                request.session["err_msg"] = _('No campaign attached with survey.')

    template = 'frontend/survey/survey_report.html'
    data = {
        'module': current_view(request),
        'msg': request.session.get('msg'),
        'err_msg': request.session.get('err_msg'),
        'notice_count': notice_count(request),
        'form': form,
        'survey_result': survey_result,
    }
    request.session['msg'] = ''
    request.session['err_msg'] = ''
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 6
0
def audio_list(request):
    """AudioFile list for the logged in user

    **Attributes**:

        * ``template`` - frontend/survey/audio_list.html

    **Logic Description**:

        * List all audios which belong to the logged in user.
    """
    template = 'frontend/survey/audio_list.html'
    data = {
        'module': current_view(request),
        'msg': request.session.get('msg'),
        'notice_count': notice_count(request),
        'audio_list': audio_list,
        'AUDIO_DEBUG': settings.AUDIO_DEBUG,
    }
    request.session['msg'] = ''
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 7
0
def voipapp_change(request, object_id):
    """Update/Delete VoIP app for logged in user

    **Attributes**:

        * ``object_id`` - Selected phonebook object
        * ``form`` - VoipAppForm
        * ``template`` - frontend/voipapp/change.html

    **Logic Description**:

        * Update/delete selected voipapp from voipapp list
          via VoipAppForm form & get redirect to voip list
    """
    voipapp = VoipApp.objects.get(pk=object_id)
    form = VoipAppForm(instance=voipapp)
    if request.method == 'POST':
        if request.POST.get('delete'):
            voipapp_del(request, object_id)
            return HttpResponseRedirect('/voipapp/')
        else:
            form = VoipAppForm(request.POST, instance=voipapp)
            if form.is_valid():
                form.save()
                request.session["msg"] = _('"%(name)s" is updated successfully.' \
                % {'name': request.POST['name']})
                return HttpResponseRedirect('/voipapp/')

    template = 'frontend/voipapp/change.html'
    data = {
       'module': current_view(request),
       'form': form,
       'action': 'update',
       'notice_count': notice_count(request),
       'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 8
0
def view_notification(request, id):
    """Notice view in detail on Customer UI

    **Attributes**

        * ``template`` - 'frontend/registration/user_notice.html'

    **Logic Description**:

        * User is able to change his/her detail.
    """
    user_notice = notification.Notice.objects.get(pk=id)
    user_notice.unseen = 0
    user_notice.save()
    template = 'frontend/registration/user_notice.html'
    data = {
        'module': current_view(request),
        'notice': user_notice,
        'notice_count': notice_count(request),
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 9
0
def voipcall_report(request):
    """VoIP Call Report

    **Attributes**:

        * ``form`` - VoipSearchForm
        * ``template`` - frontend/report/voipcall_report.html

    **Logic Description**:

        * Get VoIP call list according to search parameters for loggedin user

    **Important variable**:

        * ``request.session['voipcall_record_qs']`` - stores voipcall query set
    """
    kwargs = {}
    kwargs['user'] = request.user
    from_date = ''
    to_date = ''
    disposition = variable_value(request, 'status')
    form = VoipSearchForm()
    if request.method == 'POST':

        if request.POST['from_date'] != "":
            from_date = request.POST['from_date']
        if request.POST['to_date'] != "":
            to_date = request.POST['to_date']

        form = VoipSearchForm(request.POST)
        kwargs = voipcall_record_common_fun(request)
    else:
        tday = datetime.today()
        kwargs['starting_date__gte'] = datetime(tday.year,
                                               tday.month,
                                               tday.day, 0, 0, 0, 0)

    voipcall_list = \
    VoIPCall.objects.values('user', 'callid', 'callerid', 'phone_number',
                     'starting_date', 'duration', 'billsec',
                     'disposition', 'hangup_cause', 'hangup_cause_q850',
                     'used_gateway').filter(**kwargs).order_by('-starting_date')

    # Session variable is used to get record set with searched option
    # into export file
    request.session['voipcall_record_qs'] = voipcall_list

    select_data = \
    {"starting_date": "SUBSTR(CAST(starting_date as CHAR(30)),1,10)"}
    total_data = ''
    # Get Total Rrecords from VoIPCall Report table for Daily Call Report
    total_data = VoIPCall.objects.extra(select=select_data)\
                 .values('starting_date')\
                 .filter(**kwargs).annotate(Count('starting_date'))\
                 .annotate(Sum('duration'))\
                 .annotate(Avg('duration'))\
                 .order_by('-starting_date')
    
    # Following code will count total voip calls, duration
    if total_data.count() != 0:
        max_duration = \
        max([x['duration__sum'] for x in total_data])
        total_duration = \
        sum([x['duration__sum'] for x in total_data])
        total_calls = sum([x['starting_date__count'] for x in total_data])
        total_avg_duration = \
        (sum([x['duration__avg']\
        for x in total_data])) / total_data.count()
    else:
        max_duration = 0
        total_duration = 0
        total_calls = 0
        total_avg_duration = 0

    template = 'frontend/report/voipcall_report.html'
    data = {
        'form': form,
        'from_date': from_date,
        'to_date': to_date,
        'disposition': disposition,
        'total_data': total_data.reverse(),
        'total_duration': total_duration,
        'total_calls': total_calls,
        'total_avg_duration': total_avg_duration,
        'max_duration': max_duration,
        'module': current_view(request),
        'notice_count': notice_count(request),
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }

    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 10
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

        * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm, CheckPhoneNumberForm
        * ``template`` - 'frontend/registration/user_detail_change.html'

    **Logic Description**:

        * User is able to change his/her detail.
    """
    user_detail = User.objects.get(username=request.user)
    try:
        user_detail_extened = UserProfile.objects.get(user=user_detail)
    except UserProfile.DoesNotExist:
        #create UserProfile
        user_detail_extened = UserProfile(user=user_detail)
        user_detail_extened.save()

    user_detail_form = UserChangeDetailForm(request.user,
                                            instance=user_detail)
    user_detail_extened_form = UserChangeDetailExtendForm(request.user,
                                                          instance=user_detail_extened)
    
    user_password_form = PasswordChangeForm(user=request.user)
    check_phone_no_form = CheckPhoneNumberForm()

    try:
        user_ds = UserProfile.objects.get(user=request.user)
        dialer_set = DialerSetting.objects.get(id=user_ds.dialersetting.id)
    except:
        dialer_set = ''

    user_notification = \
    notification.Notice.objects.filter(recipient=request.user)
    # Search on sender name
    q = (Q(sender=request.user))
    if q:
        user_notification = user_notification.filter(q)

    msg_detail = ''
    msg_pass = ''
    msg_number = ''
    msg_note = ''
    error_detail = ''
    error_pass = ''
    error_number = ''
    action = ''

    if 'action' in request.GET:
        action = request.GET['action']
        
    if request.GET.get('msg_note') == 'true':
        msg_note = request.session['msg_note']

    # Mark all notification as read
    if request.GET.get('notification') == 'mark_read_all':
        notification_list = notification.Notice.objects.filter(unseen=1, recipient=request.user)
        notification_list.update(unseen=0)
        msg_note = _('All notifications are marked as read.')

    if request.method == 'POST':
        if request.POST['form-type'] == "change-detail":
            user_detail_form = UserChangeDetailForm(request.user, request.POST,
                                                    instance=user_detail)
            user_detail_extened_form = UserChangeDetailExtendForm(request.user,
                                                                  request.POST,
                                                                  instance=user_detail_extened)
            action = 'tabs-1'
            if user_detail_form.is_valid() and user_detail_extened_form.is_valid():
                user_detail_form.save()
                user_detail_extened_form.save()
                msg_detail = _('Detail has been changed.')
            else:
                error_detail = _('Please correct the errors below.')
        elif request.POST['form-type'] == "check-number": # check phone no
            action = 'tabs-5'
            check_phone_no_form = CheckPhoneNumberForm(data=request.POST)
            if check_phone_no_form.is_valid():
                if not common_contact_authorization(request.user,
                                                    request.POST['phone_number']):
                    error_number = _('This phone number is not authorized.')
                else:
                    msg_number = _('This phone number is authorized.')
            else:
                error_number = _('Please correct the errors below.')
        else: # "change-password"
            user_password_form = PasswordChangeForm(user=request.user,
                                                    data=request.POST)
            action = 'tabs-2'
            if user_password_form.is_valid():
                user_password_form.save()
                msg_pass = _('Your password has been changed.')
            else:
                error_pass = _('Please correct the errors below.')

    template = 'frontend/registration/user_detail_change.html'
    data = {
        'module': current_view(request),
        'user_detail_form': user_detail_form,
        'user_detail_extened_form': user_detail_extened_form,
        'user_password_form': user_password_form,
        'check_phone_no_form': check_phone_no_form,
        'user_notification': user_notification,
        'msg_detail': msg_detail,
        'msg_pass': msg_pass,
        'msg_number': msg_number,
        'msg_note': msg_note,
        'error_detail': error_detail,
        'error_pass': error_pass,
        'error_number': error_number,
        'notice_count': notice_count(request),
        'dialer_set': dialer_set,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
        'action': action,
    }
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 11
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

        * ``form`` - UserChangeDetailForm, PasswordChangeForm, CheckPhoneNumberForm
        * ``template`` - 'frontend/registration/user_detail_change.html'

    **Logic Description**:

        * User is able to change his/her detail.
    """
    user_detail = User.objects.get(username=request.user)
    user_detail_form = UserChangeDetailForm(user=request.user,
                                            instance=user_detail)
    user_password_form = PasswordChangeForm(user=request.user)
    check_phone_no_form = CheckPhoneNumberForm()

    try:
        user_ds = UserProfile.objects.get(user=request.user)
        dialer_set = DialerSetting.objects.get(id=user_ds.dialersetting.id)
    except:
        dialer_set = ''

    user_notification = \
    notification.Notice.objects.filter(recipient=request.user)
    # Search on sender name
    q = (Q(sender=request.user))
    if q:
        user_notification = user_notification.filter(q)

    msg_detail = ''
    msg_pass = ''
    msg_number = ''
    msg_note = ''
    error_detail = ''
    error_pass = ''
    error_number = ''
    selected = 0

    if 'selected' in request.GET:
        selected = request.GET['selected']

    if request.GET.get('msg_note') == 'true':
        msg_note = request.session['msg_note']
        
    if request.method == 'POST':
        if request.POST['form-type'] == "change-detail":
            user_detail_form = UserChangeDetailForm(request.user, request.POST,
                                                    instance=user_detail)
            selected = 0
            if user_detail_form.is_valid():
                user_detail_form.save()
                msg_detail = _('Your detail has been changed successfully.')
            else:
                error_detail = _('Please correct the errors below.')
        elif request.POST['form-type'] == "check-number": # check phone no
            selected = 4
            check_phone_no_form = CheckPhoneNumberForm(data=request.POST)
            if not common_contact_authorization(request.user,
                                                request.POST['phone_number']):
                error_number = _('This phone number is not authorized.')
            else:
                msg_number = _('This phone number is authorized.')
        else: # "change-password"
            user_password_form = PasswordChangeForm(user=request.user,
                                                    data=request.POST)
            selected = 1
            if user_password_form.is_valid():
                user_password_form.save()
                msg_pass = _('Your password has been changed successfully.')
            else:
                error_pass = _('Please correct the errors below.')

    template = 'frontend/registration/user_detail_change.html'
    data = {
        'module': current_view(request),
        'user_detail_form': user_detail_form,
        'user_password_form': user_password_form,
        'check_phone_no_form': check_phone_no_form,
        'user_notification': user_notification,
        'msg_detail': msg_detail,
        'msg_pass': msg_pass,
        'msg_number': msg_number,
        'msg_note': msg_note,
        'selected': selected,
        'error_detail': error_detail,
        'error_pass': error_pass,
        'error_number': error_number,
        'notice_count': notice_count(request),
        'dialer_set': dialer_set,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 12
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

        * ``form`` - UserChangeDetailForm, UserChangeDetailExtendForm, PasswordChangeForm, CheckPhoneNumberForm
        * ``template`` - 'frontend/registration/user_detail_change.html'

    **Logic Description**:

        * User is able to change his/her detail.
    """
    user_detail = User.objects.get(username=request.user)
    try:
        user_detail_extened = UserProfile.objects.get(user=user_detail)
    except UserProfile.DoesNotExist:
        # create UserProfile
        user_detail_extened = UserProfile(user=user_detail)
        user_detail_extened.save()

    user_detail_form = UserChangeDetailForm(request.user, instance=user_detail)
    user_detail_extened_form = UserChangeDetailExtendForm(request.user, instance=user_detail_extened)

    user_password_form = PasswordChangeForm(user=request.user)
    check_phone_no_form = CheckPhoneNumberForm()

    try:
        user_ds = UserProfile.objects.get(user=request.user)
        dialer_set = DialerSetting.objects.get(id=user_ds.dialersetting.id)
    except:
        dialer_set = ""

    user_notification = notification.Notice.objects.filter(recipient=request.user)
    # Search on sender name
    q = Q(sender=request.user)
    if q:
        user_notification = user_notification.filter(q)

    msg_detail = ""
    msg_pass = ""
    msg_number = ""
    msg_note = ""
    error_detail = ""
    error_pass = ""
    error_number = ""
    action = ""

    if "action" in request.GET:
        action = request.GET["action"]

    if request.GET.get("msg_note") == "true":
        msg_note = request.session["msg_note"]

    # Mark all notification as read
    if request.GET.get("notification") == "mark_read_all":
        notification_list = notification.Notice.objects.filter(unseen=1, recipient=request.user)
        notification_list.update(unseen=0)
        msg_note = _("All notifications are marked as read.")

    if request.method == "POST":
        if request.POST["form-type"] == "change-detail":
            user_detail_form = UserChangeDetailForm(request.user, request.POST, instance=user_detail)
            user_detail_extened_form = UserChangeDetailExtendForm(
                request.user, request.POST, instance=user_detail_extened
            )
            action = "tabs-1"
            if user_detail_form.is_valid() and user_detail_extened_form.is_valid():
                user_detail_form.save()
                user_detail_extened_form.save()
                msg_detail = _("Detail has been changed.")
            else:
                error_detail = _("Please correct the errors below.")
        elif request.POST["form-type"] == "check-number":  # check phone no
            action = "tabs-5"
            check_phone_no_form = CheckPhoneNumberForm(data=request.POST)
            if check_phone_no_form.is_valid():
                if not common_contact_authorization(request.user, request.POST["phone_number"]):
                    error_number = _("This phone number is not authorized.")
                else:
                    msg_number = _("This phone number is authorized.")
            else:
                error_number = _("Please correct the errors below.")
        else:  # "change-password"
            user_password_form = PasswordChangeForm(user=request.user, data=request.POST)
            action = "tabs-2"
            if user_password_form.is_valid():
                user_password_form.save()
                msg_pass = _("Your password has been changed.")
            else:
                error_pass = _("Please correct the errors below.")

    template = "frontend/registration/user_detail_change.html"
    data = {
        "module": current_view(request),
        "user_detail_form": user_detail_form,
        "user_detail_extened_form": user_detail_extened_form,
        "user_password_form": user_password_form,
        "check_phone_no_form": check_phone_no_form,
        "user_notification": user_notification,
        "msg_detail": msg_detail,
        "msg_pass": msg_pass,
        "msg_number": msg_number,
        "msg_note": msg_note,
        "error_detail": error_detail,
        "error_pass": error_pass,
        "error_number": error_number,
        "notice_count": notice_count(request),
        "dialer_set": dialer_set,
        "dialer_setting_msg": user_dialer_setting_msg(request.user),
        "action": action,
    }
    return render_to_response(template, data, context_instance=RequestContext(request))
Exemplo n.º 13
0
def survey_report(request):
    """Survey detail report for the logged in user

    **Attributes**:

        * ``template`` - frontend/survey/survey_report.html

    **Logic Description**:

        * List all survey_report which belong to the logged in user.
    """
    tday = datetime.today()
    from_date = tday.strftime("%Y-%m-%d")
    to_date = tday.strftime("%Y-%m-%d")
    form = SurveyDetailReportForm(request.user,
                                  initial={'from_date': from_date,
                                           'to_date': to_date})
    search_tag = 1
    survey_result = ''
    col_name_with_order = []
    survey_cdr_daily_data = {
        'total_data': '',
        'total_duration': '',
        'total_calls': '',
        'total_avg_duration': '',
        'max_duration': '',
    }
    PAGE_SIZE = settings.PAGE_SIZE
    action = 'tabs-1'

    if request.method == 'POST':
        #search_tag = 1
        form = SurveyDetailReportForm(request.user, request.POST)
        if form.is_valid():
            # set session var value
            request.session['session_from_date'] = ''
            request.session['session_to_date'] = ''
            request.session['session_campaign_id'] = ''
            request.session['session_surveycalls'] = ''
            request.session['session_survey_result'] = ''
            request.session['session_survey_cdr_daily_data'] = {}

            if "from_date" in request.POST:
                # From
                from_date = request.POST['from_date']
                start_date = datetime(int(from_date[0:4]),
                                      int(from_date[5:7]),
                                      int(from_date[8:10]),
                                      0, 0, 0, 0)
                request.session['session_from_date'] = from_date

            if "to_date" in request.POST:
                # To
                to_date = request.POST['to_date']
                end_date = datetime(int(to_date[0:4]),
                                    int(to_date[5:7]),
                                    int(to_date[8:10]),
                                    23, 59, 59, 999999)
                request.session['session_to_date'] = to_date

            campaign_id = variable_value(request, 'campaign')
            if campaign_id:
                request.session['session_campaign_id'] = campaign_id
    else:
        rows = []
        campaign_id = ''

    try:
        if request.GET.get('page') or request.GET.get('sort_by'):
            from_date = request.session.get('session_from_date')
            to_date = request.session.get('session_to_date')
            campaign_id = request.session.get('session_campaign_id')
            search_tag = request.session.get('session_search_tag')
        else:
            from_date
    except NameError:
        tday = datetime.today()
        from_date = tday.strftime('%Y-%m-01')
        last_day = ((datetime(tday.year, tday.month, 1, 23, 59, 59, 999999) + \
                    relativedelta(months=1)) - \
                    relativedelta(days=1)).strftime('%d')
        to_date = tday.strftime('%Y-%m-' + last_day)
        search_tag = 0

        # unset session var value
        request.session['session_from_date'] = from_date
        request.session['session_to_date'] = to_date
        request.session['session_campaign_id'] = ''
        request.session['session_surveycalls'] = ''
        request.session['session_survey_result'] = ''
        request.session['session_search_tag'] = search_tag

    start_date = datetime(int(from_date[0:4]),
                          int(from_date[5:7]),
                          int(from_date[8:10]),
                          0, 0, 0, 0)
    end_date = datetime(int(to_date[0:4]),
                        int(to_date[5:7]),
                        int(to_date[8:10]),
                        23, 59, 59, 999999)

    kwargs = {}
    kwargs['user'] = request.user
    kwargs['disposition__exact'] = 'ANSWER'

    survey_result_kwargs = {}
    survey_result_kwargs['callrequest__user'] = request.user

    if start_date and end_date:
        kwargs['starting_date__range'] = (start_date, end_date)
        survey_result_kwargs['created_date__range'] = (start_date, end_date)
    if start_date and end_date == '':
        kwargs['starting_date__gte'] = start_date
        survey_result_kwargs['created_date__gte'] = start_date
    if start_date == '' and end_date:
        kwargs['starting_date__lte'] = end_date
        survey_result_kwargs['created_date__lte'] = end_date

    try:
        campaign_id = int(campaign_id)
        campaign_obj = Campaign.objects.get(id=campaign_id)
        survey_result_kwargs['campaign'] = campaign_obj
        survey_result_kwargs['callrequest__status'] = 4

        # Get survey result report from session
        # while using pagination & sorting
        if request.GET.get('page') or request.GET.get('sort_by'):
            survey_result = request.session['session_survey_result']
        else:
            survey_result = get_survey_result(survey_result_kwargs)
            request.session['session_survey_result'] = survey_result

        kwargs['callrequest__campaign'] = campaign_obj

        # sorting on column
        col_name_with_order = {}
        sort_field = variable_value(request, 'sort_by')
        if not sort_field:
            sort_field = '-starting_date'  # default sort field
        else:
            if "-" in sort_field:
                col_name_with_order['sort_field'] = sort_field[1:]
            else:
                col_name_with_order['sort_field'] = sort_field

        # List of Survey VoIP call report
        from_query =\
            'FROM survey_surveycampaignresult '\
            'WHERE survey_surveycampaignresult.callrequest_id = '\
            'dialer_callrequest.id '
        select_group_query = 'SELECT group_concat(CONCAT_WS("*|*", question, response, record_file) SEPARATOR "-|-") '

        rows = VoIPCall.objects\
                .only('starting_date', 'phone_number', 'duration', 'disposition')\
                .filter(**kwargs)\
                .extra(
                    select={
                        'question_response': select_group_query + from_query
                        },
                ).order_by(sort_field)

        request.session['session_surveycalls'] = rows

        # Get daily report from session while using pagination & sorting
        if request.GET.get('page') or request.GET.get('sort_by'):
            survey_cdr_daily_data = \
                request.session['session_survey_cdr_daily_data']
        else:
            survey_cdr_daily_data = survey_cdr_daily_report(kwargs,
                                                            from_query,
                                                    select_group_query)
            request.session['session_survey_cdr_daily_data'] = \
                survey_cdr_daily_data
    except:
        rows = []
        if request.method == 'POST':
            request.session["err_msg"] = \
                _('No campaign attached with survey.')

    template = 'frontend/survey/survey_report.html'

    data = {
        'rows': rows,
        'PAGE_SIZE': PAGE_SIZE,
        'col_name_with_order': col_name_with_order,
        'total_data': survey_cdr_daily_data['total_data'],
        'total_duration': survey_cdr_daily_data['total_duration'],
        'total_calls': survey_cdr_daily_data['total_calls'],
        'total_avg_duration': survey_cdr_daily_data['total_avg_duration'],
        'max_duration': survey_cdr_daily_data['max_duration'],
        'module': current_view(request),
        'msg': request.session.get('msg'),
        'err_msg': request.session.get('err_msg'),
        'notice_count': notice_count(request),
        'form': form,
        'survey_result': survey_result,
        'action': action,
        'search_tag': search_tag,
        'start_date': start_date,
        'end_date': end_date,
        }
    request.session['msg'] = ''
    request.session['err_msg'] = ''
    return render_to_response(template, data,
        context_instance=RequestContext(request))