Ejemplo n.º 1
0
def api_list_view(request):
    """
    Get List of API names & their links
    """
    exclude_file = ['__init__.py', 'urls.py', 'views.py']
    list_of_api = []
    os.chdir(settings.APPLICATION_DIR + "/api/api_playgrounds/")
    for files in os.listdir("."):
        if files.endswith(".py") and files.endswith(".py"):
            if str(files) not in exclude_file:
                api_arr = str(files).split('_playground.py')
                api_link = '/api-explorer/' + api_arr[0].replace("_", "-")
                list_of_api.append({
                    'api_name': api_arr[0],
                    'api_link': api_link
                })

    template = 'frontend/api/api_list.html'
    data = {
        'list_of_api': list_of_api,
        'notice_count': notice_count(request),
        'module': current_view(request),
    }
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def alarm_add(request):
    """Add new Alarm for the logged in user

    **Attributes**:

        * ``form`` - AlarmForm
        * ``template`` - frontend/cdr_alert/alarm/change.html

    **Logic Description**:

        * Add a new Alarm which will belong to the logged in user
          via the AlarmForm & get redirected to the Alarm list
    """
    form = AlarmForm()
    if request.method == 'POST':
        form = AlarmForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = User.objects.get(username=request.user)
            obj.save()
            request.session["msg"] = _('"%(name)s" added.') %\
                                     {'name': request.POST['name']}
            return HttpResponseRedirect('/alert/')
    template = 'frontend/cdr_alert/alarm/change.html'
    data = {
        'module': current_view(request),
        'form': form,
        'action': 'add',
        'notice_count': notice_count(request),
    }
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Ejemplo n.º 3
0
def trust_control(request):
    #Blacklist, Whitelist
    prefix_list = \
        map(str, Prefix.objects.values_list("prefix", flat=True).all().order_by('prefix'))
    prefix_list = (','.join('"' + item + '"' for item in prefix_list))
    prefix_list = "[" + str(prefix_list) + "]"

    blacklist = Blacklist.objects.filter(user=request.user).order_by('id')
    whitelist = Whitelist.objects.filter(user=request.user).order_by('id')

    # blacklist form
    bl_country_form = BWCountryForm()
    bl_prefix_form = BWPrefixForm()

    # whitelist form
    wl_country_form = BWCountryForm()
    wl_prefix_form = BWPrefixForm()

    template = 'frontend/cdr_alert/common_black_white_list.html'
    data = {
        'module': current_view(request),
        'prefix_list': prefix_list,
        'bl_country_form': bl_country_form,
        'bl_prefix_form': bl_prefix_form,
        'wl_country_form': wl_country_form,
        'wl_prefix_form': wl_prefix_form,
        'blacklist': blacklist,
        'whitelist': whitelist,
        'notice_count': notice_count(request),
    }
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
def api_list_view(request):
    """
    Get List of API names & their links
    """
    exclude_file = ['__init__.py', 'urls.py', 'views.py']
    list_of_api = []
    os.chdir(settings.APPLICATION_DIR + "/api/api_playgrounds/")
    for files in os.listdir("."):
        if files.endswith(".py") and files.endswith(".py"):
            if str(files) not in exclude_file:
                api_arr = str(files).split('_playground.py')
                api_link = '/api-explorer/' + api_arr[0].replace("_", "-")
                list_of_api.append({'api_name': api_arr[0],
                                    'api_link': api_link})

    template = 'frontend/api/api_list.html'
    data = {
        'list_of_api': list_of_api,
        'notice_count': notice_count(request),
        'module': current_view(request),
    }
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Ejemplo n.º 6
0
def alarm_change(request, object_id):
    """Update/Delete Alarm for the logged in user

    **Attributes**:

        * ``object_id`` - Selected alarm object
        * ``form`` - AlarmForm
        * ``template`` - frontend/cdr_alert/alarm/change.html

    **Logic Description**:

        * Update/delete selected alarm from the alarm list
          via alarmForm & get redirected to alarm list
    """
    alarm = get_object_or_404(Alarm, pk=object_id, user=request.user)
    form = AlarmForm(instance=alarm)
    if request.method == 'POST':
        if request.POST.get('delete'):
            alarm_del(request, object_id)
            return HttpResponseRedirect('/alert/')
        else:
            form = AlarmForm(request.POST, instance=alarm)
            if form.is_valid():
                form.save()
                request.session["msg"] = _('"%(name)s" is updated.')\
                                         % {'name': request.POST['name']}
                return HttpResponseRedirect('/alert/')

    template = 'frontend/cdr_alert/alarm/change.html'
    data = {
        'module': current_view(request),
        'form': form,
        'action': 'update',
        'notice_count': notice_count(request),
    }
    return render_to_response(template, data,
        context_instance=RequestContext(request))
Ejemplo n.º 7
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))
Ejemplo n.º 8
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

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

    **Logic Description**:

        * User is able to change their details.
    """
    if not request.user.is_superuser:  # not superuser
        if not chk_account_code(request):
            return HttpResponseRedirect("/?acc_code_error=true")

    user_detail = get_object_or_404(User, username=request.user)
    try:
        user_detail_extened = UserProfile.objects.get(user=user_detail)
    except UserProfile.DoesNotExist:
        # create UserProfile
        user_detail_extened = UserProfile(user=user_detail)
        user_detail_extened.save()

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

    user_password_form = PasswordChangeForm(user=request.user)

    msg_detail = ""
    msg_pass = ""
    error_detail = ""
    error_pass = ""
    action = ""

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

    if request.method == "POST":
        if request.POST["form-type"] == "change-detail":
            user_detail_form = UserChangeDetailForm(request.user, request.POST, instance=user_detail)
            user_detail_extened_form = UserChangeDetailExtendForm(
                request.user, request.POST, instance=user_detail_extened
            )
            action = "tabs-1"
            if user_detail_form.is_valid() and user_detail_extened_form.is_valid():
                user_detail_form.save()
                user_detail_extened_form.save()
                msg_detail = _("Detail has been changed.")
            else:
                error_detail = _("Please correct the errors below.")
        else:
            # change-password
            user_password_form = PasswordChangeForm(user=request.user, data=request.POST)
            action = "tabs-2"
            if user_password_form.is_valid():
                user_password_form.save()
                msg_pass = _("Your password has been changed.")
            else:
                error_pass = _("Please correct the errors below.")

    template = "frontend/registration/user_detail_change.html"
    data = {
        "module": current_view(request),
        "user_detail_form": user_detail_form,
        "user_detail_extened_form": user_detail_extened_form,
        "user_password_form": user_password_form,
        "msg_detail": msg_detail,
        "msg_pass": msg_pass,
        "error_detail": error_detail,
        "error_pass": error_pass,
        "notice_count": notice_count(request),
        "action": action,
    }
    return render_to_response(template, data, context_instance=RequestContext(request))
Ejemplo n.º 9
0
def customer_detail_change(request):
    """User Detail change on Customer UI

    **Attributes**:

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

    **Logic Description**:

        * User is able to change their details.
    """
    if not request.user.is_superuser:  # not superuser
        if not chk_account_code(request):
            return HttpResponseRedirect('/?acc_code_error=true')

    user_detail = get_object_or_404(User, username=request.user)
    try:
        user_detail_extened = UserProfile.objects.get(user=user_detail)
    except UserProfile.DoesNotExist:
        #create UserProfile
        user_detail_extened = UserProfile(user=user_detail)
        user_detail_extened.save()

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

    user_password_form = PasswordChangeForm(user=request.user)

    msg_detail = ''
    msg_pass = ''
    error_detail = ''
    error_pass = ''
    action = ''

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

    if request.method == 'POST':
        if request.POST['form-type'] == "change-detail":
            user_detail_form = UserChangeDetailForm(
                request.user, request.POST, instance=user_detail)
            user_detail_extened_form = UserChangeDetailExtendForm(
                request.user, request.POST, instance=user_detail_extened)
            action = 'tabs-1'
            if user_detail_form.is_valid() and user_detail_extened_form.is_valid():
                user_detail_form.save()
                user_detail_extened_form.save()
                msg_detail = _('Detail has been changed.')
            else:
                error_detail = _('Please correct the errors below.')
        else:
            # change-password
            user_password_form = PasswordChangeForm(user=request.user,
                                                    data=request.POST)
            action = 'tabs-2'
            if user_password_form.is_valid():
                user_password_form.save()
                msg_pass = _('Your password has been changed.')
            else:
                error_pass = _('Please correct the errors below.')

    template = 'frontend/registration/user_detail_change.html'
    data = {
        'module': current_view(request),
        'user_detail_form': user_detail_form,
        'user_detail_extened_form': user_detail_extened_form,
        'user_password_form': user_password_form,
        'msg_detail': msg_detail,
        'msg_pass': msg_pass,
        'error_detail': error_detail,
        'error_pass': error_pass,
        'notice_count': notice_count(request),
        'action': action,
    }
    return render_to_response(template, data,
           context_instance=RequestContext(request))