Beispiel #1
0
def alert_report(request):
    """
    To get alarm report for logged in user

    **Attributes**:

        * ``form`` - AlarmReportForm
        * ``template`` - cdr_alert/alarm_report.html
    """
    form = AlarmReportForm(request.user, request.POST or None)
    sort_col_field_list = [
        'id', 'alarm', 'calculatedvalue', 'status', 'daterun'
    ]
    page_data = get_pagination_vars(request,
                                    sort_col_field_list,
                                    default_sort_field='id')

    alarm_id = 0
    action = 'tabs-1'
    post_var_with_page = 0
    if form.is_valid():
        post_var_with_page = 1
        request.session['session_alarm_id'] = ''
        alarm_id = getvar(request, 'alarm_id', setsession=True)

    if request.GET.get('page') or request.GET.get('sort_by'):
        post_var_with_page = 1
        alarm_id = request.session.get('session_alarm_id')
        form = AlarmReportForm(request.user, initial={'alarm_id': alarm_id})

    if post_var_with_page == 0:
        # unset session var
        request.session['session_alarm_id'] = ''

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

    alarm_report_list = AlarmReport.objects.filter(**kwargs)
    all_alarm_list = alarm_report_list.order_by(page_data['sort_order'])
    alarm_list = all_alarm_list[page_data['start_page']:page_data['end_page']]
    contact_alarm = all_alarm_list.count()

    days_report = last_seven_days_report(request, kwargs)

    data = {
        'form': form,
        'action': action,
        'total_data': days_report['total_data'],
        'start_date': days_report['start_date'],
        'end_date': days_report['end_date'],
        'all_alarm_list': all_alarm_list,
        'rows': alarm_list,
        'total_count': contact_alarm,
        'ALARM_REPORT_COLUMN_NAME': ALARM_REPORT_COLUMN_NAME,
        'col_name_with_order': page_data['col_name_with_order'],
        'charttype': days_report['charttype'],
        'chartdata': days_report['chartdata'],
        'chartcontainer': 'chartcontainer',
        'extra': {
            'x_is_date': True,
            'x_axis_format': '%d %b %y',
            'tag_script_js': False,
            'jquery_on_ready': True,
        },
    }
    return render_to_response('cdr_alert/alarm_report.html',
                              data,
                              context_instance=RequestContext(request))
Beispiel #2
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))
Beispiel #3
0
def alert_report(request):
    """
    To get alarm report for logged in user

    **Attributes**:

        * ``form`` - AlarmReportForm
        * ``template`` - cdr_alert/alarm_report.html
    """
    form = AlarmReportForm(request.user, request.POST or None)
    sort_col_field_list = ['id', 'alarm', 'calculatedvalue', 'status', 'daterun']
    page_data = get_pagination_vars(request, sort_col_field_list, default_sort_field='id')

    alarm_id = 0
    action = 'tabs-1'
    post_var_with_page = 0
    if form.is_valid():
        post_var_with_page = 1
        request.session['session_alarm_id'] = ''
        alarm_id = getvar(request, 'alarm_id', setsession=True)

    if request.GET.get('page') or request.GET.get('sort_by'):
        post_var_with_page = 1
        alarm_id = request.session.get('session_alarm_id')
        form = AlarmReportForm(request.user, initial={'alarm_id': alarm_id})

    if post_var_with_page == 0:
        # unset session var
        request.session['session_alarm_id'] = ''

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

    alarm_report_list = AlarmReport.objects.filter(**kwargs)
    all_alarm_list = alarm_report_list.order_by(page_data['sort_order'])
    alarm_list = all_alarm_list[page_data['start_page']:page_data['end_page']]
    contact_alarm = all_alarm_list.count()

    days_report = last_seven_days_report(request, kwargs)

    data = {
        'form': form,
        'action': action,
        'total_data': days_report['total_data'],
        'start_date': days_report['start_date'],
        'end_date': days_report['end_date'],
        'all_alarm_list': all_alarm_list,
        'rows': alarm_list,
        'total_count': contact_alarm,
        'ALARM_REPORT_COLUMN_NAME': ALARM_REPORT_COLUMN_NAME,
        'col_name_with_order': page_data['col_name_with_order'],
        'charttype': days_report['charttype'],
        'chartdata': days_report['chartdata'],
        'chartcontainer': 'chartcontainer',
        'extra': {
            'x_is_date': True,
            'x_axis_format': '%d %b %y',
            'tag_script_js': False,
            'jquery_on_ready': True,
        },
    }
    return render_to_response('cdr_alert/alarm_report.html', data, context_instance=RequestContext(request))