Exemplo n.º 1
0
def phonebook_list(request):
    """Phonebook list for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all phonebooks which belong to the logged in user.
    """
    sort_col_field_list = ["id", "name", "updated_date"]
    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"]

    phonebook_list = (
        Phonebook.objects.annotate(contact_count=Count("contact")).filter(user=request.user).order_by(sort_order)
    )

    template = "frontend/phonebook/list.html"
    data = {
        "msg": request.session.get("msg"),
        "phonebook_list": phonebook_list,
        "total_phonebook": phonebook_list.count(),
        "PAGE_SIZE": PAGE_SIZE,
        "PHONEBOOK_COLUMN_NAME": PHONEBOOK_COLUMN_NAME,
        "col_name_with_order": pagination_data["col_name_with_order"],
        "dialer_setting_msg": user_dialer_setting_msg(request.user),
    }
    request.session["msg"] = ""
    request.session["error_msg"] = ""
    return render_to_response(template, data, context_instance=RequestContext(request))
Exemplo n.º 2
0
def dnc_list(request):
    """DNC list for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all dnc which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'name', 'updated_date']
    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']

    dnc_list = DNC.objects.filter(user=request.user).order_by(sort_order)

    template = 'frontend/dnc_list/list.html'
    data = {
        'msg': request.session.get('msg'),
        'dnc_list': dnc_list,
        'total_dnc': dnc_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'DNC_COLUMN_NAME': DNC_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 3
0
def tier_list(request):
    """Tier list for the logged in Manager

    **Attributes**:

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

    **Logic Description**:

        * List all tier which belong to the logged in manager.
    """
    sort_col_field_list = ['agent', 'queue', 'level', 'position', 'updated_date']
    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']

    tier_list = Tier.objects\
        .filter(manager=request.user).order_by(sort_order)

    template = 'frontend/tier/list.html'
    data = {
        'msg': request.session.get('msg'),
        'tier_list': tier_list,
        'total_tier': tier_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'TIER_COLUMN_NAME': TIER_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 4
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
    """
    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']

    campaign_list = Campaign.objects.filter(
        user=request.user).order_by(sort_order)

    template = 'frontend/campaign/list.html'
    data = {
        'module': current_view(request),
        'campaign_list': campaign_list,
        'total_campaign': campaign_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'CAMPAIGN_COLUMN_NAME': CAMPAIGN_COLUMN_NAME,
        '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))
Exemplo n.º 5
0
def get_notification_list_for_view(request):
    sort_col_field_list = ['message', 'notice_type', 'sender', 'added']
    default_sort_field = 'message'
    pagination_data =\
        get_pagination_vars(request, sort_col_field_list, default_sort_field)
    sort_order = pagination_data['sort_order']

    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)

    user_notification = user_notification.order_by(sort_order)
    data = {
        'pagination_data': pagination_data,
        'user_notification': user_notification,
    }
    return data
Exemplo n.º 6
0
def get_notification_list_for_view(request):
    sort_col_field_list = ['message', 'notice_type', 'sender', 'added']
    default_sort_field = 'message'
    pagination_data =\
        get_pagination_vars(request, sort_col_field_list, default_sort_field)
    sort_order = pagination_data['sort_order']

    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)

    user_notification = user_notification.order_by(sort_order)
    data = {
        'pagination_data': pagination_data,
        'user_notification': user_notification,
    }
    return data
Exemplo n.º 7
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
    """
    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']

    campaign_list = Campaign.objects.filter(user=request.user).order_by(sort_order)

    template = 'frontend/campaign/list.html'
    data = {
        'module': current_view(request),
        'campaign_list': campaign_list,
        'total_campaign': campaign_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'CAMPAIGN_COLUMN_NAME': CAMPAIGN_COLUMN_NAME,
        '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))
Exemplo n.º 8
0
def alarm_list(request):
    """Alarm list for the logged in user

    **Attributes**:

        * ``template`` - frontend/cdr_alert/alert_list.html

    **Logic Description**:

        * List all alarms which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'name', 'period', 'type', 'alert_condition',
                           'alert_value', 'status', 'updated_date']
    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']

    alarm_list = Alarm.objects\
        .filter(user=request.user).order_by(sort_order)

    template_name = 'frontend/cdr_alert/alarm/list.html'

    PAGE_SIZE = settings.PAGE_SIZE
    template_data = {
        'module': current_view(request),
        'msg': request.session.get('msg'),
        'rows': alarm_list,
        'total_count': alarm_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'ALARM_COLUMN_NAME': ALARM_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'notice_count': notice_count(request),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template_name, template_data,
        context_instance=RequestContext(request))
Exemplo n.º 9
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.
    """
    sort_col_field_list = ['id', 'name', 'updated_date']
    default_sort_field = 'id'
    pagination_data =\
        get_pagination_vars(request, sort_col_field_list, default_sort_field)

    #PAGE_NUMBER = pagination_data['PAGE_NUMBER']
    PAGE_SIZE = pagination_data['PAGE_SIZE']
    sort_order = pagination_data['sort_order']

    survey_list = Survey_template.objects\
        .values('id', 'name', 'description', 'updated_date')\
        .filter(user=request.user).order_by(sort_order)

    template = 'frontend/survey/survey_list.html'
    data = {
        'module': current_view(request),
        'survey_list': survey_list,
        'total_survey': survey_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'SURVEY_COLUMN_NAME': SURVEY_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'msg': request.session.get('msg'),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Exemplo n.º 10
0
def alarm_list(request):
    """Alarm list for the logged in user

    **Attributes**:

        * ``template`` - frontend/appointment/alarm/list.html

    **Logic Description**:

        * List all alarms which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'alarm_phonenumber', 'alarm_email', 'daily_start',
                           'daily_stop', 'method', 'survey', 'event',
                           'date_start_notice', 'status']
    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']

    calendar_user_id_list = get_calendar_user_id_list(request.user)
    alarm_list = Alarm.objects.filter(
        event__calendar__user_id__in=calendar_user_id_list).order_by(sort_order)

    template = 'frontend/appointment/alarm/list.html'
    data = {
        'msg': request.session.get('msg'),
        'alarm_list': alarm_list,
        'total_alarm': alarm_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'ALARM_COLUMN_NAME': ALARM_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 11
0
def phonebook_list(request):
    """Phonebook list for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all phonebooks which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'name', 'updated_date']
    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']

    phonebook_list = Phonebook.objects\
        .annotate(contact_count=Count('contact'))\
        .filter(user=request.user).order_by(sort_order)

    template = 'frontend/phonebook/list.html'
    data = {
        'module': current_view(request),
        'msg': request.session.get('msg'),
        'phonebook_list': phonebook_list,
        'total_phonebook': phonebook_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'PHONEBOOK_COLUMN_NAME': PHONEBOOK_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Exemplo n.º 12
0
def audio_list(request):
    """AudioFile list for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all audios which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'name', 'updated_date']
    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']
    audio_list = AudioFile.objects.filter(
        user=request.user).order_by(sort_order)
    domain = Site.objects.get_current().domain

    template = 'frontend/audio/audio_list.html'
    data = {
        'module': current_view(request),
        'audio_list': audio_list,
        'total_audio': audio_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'AUDIO_COLUMN_NAME': AUDIO_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'domain': domain,
        'msg': request.session.get('msg'),
        'AUDIO_DEBUG': settings.AUDIO_DEBUG,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Exemplo n.º 13
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.
    """
    sort_col_field_list = ['id', 'name', 'updated_date']
    default_sort_field = 'id'
    pagination_data =\
        get_pagination_vars(request, sort_col_field_list, default_sort_field)

    #PAGE_NUMBER = pagination_data['PAGE_NUMBER']
    PAGE_SIZE = pagination_data['PAGE_SIZE']
    sort_order = pagination_data['sort_order']

    survey_list = Survey_template.objects\
        .values('id', 'name', 'description', 'updated_date')\
        .filter(user=request.user).order_by(sort_order)

    template = 'frontend/survey/survey_list.html'
    data = {
        'module': current_view(request),
        'survey_list': survey_list,
        'total_survey': survey_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'SURVEY_COLUMN_NAME': SURVEY_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'msg': request.session.get('msg'),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 14
0
def calendar_list(request):
    """Calendar list for the logged in user

    **Attributes**:

        * ``template`` - frontend/appointment/calendar/list.html

    **Logic Description**:

        * List all calendars which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'name', 'user', 'max_concurrent',
                           'created_date']
    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']

    calendar_user_id_list = get_calendar_user_id_list(request.user)
    calendar_list = Calendar.objects.filter(
        user_id__in=calendar_user_id_list).order_by(sort_order)

    template = 'frontend/appointment/calendar/list.html'
    data = {
        'msg': request.session.get('msg'),
        'calendar_list': calendar_list,
        'total_calendar': calendar_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'CALENDAR_COLUMN_NAME': CALENDAR_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 15
0
def phonebook_list(request):
    """Phonebook list for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all phonebooks which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'name', 'updated_date']
    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']

    phonebook_list = Phonebook.objects\
        .annotate(contact_count=Count('contact'))\
        .filter(user=request.user).order_by(sort_order)

    template = 'frontend/phonebook/list.html'
    data = {
        'module': current_view(request),
        'msg': request.session.get('msg'),
        'phonebook_list': phonebook_list,
        'total_phonebook': phonebook_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'PHONEBOOK_COLUMN_NAME': PHONEBOOK_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 16
0
def audio_list(request):
    """AudioFile list for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all audios which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'name', 'updated_date']
    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']
    audio_list = AudioFile.objects.filter(user=request.user).order_by(sort_order)
    domain = Site.objects.get_current().domain

    template = 'frontend/audio/audio_list.html'
    data = {
        'module': current_view(request),
        'audio_list': audio_list,
        'total_audio': audio_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'AUDIO_COLUMN_NAME': AUDIO_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'domain': domain,
        'msg': request.session.get('msg'),
        'AUDIO_DEBUG': settings.AUDIO_DEBUG,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 17
0
def sealed_survey_list(request):
    """Survey list for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all sealed surveys which belong to the logged in user.
    """
    sort_col_field_list = ["id", "name", "updated_date", "campaign"]
    default_sort_field = "id"
    pagination_data = get_pagination_vars(request, sort_col_field_list, default_sort_field)

    # PAGE_NUMBER = pagination_data['PAGE_NUMBER']
    PAGE_SIZE = pagination_data["PAGE_SIZE"]
    sort_order = pagination_data["sort_order"]

    survey_list = (
        Survey.objects.values("id", "name", "description", "updated_date", "campaign__name")
        .filter(user=request.user)
        .order_by(sort_order)
    )

    template = "frontend/survey/sealed_survey_list.html"
    data = {
        "survey_list": survey_list,
        "total_survey": survey_list.count(),
        "PAGE_SIZE": PAGE_SIZE,
        "SEALED_SURVEY_COLUMN_NAME": SEALED_SURVEY_COLUMN_NAME,
        "col_name_with_order": pagination_data["col_name_with_order"],
        "msg": request.session.get("msg"),
    }
    request.session["msg"] = ""
    request.session["error_msg"] = ""
    return render_to_response(template, data, context_instance=RequestContext(request))
Exemplo n.º 18
0
def queue_list(request):
    """Queue list for the logged in Manager

    **Attributes**:

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

    **Logic Description**:

        * List all queue which belong to the logged in manager.
    """
    sort_col_field_list = ['name', 'strategy', 'time_base_score', 'updated_date']
    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']

    queue_list = Queue.objects\
        .filter(manager=request.user).order_by(sort_order)

    template = 'frontend/queue/list.html'
    data = {
        'msg': request.session.get('msg'),
        'error_msg': request.session.get('error_msg'),
        'queue_list': queue_list,
        'total_queue': queue_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'QUEUE_COLUMN_NAME': QUEUE_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 19
0
def calendar_setting_list(request):
    """Calendar setting list for the logged in user

    **Attributes**:

        * ``template`` - frontend/appointment/calendar_setting/list.html

    **Logic Description**:

        * List all calendar settings which belong to the logged in user.
    """
    sort_col_field_list = ['id', 'label', 'callerid', 'caller_name',
                           'call_timeout', 'survey', 'aleg_gateway',
                           'sms_gateway']
    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']

    calendar_setting_list = CalendarSetting.objects.filter(user=request.user).order_by(sort_order)

    template = 'frontend/appointment/calendar_setting/list.html'
    data = {
        'msg': request.session.get('msg'),
        'calendar_setting_list': calendar_setting_list,
        'total_calendar_setting': calendar_setting_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'CALENDAR_SETTING_COLUMN_NAME': CALENDAR_SETTING_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 20
0
def agent_list(request):
    """Agent list for the logged in Manager

    **Attributes**:

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

    **Logic Description**:

        * List all agents which belong to the logged in manager.
    """
    sort_col_field_list = ['user', 'status', 'contact', 'updated_date']
    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']

    agent_list = AgentProfile.objects \
        .filter(manager=request.user).order_by(sort_order)

    template = 'frontend/agent/list.html'
    data = {
        'msg': request.session.get('msg'),
        'agent_list': agent_list,
        'total_agent': agent_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'AGENT_COLUMN_NAME': AGENT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 21
0
def contact_list(request):
    """Contact list for the logged in user

    **Attributes**:

        * ``template`` - frontend/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',
        'updated_date'
    ]
    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']

    form = ContactSearchForm(request.user)
    phonebook_id_list = Phonebook.objects.values_list('id', flat=True)\
        .filter(user=request.user)
    search_tag = 1
    contact_no = ''
    contact_name = ''
    phonebook = ''
    contact_status = STATUS_CHOICE.ALL
    if request.method == 'POST':
        form = ContactSearchForm(request.user, request.POST)
        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 = 0
    try:
        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
                                     })
        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 = [
            '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 = type_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', 'status', 'updated_date')\
            .filter(phonebook__in=phonebook_id_list)

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

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

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

    template = 'frontend/contact/list.html'
    data = {
        'module': current_view(request),
        'contact_list': contact_list,
        'all_contact_list': all_contact_list,
        'total_contacts': contact_count,
        'PAGE_SIZE': PAGE_SIZE,
        'CONTACT_COLUMN_NAME': CONTACT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'msg': request.session.get('msg'),
        'error_msg': request.session.get('error_msg'),
        'form': form,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
        'search_tag': search_tag,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Exemplo n.º 22
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 = ''

    survey_cdr_daily_data = {
        'total_data': '',
        'total_duration': '',
        'total_calls': '',
        'total_avg_duration': '',
        'max_duration': '',
    }

    sort_col_field_list = [
        'starting_date', 'phone_number', 'duration', 'disposition', 'id'
    ]
    default_sort_field = 'starting_date'
    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']

    campaign_obj = ''
    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_kwargs'] = ''
            request.session['session_survey_cdr_daily_data'] = {}

            if "from_date" in request.POST:
                # From
                from_date = request.POST['from_date']
                request.session['session_from_date'] = from_date

            if "to_date" in request.POST:
                # To
                to_date = request.POST['to_date']
                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_kwargs'] = ''
        request.session['session_search_tag'] = search_tag

    start_date = ceil_strdate(from_date, 'start')
    end_date = ceil_strdate(to_date, 'end')

    kwargs = {}
    if not request.user.is_superuser:
        kwargs['user'] = request.user
    kwargs['disposition__exact'] = VOIPCALL_DISPOSITION.ANSWER

    survey_result_kwargs = {}

    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

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

        survey_result = get_survey_result(survey_result_kwargs)
        kwargs['callrequest__campaign'] = campaign_obj

        # List of Survey VoIP call report
        voipcall_list = VoIPCall.objects.filter(**kwargs)
        request.session['session_surveycalls_kwargs'] = kwargs
        all_call_list = voipcall_list.values_list('id', flat=True)

        # 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']
            action = 'tabs-2'
        else:
            survey_cdr_daily_data = survey_cdr_daily_report(voipcall_list)
            request.session[
                'session_survey_cdr_daily_data'] = survey_cdr_daily_data

        rows = voipcall_list.order_by(sort_order)[start_page:end_page]
    except:
        rows = []
        if request.method == 'POST':
            request.session["err_msg"] = _('no campaign attached with survey.')

    template = 'frontend/survey/survey_report.html'

    data = {
        'rows': rows,
        'all_call_list': all_call_list,
        'call_count': all_call_list.count() if all_call_list else 0,
        'PAGE_SIZE': PAGE_SIZE,
        'SURVEY_CALL_RESULT_NAME': SURVEY_CALL_RESULT_NAME,
        'col_name_with_order': pagination_data['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'),
        'form': form,
        'survey_result': survey_result,
        'action': action,
        'search_tag': search_tag,
        'start_date': start_date,
        'end_date': end_date,
        'campaign_obj': campaign_obj,
    }
    request.session['msg'] = ''
    request.session['err_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Exemplo n.º 23
0
def dnc_contact_list(request):
    """DNC Contact list for the logged in user

    **Attributes**:

        * ``template`` - frontend/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']
    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']

    form = DNCContactSearchForm(request.user)
    dnc_id_list = DNC.objects.values_list('id', flat=True)\
        .filter(user=request.user)
    search_tag = 1
    phone_number = ''
    dnc = ''

    if request.method == 'POST':
        form = DNCContactSearchForm(request.user, request.POST)
        if form.is_valid():
            request.session['session_phone_number'] = ''
            request.session['session_dnc'] = ''

            if request.POST.get('phone_number'):
                phone_number = request.POST.get('phone_number')
                request.session['session_phone_number'] = phone_number

            if request.POST.get('dnc'):
                dnc = request.POST.get('dnc')
                request.session['session_dnc'] = dnc

    post_var_with_page = 0
    try:
        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
                                        })
        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
        request.session['session_phone_number'] = ''
        request.session['session_dnc'] = ''

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

    phone_number_type = '1'
    phone_number = type_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:
        phone_number_list = DNCContact.objects.values('id', 'dnc__name',
            'phone_number', 'updated_date')\
            .filter(dnc__in=dnc_id_list)

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

        all_phone_number_list = phone_number_list.order_by(sort_order)
        phone_number_list = all_phone_number_list[start_page:end_page]
        phone_number_count = all_phone_number_list.count()

    template = 'frontend/dnc_contact/list.html'
    data = {
        'module': current_view(request),
        'phone_number_list': phone_number_list,
        'all_phone_number_list': all_phone_number_list,
        'total_phone_numbers': phone_number_count,
        'PAGE_SIZE': PAGE_SIZE,
        'DNC_CONTACT_COLUMN_NAME': DNC_CONTACT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'msg': request.session.get('msg'),
        'error_msg': request.session.get('error_msg'),
        'form': form,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
        'search_tag': search_tag,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Exemplo n.º 24
0
def dnc_contact_list(request):
    """DNC Contact list for the logged in user

    **Attributes**:

        * ``template`` - frontend/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']
    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']

    form = DNCContactSearchForm(request.user)
    dnc_id_list = DNC.objects.values_list('id', flat=True)\
        .filter(user=request.user)
    search_tag = 1
    phone_number = ''
    dnc = ''

    if request.method == 'POST':
        form = DNCContactSearchForm(request.user, request.POST)
        if form.is_valid():
            request.session['session_phone_number'] = ''
            request.session['session_dnc'] = ''

            if request.POST.get('phone_number'):
                phone_number = request.POST.get('phone_number')
                request.session['session_phone_number'] = phone_number

            if request.POST.get('dnc'):
                dnc = request.POST.get('dnc')
                request.session['session_dnc'] = dnc

    post_var_with_page = 0
    try:
        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})
        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
        request.session['session_phone_number'] = ''
        request.session['session_dnc'] = ''

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

    phone_number_type = '1'
    phone_number = type_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:
        phone_number_list = DNCContact.objects.values('id', 'dnc__name',
            'phone_number', 'updated_date')\
            .filter(dnc__in=dnc_id_list)

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

        all_phone_number_list = phone_number_list.order_by(sort_order)
        phone_number_list = all_phone_number_list[start_page:end_page]
        phone_number_count = all_phone_number_list.count()

    template = 'frontend/dnc_contact/list.html'
    data = {
        'module': current_view(request),
        'phone_number_list': phone_number_list,
        'all_phone_number_list': all_phone_number_list,
        'total_phone_numbers': phone_number_count,
        'PAGE_SIZE': PAGE_SIZE,
        'DNC_CONTACT_COLUMN_NAME': DNC_CONTACT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'msg': request.session.get('msg'),
        'error_msg': request.session.get('error_msg'),
        'form': form,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
        'search_tag': search_tag,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 25
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 = ""

    survey_cdr_daily_data = {
        "total_data": "",
        "total_duration": "",
        "total_calls": "",
        "total_avg_duration": "",
        "max_duration": "",
    }

    sort_col_field_list = ["starting_date", "phone_number", "duration", "disposition", "id"]
    default_sort_field = "starting_date"
    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"]

    survey_id = ""
    action = "tabs-1"
    campaign_obj = ""
    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_survey_id"] = ""
            request.session["session_surveycalls_kwargs"] = ""
            request.session["session_survey_cdr_daily_data"] = {}

            if "from_date" in request.POST:
                # From
                from_date = request.POST["from_date"]
                request.session["session_from_date"] = from_date

            if "to_date" in request.POST:
                # To
                to_date = request.POST["to_date"]
                request.session["session_to_date"] = to_date

            survey_id = variable_value(request, "survey_id")
            if survey_id:
                request.session["session_survey_id"] = survey_id
    else:
        rows = []
        survey_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")
            survey_id = request.session.get("session_survey_id")
            search_tag = request.session.get("session_search_tag")
        else:
            from_date
    except NameError:
        tday = datetime.utcnow().replace(tzinfo=utc)
        from_date = tday.strftime("%Y-%m-01")
        last_day = (
            (datetime(tday.year, tday.month, 1, 23, 59, 59, 999999).replace(tzinfo=utc) + 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_survey_id"] = ""
        request.session["session_surveycalls_kwargs"] = ""
        request.session["session_search_tag"] = search_tag

    start_date = ceil_strdate(from_date, "start")
    end_date = ceil_strdate(to_date, "end")

    kwargs = {}
    if not request.user.is_superuser:
        kwargs["user"] = request.user
    kwargs["disposition__exact"] = VOIPCALL_DISPOSITION.ANSWER

    survey_result_kwargs = {}

    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

    all_call_list = []
    try:
        survey_result_kwargs["survey_id"] = survey_id
        survey_result = get_survey_result(survey_result_kwargs)

        campaign_obj = Survey.objects.get(id=int(survey_id)).campaign
        kwargs["callrequest__campaign"] = campaign_obj

        # List of Survey VoIP call report
        voipcall_list = VoIPCall.objects.filter(**kwargs)
        request.session["session_surveycalls_kwargs"] = kwargs
        all_call_list = voipcall_list.values_list("id", flat=True)

        # 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"]
            action = "tabs-2"
        else:
            survey_cdr_daily_data = survey_cdr_daily_report(voipcall_list)
            request.session["session_survey_cdr_daily_data"] = survey_cdr_daily_data

        rows = voipcall_list.order_by(sort_order)[start_page:end_page]
    except:
        rows = []
        if request.method == "POST":
            request.session["err_msg"] = _("no campaign attached with survey.")

    template = "frontend/survey/survey_report.html"

    data = {
        "rows": rows,
        "all_call_list": all_call_list,
        "call_count": all_call_list.count() if all_call_list else 0,
        "PAGE_SIZE": PAGE_SIZE,
        "SURVEY_CALL_RESULT_NAME": SURVEY_CALL_RESULT_NAME,
        "col_name_with_order": pagination_data["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"],
        "msg": request.session.get("msg"),
        "err_msg": request.session.get("err_msg"),
        "form": form,
        "survey_result": survey_result,
        "action": action,
        "search_tag": search_tag,
        "start_date": start_date,
        "end_date": end_date,
        "campaign_obj": campaign_obj,
    }
    request.session["msg"] = ""
    request.session["err_msg"] = ""
    return render_to_response(template, data, context_instance=RequestContext(request))
Exemplo n.º 26
0
def sms_campaign_list(request):
    """List all sms campaigns for the logged in user

    **Attributes**:

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

    **Logic Description**:

        * List all sms campaigns belonging to the logged in user
    """
    form = SMSCampaignSearchForm(request.user)
    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 = SMSCampaignSearchForm(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 = SMSCampaignSearchForm(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

    smscampaign_list = SMSCampaign.objects.filter(user=request.user).order_by(sort_order)
    smscampaign_count = smscampaign_list.count()
    if kwargs:
        all_smscampaign_list = smscampaign_list.filter(**kwargs).order_by(sort_order)
        smscampaign_list = all_smscampaign_list[start_page:end_page]
        smscampaign_count = all_smscampaign_list.count()

    template = 'frontend/sms_campaign/list.html'
    data = {
        'form': form,
        'smscampaign_list': smscampaign_list,
        'search_tag': search_tag,
        'total_campaign': smscampaign_count,
        'PAGE_SIZE': PAGE_SIZE,
        'SMS_CAMPAIGN_COLUMN_NAME': SMS_CAMPAIGN_COLUMN_NAME,
        '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))
Exemplo n.º 27
0
def event_list(request):
    """Event list for the logged in user

    **Attributes**:

        * ``template`` - frontend/appointment/event/list.html

    **Logic Description**:

        * List all events which belong to the logged in user.
    """
    today = datetime.utcnow().replace(tzinfo=utc)
    form = EventSearchForm(request.user,
                           initial={'start': today.strftime('%Y-%m-%d %H:%M:%S')})
    sort_col_field_list = ['id', 'start', 'end', 'title',
                           'calendar', 'status', 'created_on']
    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']

    #search_tag = 1
    start_date = ''
    calendar_id = ''
    calendar_user_id = ''

    if request.method == 'POST':
        form = EventSearchForm(request.user, request.POST)
        if form.is_valid():
            field_list = ['start_date', 'calendar_id', 'calendar_user_id']
            unset_session_var(request, field_list)

            if request.POST.get('start_date'):
                # start date
                start_date = ceil_strdate(request.POST['start_date'], 'start')
                request.session['session_start_date'] = start_date

            calendar_id = getvar(request, 'calendar_id', setsession=True)
            calendar_user_id = getvar(request, 'calendar_user_id', setsession=True)

    post_var_with_page = 0
    try:
        if request.GET.get('page') or request.GET.get('sort_by'):
            post_var_with_page = 1
            start_date = request.session.get('session_start_date')
            calendar_id = request.session.get('session_calendar_id')
            calendar_user_id = request.session.get('session_calendar_user_id')
            form = EventSearchForm(request.user, initial={'start_date': start_date,
                                                          'calendar_id': calendar_id,
                                                          'calendar_user_id': calendar_user_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 = ['start_date', 'calendar_id', 'calendar_user_id']
        unset_session_var(request, field_list)

    kwargs = {}
    if start_date:
        kwargs['start__gte'] = start_date

    if calendar_id and int(calendar_id) != 0:
        kwargs['calendar_id'] = calendar_id

    if calendar_user_id and int(calendar_user_id) != 0:
        kwargs['creator_id'] = calendar_user_id

    calendar_user_id_list = get_calendar_user_id_list(request.user)
    event_list = Event.objects.filter(
        calendar__user_id__in=calendar_user_id_list).order_by(sort_order)
    if kwargs:
        event_list = event_list.filter(**kwargs)
    event_list = event_list[start_page:end_page]

    template = 'frontend/appointment/event/list.html'
    data = {
        'form': form,
        'msg': request.session.get('msg'),
        'event_list': event_list,
        'total_event': event_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'EVENT_COLUMN_NAME': EVENT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 28
0
def sms_report(request):
    """SMS Report

    **Attributes**:

        * ``form`` - SMSSearchForm
        * ``template`` - frontend/sms_campaign/sms_report.html

    **Logic Description**:

        * Get SMS list according to search parameters for logged-in user

    **Important variable**:

        * ``request.session['sms_record_qs']`` - stores sms query set
    """
    sort_col_field_list = ['send_date', 'recipient_number', 'uuid',
                           'status', 'status_message', 'gateway']
    default_sort_field = 'send_date'

    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']

    from_date = ''
    to_date = ''
    status = 'all'
    smscampaign = ''

    form = SMSSearchForm(request.user)
    search_tag = 1
    action = 'tabs-1'
    kwargs = {}

    if request.method == 'POST':
        form = SMSSearchForm(request.user, request.POST)
        if form.is_valid():
            request.session['session_start_date'] = ''
            request.session['session_end_date'] = ''
            request.session['session_status'] = ''
            request.session['session_smscampaign'] = ''

            if request.POST.get('from_date'):
                # From
                from_date = request.POST['from_date']
                start_date = ceil_strdate(from_date, 'start')
                request.session['session_start_date'] = start_date

            if request.POST.get('to_date'):
                # To
                to_date = request.POST['to_date']
                end_date = ceil_strdate(to_date, 'end')
                request.session['session_end_date'] = end_date

            status = request.POST.get('status')
            if status != 'all':
                request.session['session_status'] = status

            smscampaign = request.POST.get('smscampaign')
            if smscampaign != '0':
                request.session['session_smscampaign'] = smscampaign

    post_var_with_page = 0
    try:
        if request.GET.get('page') or request.GET.get('sort_by'):
            post_var_with_page = 1
            start_date = request.session.get('session_start_date')
            end_date = request.session.get('session_end_date')
            status = request.session.get('session_status')
            smscampaign = request.session.get('session_smscampaign')

            form = SMSSearchForm(request.user,
                                 initial={'from_date': start_date.strftime('%Y-%m-%d'),
                                          'to_date': end_date.strftime('%Y-%m-%d'),
                                          'status': status,
                                          'smscampaign': smscampaign})
        else:
            post_var_with_page = 1
            if request.method == 'GET':
                post_var_with_page = 0
    except:
        pass

    if post_var_with_page == 0:
        # default
        tday = datetime.utcnow().replace(tzinfo=utc)
        from_date = tday.strftime('%Y-%m-%d')
        to_date = tday.strftime('%Y-%m-%d')
        start_date = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0).replace(tzinfo=utc)
        end_date = datetime(tday.year, tday.month, tday.day, 23, 59, 59, 999999).replace(tzinfo=utc)
        status = 'all'
        smscampaign = ''
        form = SMSSearchForm(
            request.user, initial={'from_date': from_date, 'to_date': to_date,
                                   'status': status, 'smscampaign': smscampaign})
        # unset session var
        request.session['session_start_date'] = start_date
        request.session['session_end_date'] = end_date
        request.session['session_status'] = status
        request.session['session_smscampaign'] = smscampaign

    kwargs['sender'] = request.user

    if start_date and end_date:
        kwargs['send_date__range'] = (start_date, end_date)
    if start_date and end_date == '':
        kwargs['send_date__gte'] = start_date
    if start_date == '' and end_date:
        kwargs['send_date__lte'] = end_date

    if status and status != 'all':
        kwargs['status__exact'] = status

    if smscampaign and smscampaign != '0':
        kwargs['sms_campaign_id'] = smscampaign

    smslist = SMSMessage.objects.filter(**kwargs)
    all_sms_list = smslist.values_list('id', flat=True)
    sms_list = smslist.order_by(sort_order)[start_page:end_page]

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

    select_data = {"send_date": "SUBSTR(CAST(send_date as CHAR(30)),1,10)"}

    # Get Total Rrecords from SMSMessage Report table for Daily SMS Report
    total_data = all_sms_list.extra(select=select_data).values('send_date')\
        .annotate(Count('send_date')).order_by('-send_date')

    # Following code will count total sms
    if total_data.count() != 0:
        total_sms = sum([x['send_date__count'] for x in total_data])
    else:
        total_sms = 0

    template = 'frontend/sms_campaign/sms_report.html'
    data = {
        'form': form,
        'from_date': from_date,
        'all_sms_list': all_sms_list,
        'sms_list': sms_list,
        'sms_count': all_sms_list.count() if all_sms_list else 0,
        'SMS_REPORT_COLUMN_NAME': SMS_REPORT_COLUMN_NAME,
        'PAGE_SIZE': PAGE_SIZE,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'start_date': start_date,
        'end_date': end_date,
        'to_date': to_date,
        'search_tag': search_tag,
        'action': action,
        'status': status,
        'total_data': total_data.reverse(),
        'total_sms': total_sms,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
    }

    return render_to_response(
        template, data, context_instance=RequestContext(request))
Exemplo n.º 29
0
def contact_list(request):
    """Contact list for the logged in user

    **Attributes**:

        * ``template`` - frontend/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', 'updated_date']
    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']

    form = ContactSearchForm(request.user)
    phonebook_id_list = Phonebook.objects.values_list('id', flat=True)\
        .filter(user=request.user)
    search_tag = 1
    contact_no = ''
    contact_name = ''
    phonebook = ''
    contact_status = STATUS_CHOICE.ALL
    if request.method == 'POST':
        form = ContactSearchForm(request.user, request.POST)
        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 = 0
    try:
        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})
        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 = ['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 = type_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', 'status', 'updated_date')\
            .filter(phonebook__in=phonebook_id_list)

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

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

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

    template = 'frontend/contact/list.html'
    data = {
        'module': current_view(request),
        'contact_list': contact_list,
        'all_contact_list': all_contact_list,
        'total_contacts': contact_count,
        'PAGE_SIZE': PAGE_SIZE,
        'CONTACT_COLUMN_NAME': CONTACT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'msg': request.session.get('msg'),
        'error_msg': request.session.get('error_msg'),
        'form': form,
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
        'search_tag': search_tag,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 30
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))
Exemplo n.º 31
0
def subscriber_list(request):
    """Subscriber list for the logged in user

    **Attributes**:

        * ``template`` - frontend/subscriber/list.html
        * ``form`` - SubscriberSearchForm

    **Logic Description**:

        * List all subscribers belonging to the logged in user & their campaign
    """
    sort_col_field_list = [
        "contact",
        "updated_date",
        "count_attempt",
        "completion_count_attempt",
        "status",
        "disposition",
        "collected_data",
        "agent",
    ]
    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"]

    form = SubscriberSearchForm(request.user)

    search_tag = 1
    campaign_id = ""
    agent_id = ""
    status = "all"

    if request.method == "POST":
        form = SubscriberSearchForm(request.user, request.POST)

        if form.is_valid():
            field_list = ["start_date", "end_date", "status", "campaign_id", "agent_id"]
            unset_session_var(request, field_list)
            campaign_id = getvar(request, "campaign_id", setsession=True)
            agent_id = getvar(request, "agent_id", setsession=True)

            if request.POST.get("from_date"):
                # From
                from_date = request.POST["from_date"]
                start_date = ceil_strdate(from_date, "start")
                request.session["session_start_date"] = start_date

            if request.POST.get("to_date"):
                # To
                to_date = request.POST["to_date"]
                end_date = ceil_strdate(to_date, "end")
                request.session["session_end_date"] = end_date

            status = request.POST.get("status")
            if status != "all":
                request.session["session_status"] = status

    post_var_with_page = 0
    try:
        if request.GET.get("page") or request.GET.get("sort_by"):
            post_var_with_page = 1
            start_date = request.session.get("session_start_date")
            end_date = request.session.get("session_end_date")
            campaign_id = request.session.get("session_campaign_id")
            agent_id = request.session.get("session_agent_id")
            status = request.session.get("session_status")
            form = SubscriberSearchForm(
                request.user,
                initial={
                    "from_date": start_date.strftime("%Y-%m-%d"),
                    "to_date": end_date.strftime("%Y-%m-%d"),
                    "campaign_id": campaign_id,
                    "agent_id": agent_id,
                    "status": status,
                },
            )
        else:
            post_var_with_page = 1
            if request.method == "GET":
                post_var_with_page = 0
    except:
        pass

    if post_var_with_page == 0:
        # default
        tday = datetime.utcnow().replace(tzinfo=utc)
        from_date = tday.strftime("%Y-%m-%d")
        to_date = tday.strftime("%Y-%m-%d")
        start_date = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0).replace(tzinfo=utc)
        end_date = datetime(tday.year, tday.month, tday.day, 23, 59, 59, 999999).replace(tzinfo=utc)

        form = SubscriberSearchForm(request.user, initial={"from_date": from_date, "to_date": to_date})
        # unset session var
        request.session["session_start_date"] = start_date
        request.session["session_end_date"] = end_date
        request.session["session_status"] = ""
        request.session["session_campaign_id"] = ""
        request.session["session_agent_id"] = ""

    kwargs = {}
    # updated_date might be replaced with last_attempt
    if start_date and end_date:
        kwargs["updated_date__range"] = (start_date, end_date)
    if start_date and end_date == "":
        kwargs["updated_date__gte"] = start_date
    if start_date == "" and end_date:
        kwargs["updated_date__lte"] = end_date

    if campaign_id and campaign_id != "0":
        kwargs["campaign_id"] = campaign_id

    if agent_id and agent_id != "0":
        kwargs["agent_id"] = agent_id

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

    subscriber_list = []
    all_subscriber_list = []
    subscriber_count = 0

    if request.user.is_superuser:
        subscriber_list = Subscriber.objects.all()
    else:
        subscriber_list = Subscriber.objects.filter(campaign__user=request.user)

    if kwargs:
        subscriber_list = subscriber_list.filter(**kwargs)
        request.session["subscriber_list_kwargs"] = kwargs
    # if contact_name:
    #    # Search on contact name
    #    q = (Q(last_name__icontains=contact_name) |
    #         Q(first_name__icontains=contact_name))
    #    if q:
    #        contact_list = contact_list.filter(q)

    all_subscriber_list = subscriber_list.order_by(sort_order)
    subscriber_list = all_subscriber_list[start_page:end_page]
    subscriber_count = all_subscriber_list.count()

    template = "frontend/subscriber/list.html"
    data = {
        "subscriber_list": subscriber_list,
        "all_subscriber_list": all_subscriber_list,
        "total_subscribers": subscriber_count,
        "PAGE_SIZE": PAGE_SIZE,
        "SUBSCRIBER_COLUMN_NAME": SUBSCRIBER_COLUMN_NAME,
        "col_name_with_order": pagination_data["col_name_with_order"],
        "msg": request.session.get("msg"),
        "error_msg": request.session.get("error_msg"),
        "form": form,
        "dialer_setting_msg": user_dialer_setting_msg(request.user),
        "search_tag": search_tag,
    }
    request.session["msg"] = ""
    request.session["error_msg"] = ""
    return render_to_response(template, data, context_instance=RequestContext(request))
Exemplo n.º 32
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_kwargs']`` - stores voipcall kwargs
    """
    sort_col_field_list = ['starting_date', 'leg_type', 'disposition',
                           'used_gateway', 'callerid', 'callid', 'phone_number',
                           'duration', 'billsec', 'amd_status']
    default_sort_field = 'starting_date'
    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']

    search_tag = 1
    action = 'tabs-1'

    if request.method == 'POST':
        form = VoipSearchForm(request.user, request.POST)
        if form.is_valid():
            field_list = ['start_date', 'end_date',
                          'disposition', 'campaign_id']
            unset_session_var(request, field_list)

            if request.POST.get('from_date'):
                # From
                from_date = request.POST['from_date']
                start_date = ceil_strdate(from_date, 'start')
                request.session['session_start_date'] = start_date

            if request.POST.get('to_date'):
                # To
                to_date = request.POST['to_date']
                end_date = ceil_strdate(to_date, 'end')
                request.session['session_end_date'] = end_date

            disposition = request.POST.get('status')
            if disposition != 'all':
                request.session['session_disposition'] = disposition

            campaign_id = request.POST.get('campaign_id')
            if campaign_id and int(campaign_id) != 0:
                request.session['session_campaign_id'] = int(campaign_id)

    post_var_with_page = 0
    try:
        if request.GET.get('page') or request.GET.get('sort_by'):
            post_var_with_page = 1
            start_date = request.session.get('session_start_date')
            end_date = request.session.get('session_end_date')
            disposition = request.session.get('session_disposition')
            campaign_id = request.session.get('session_campaign_id')
            form = VoipSearchForm(request.user,
                                  initial={'from_date': start_date.strftime('%Y-%m-%d'),
                                           'to_date': end_date.strftime('%Y-%m-%d'),
                                           'status': disposition,
                                           'campaign_id': campaign_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
        tday = datetime.today()
        from_date = tday.strftime('%Y-%m-%d')
        to_date = tday.strftime('%Y-%m-%d')
        start_date = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0)
        end_date = datetime(tday.year, tday.month, tday.day, 23, 59, 59, 999999)
        disposition = 'all'
        campaign_id = 0
        form = VoipSearchForm(request.user,
                              initial={'from_date': from_date, 'to_date': to_date,
                                       'status': disposition, 'campaign_id': campaign_id})
        # unset session var
        request.session['session_start_date'] = start_date
        request.session['session_end_date'] = end_date
        request.session['session_disposition'] = disposition
        request.session['session_campaign_id'] = ''

    kwargs = {}
    if start_date and end_date:
        kwargs['starting_date__range'] = (start_date, end_date)
    if start_date and end_date == '':
        kwargs['starting_date__gte'] = start_date
    if start_date == '' and end_date:
        kwargs['starting_date__lte'] = end_date

    if disposition and disposition != 'all':
        kwargs['disposition__exact'] = disposition

    if campaign_id and int(campaign_id) != 0:
        kwargs['callrequest__campaign_id'] = campaign_id

    if not request.user.is_superuser:
        kwargs['user'] = request.user

    voipcall_list = VoIPCall.objects.filter(**kwargs)

    all_voipcall_list = voipcall_list.values_list('id', flat=True)

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

    if request.GET.get('page') or request.GET.get('sort_by'):
        daily_data = request.session['voipcall_daily_data']
    else:
        if not voipcall_list:
            request.session['voipcall_daily_data'] = ''
        daily_data = get_voipcall_daily_data(voipcall_list)
        request.session['voipcall_daily_data'] = daily_data

    voipcall_list = voipcall_list.order_by(sort_order)[start_page:end_page]

    template = 'frontend/report/voipcall_report.html'
    data = {
        'form': form,
        'total_data': daily_data['total_data'],
        'total_duration': daily_data['total_duration'],
        'total_calls': daily_data['total_calls'],
        'total_avg_duration': daily_data['total_avg_duration'],
        'max_duration': daily_data['max_duration'],
        'module': current_view(request),
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
        'all_voipcall_list': all_voipcall_list,
        'voipcall_list': voipcall_list,
        'PAGE_SIZE': PAGE_SIZE,
        'CDR_REPORT_COLUMN_NAME': CDR_REPORT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'search_tag': search_tag,
        'start_date': start_date,
        'end_date': end_date,
        'action': action,
        'AMD': settings.AMD,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 33
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_kwargs']`` - stores voipcall kwargs
    """
    sort_col_field_list = ['starting_date', 'leg_type', 'disposition',
                           'used_gateway', 'callerid', 'callid', 'phone_number',
                           'duration', 'billsec', 'amd_status']
    default_sort_field = 'starting_date'
    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']

    search_tag = 1
    action = 'tabs-1'

    if request.method == 'POST':
        form = VoipSearchForm(request.user, request.POST)
        if form.is_valid():
            field_list = ['start_date', 'end_date',
                          'disposition', 'campaign_id', 'leg_type']
            unset_session_var(request, field_list)

            if request.POST.get('from_date'):
                # From
                from_date = request.POST['from_date']
                start_date = ceil_strdate(from_date, 'start')
                request.session['session_start_date'] = start_date

            if request.POST.get('to_date'):
                # To
                to_date = request.POST['to_date']
                end_date = ceil_strdate(to_date, 'end')
                request.session['session_end_date'] = end_date

            disposition = request.POST.get('status')
            if disposition != 'all':
                request.session['session_disposition'] = disposition

            campaign_id = request.POST.get('campaign_id')
            if campaign_id and int(campaign_id) != 0:
                request.session['session_campaign_id'] = int(campaign_id)

            leg_type = request.POST.get('leg_type')
            if leg_type and leg_type != '':
                request.session['session_leg_type'] = leg_type

    post_var_with_page = 0
    try:
        if request.GET.get('page') or request.GET.get('sort_by'):
            post_var_with_page = 1
            start_date = request.session.get('session_start_date')
            end_date = request.session.get('session_end_date')
            disposition = request.session.get('session_disposition')
            campaign_id = request.session.get('session_campaign_id')
            leg_type = request.session.get('session_leg_type')
            form = VoipSearchForm(request.user,
                                  initial={'from_date': start_date.strftime('%Y-%m-%d'),
                                           'to_date': end_date.strftime('%Y-%m-%d'),
                                           'status': disposition,
                                           'campaign_id': campaign_id,
                                           'leg_type': leg_type})
        else:
            post_var_with_page = 1
            if request.method == 'GET':
                post_var_with_page = 0
    except:
        pass

    if post_var_with_page == 0:
        # default
        tday = datetime.today()
        from_date = tday.strftime('%Y-%m-%d')
        to_date = tday.strftime('%Y-%m-%d')
        start_date = datetime(tday.year, tday.month, tday.day, 0, 0, 0, 0)
        end_date = datetime(tday.year, tday.month, tday.day, 23, 59, 59, 999999)
        disposition = 'all'
        campaign_id = 0
        leg_type = ''
        form = VoipSearchForm(request.user,
                              initial={'from_date': from_date,
                                       'to_date': to_date,
                                       'status': disposition,
                                       'campaign_id': campaign_id,
                                       'leg_type': leg_type})
        # unset session var
        request.session['session_start_date'] = start_date
        request.session['session_end_date'] = end_date
        request.session['session_disposition'] = disposition
        request.session['session_campaign_id'] = ''
        request.session['session_leg_type'] = ''

    kwargs = {}
    if start_date and end_date:
        kwargs['starting_date__range'] = (start_date, end_date)
    if start_date and end_date == '':
        kwargs['starting_date__gte'] = start_date
    if start_date == '' and end_date:
        kwargs['starting_date__lte'] = end_date

    if disposition and disposition != 'all':
        kwargs['disposition__exact'] = disposition

    if campaign_id and int(campaign_id) != 0:
        kwargs['callrequest__campaign_id'] = campaign_id

    if leg_type and leg_type != '':
        kwargs['leg_type__exact'] = leg_type

    if not request.user.is_superuser:
        kwargs['user'] = request.user

    voipcall_list = VoIPCall.objects.filter(**kwargs)

    all_voipcall_list = voipcall_list.values_list('id', flat=True)

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

    if request.GET.get('page') or request.GET.get('sort_by'):
        daily_data = request.session['voipcall_daily_data']
    else:
        if not voipcall_list:
            request.session['voipcall_daily_data'] = ''
        daily_data = get_voipcall_daily_data(voipcall_list)
        request.session['voipcall_daily_data'] = daily_data

    voipcall_list = voipcall_list.order_by(sort_order)[start_page:end_page]

    template = 'frontend/report/voipcall_report.html'
    data = {
        'form': form,
        'total_data': daily_data['total_data'],
        'total_duration': daily_data['total_duration'],
        'total_calls': daily_data['total_calls'],
        'total_avg_duration': daily_data['total_avg_duration'],
        'max_duration': daily_data['max_duration'],
        'module': current_view(request),
        'dialer_setting_msg': user_dialer_setting_msg(request.user),
        'all_voipcall_list': all_voipcall_list,
        'voipcall_list': voipcall_list,
        'PAGE_SIZE': PAGE_SIZE,
        'CDR_REPORT_COLUMN_NAME': CDR_REPORT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'search_tag': search_tag,
        'start_date': start_date,
        'end_date': end_date,
        'action': action,
        'AMD': settings.AMD,
    }
    request.session['msg'] = ''
    request.session['error_msg'] = ''
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 34
0
def alert_report(request):
    """
    To get alarm report for logged in user

    **Attributes**:

        * ``form`` - AlarmReportForm
        * ``template`` - frontend/cdr_alert/alarm_report.html
    """
    form = AlarmReportForm(request.user, initial={'alarm': 0})
    sort_col_field_list = ['id', 'alarm', 'calculatedvalue', 'status','daterun']
    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']
    search_tag = 1
    alert_id = ''
    action = 'tabs-1'

    if request.method == 'POST':
        form = AlarmReportForm(request.user, request.POST)
        if form.is_valid():
            request.session['session_alarm'] = ''

            if request.POST.get('alarm'):
                alert_id = request.POST.get('alarm')
                request.session['session_alarm'] = alert_id

    post_var_with_page = 0
    try:
        if request.GET.get('page') or request.GET.get('sort_by'):
            post_var_with_page = 1
            alert_id = request.session.get('session_alarm')
            form = AlarmReportForm(request.user, initial={'alarm': alert_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
        request.session['session_alarm'] = ''

    kwargs = {}
    if alert_id and alert_id != 0:
        kwargs['alarm_id'] = alert_id
    kwargs['alarm__user'] = request.user

    alarm_report_list = AlarmReport.objects.filter(**kwargs).order_by(sort_order)
    days_report = last_seven_days_report(request, kwargs)

    total_data = days_report['total_data']
    total_alert = days_report['total_alert']
    start_date = days_report['start_date']
    end_date = days_report['end_date']

    template = 'frontend/cdr_alert/alarm_report.html'
    data = {
        'module': current_view(request),
        'form': form,
        'action': action,
        'total_data': total_data,
        'start_date': start_date,
        'end_date': end_date,
        'rows': alarm_report_list,
        'total_count': alarm_report_list.count(),
        'PAGE_SIZE': PAGE_SIZE,
        'ALARM_REPORT_COLUMN_NAME': ALARM_REPORT_COLUMN_NAME,
        'col_name_with_order': pagination_data['col_name_with_order'],
        'notice_count': notice_count(request),
    }
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Exemplo n.º 35
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 = ''

    survey_cdr_daily_data = {
        'total_data': '',
        'total_duration': '',
        'total_calls': '',
        'total_avg_duration': '',
        'max_duration': '',
    }

    sort_col_field_list = ['starting_date', 'phone_number', 'duration',
                           'disposition', 'id']
    default_sort_field = 'starting_date'
    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']

    campaign_obj = ''
    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_kwargs'] = ''
            request.session['session_survey_cdr_daily_data'] = {}

            if "from_date" in request.POST:
                # From
                from_date = request.POST['from_date']
                request.session['session_from_date'] = from_date

            if "to_date" in request.POST:
                # To
                to_date = request.POST['to_date']
                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_kwargs'] = ''
        request.session['session_search_tag'] = search_tag

    start_date = ceil_strdate(from_date, 'start')
    end_date = ceil_strdate(to_date, 'end')

    kwargs = {}
    if not request.user.is_superuser:
        kwargs['user'] = request.user
    kwargs['disposition__exact'] = VOIPCALL_DISPOSITION.ANSWER

    survey_result_kwargs = {}

    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

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

        survey_result = get_survey_result(survey_result_kwargs)
        kwargs['callrequest__campaign'] = campaign_obj

        # List of Survey VoIP call report
        voipcall_list = VoIPCall.objects.filter(**kwargs)
        request.session['session_surveycalls_kwargs'] = kwargs
        all_call_list = voipcall_list.values_list('id', flat=True)

        # 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']
            action = 'tabs-2'
        else:
            survey_cdr_daily_data = survey_cdr_daily_report(voipcall_list)
            request.session['session_survey_cdr_daily_data'] = survey_cdr_daily_data

        rows = voipcall_list.order_by(sort_order)[start_page:end_page]
    except:
        rows = []
        if request.method == 'POST':
            request.session["err_msg"] = _('no campaign attached with survey.')

    template = 'frontend/survey/survey_report.html'

    data = {
        'rows': rows,
        'all_call_list': all_call_list,
        'call_count': all_call_list.count() if all_call_list else 0,
        'PAGE_SIZE': PAGE_SIZE,
        'SURVEY_CALL_RESULT_NAME': SURVEY_CALL_RESULT_NAME,
        'col_name_with_order': pagination_data['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'),
        'form': form,
        'survey_result': survey_result,
        'action': action,
        'search_tag': search_tag,
        'start_date': start_date,
        'end_date': end_date,
        'campaign_obj': campaign_obj,
    }
    request.session['msg'] = ''
    request.session['err_msg'] = ''
    return render_to_response(template, data,
                              context_instance=RequestContext(request))
Exemplo n.º 36
0
def contact_list(request):
    """Contact list for the logged in user

    **Attributes**:

        * ``template`` - frontend/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"]
    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"]

    form = ContactSearchForm(request.user)
    phonebook_id_list = Phonebook.objects.values_list("id", flat=True).filter(user=request.user)
    search_tag = 1
    contact_no = ""
    contact_name = ""
    phonebook = ""
    contact_status = STATUS_CHOICE.ALL
    if request.method == "POST":
        form = ContactSearchForm(request.user, request.POST)
        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 = 0
    try:
        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,
                },
            )
        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 = ["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 = type_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
            q = Q(last_name__icontains=contact_name) | Q(first_name__icontains=contact_name)
            if q:
                contact_list = contact_list.filter(q)

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

    template = "frontend/contact/list.html"
    data = {
        "contact_list": contact_list,
        "all_contact_list": all_contact_list,
        "total_contacts": contact_count,
        "PAGE_SIZE": PAGE_SIZE,
        "CONTACT_COLUMN_NAME": CONTACT_COLUMN_NAME,
        "col_name_with_order": pagination_data["col_name_with_order"],
        "msg": request.session.get("msg"),
        "error_msg": request.session.get("error_msg"),
        "form": form,
        "dialer_setting_msg": user_dialer_setting_msg(request.user),
        "search_tag": search_tag,
    }
    request.session["msg"] = ""
    request.session["error_msg"] = ""
    return render_to_response(template, data, context_instance=RequestContext(request))