예제 #1
0
def index(request):
    try:
        if request.is_ajax():
            return JsonResponse({'spaces': maas.get_spaces()})

        context = {
            'title': 'Spaces',
            'spaces': maas.get_spaces(),
            'menus_active': 'spaces_active'
        }
    except (MAASError, ConnectionError, TimeoutError) as e:
        context = None

    return render(request, 'maas/spaces/index.html', context)
예제 #2
0
def detail(request, space_id):
    try:
        spaces = maas.get_spaces(space_id)
        context = {
            'title': _('Detail Space'),
            'space': spaces,
            'subnets': maas.get_subnets()
        }
    except (MAASError, ConnectionError, TimeoutError) as e:
        sweetify.sweetalert(request, 'Warning', icon='error', text=str(e), button='Ok', timer=5000)

    return render(request, 'maas/spaces/detail.html', context)
예제 #3
0
def delete(request, space_id):
    try:
        spaces = maas.get_spaces(space_id)
        if not spaces:
            sweetify.warning(request, _('Data Space not Found..'), timer=5000)
            return redirect('maas.spaces.index')

        space_id = spaces[0]['id']
        m = MAAS()
        resp = m.delete(f'spaces/{space_id}/')
        if resp.status_code in m.ok:
            sweetify.success(request, _('Spaces Deteled Successfully'), timer=2000)
        sweetify.warning(request, _(resp.text), timer=5000)
        return redirect('maas:spaces:index')
    except (MAASError, ConnectionError, TimeoutError) as e:
        sweetify.sweetalert(request, 'Warning', icon='error', text=str(e), button='Ok', timer=5000)
예제 #4
0
def index(request):
    try:
        if request.is_ajax():
            return JsonResponse({'subnets': maas.get_subnets()})
        subnets = maas.get_subnets()
        fabrics = maas.get_fabrics()
        spaces = maas.get_spaces()
        group_subnet = maas.get_subnet_byfabric()
        context = {
            'title': 'Subnet By Fabric',
            'subnets': subnets,
            'fabrics': fabrics,
            'spaces': spaces,
            'group_subnet': group_subnet,
            'menus_active': 'subnets_active'
        }
    except (MAASError, ConnectionError, TimeoutError) as e:
        sweetify.sweetalert(request, 'Warning', text=str(e), icon='error', timer=5000)
        context = None

    return render(request, 'maas/subnets/index.html', context)
예제 #5
0
def edit(request, space_id):
    try:

        spaces = maas.get_spaces(space_id)
        form = forms.SpacesForm(request.POST or None, initial=spaces)

        if form.is_valid():
            data = form.clean()
            m = MAAS()
            resp = m.put(f'/spaces/{space_id}/', data=data)
            if resp.status_code in m.ok:
                sweetify.success(request, _(
                    'Space Successfully Updated'), timer=2000)
            sweetify.warning(request, _(resp.text), timer=5000)
            return redirect('maas:spaces:index')
    except (MAASError, ConnectionError, TimeoutError) as e:
        form = None
        sweetify.sweetalert(request, 'Warning', icon='error', button='Ok', timer=5000, text=str(e))
    context = {
        'title': _('Edit Space'),
        'form': form
    }
    return render(request, 'maas/spaces/add.html', context)
예제 #6
0
 def get_choice_space(self):
     space = maas.get_spaces()
     choices = [(x['id'], x['name']) for x in space]
     choices.insert(0, (None, '-----'))
     return choices
예제 #7
0
 def get_choice_space(self):
     resp = maas.get_spaces()
     b = [(i['id'], i['name']) for i in resp]
     b.insert(0, (None, '-------'))
     return b