cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
network.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 ##
21 # @package src.wi.views.admin_cm.network
22 # @author Krzysztof Danielowski
23 # @author Piotr W√≥jcik
24 # @date 19.10.2012
25 #
26 from django.shortcuts import render_to_response
27 from django.template import RequestContext
28 from django.template.loader import render_to_string
29 
30 from wi.utils import messages_ajax
31 from wi.utils.decorators import admin_cm_permission
32 from wi.utils.decorators import django_view
33 from wi.utils.messages_ajax import ajax_request
34 from wi.utils.states import pool_states_reversed
35 from wi.utils.views import prep_data
36 
37 
38 @django_view
39 @admin_cm_permission
40 ##
41 #
42 # View rendering network list.
43 #
44 def cma_networks(request, template_name='admin_cm/networks.html'):
45  rest_data = prep_data(('admin_cm/user/get_list/', {'short': True}), request.session)
46  return render_to_response(template_name, {'all_users': rest_data}, context_instance=RequestContext(request))
47 
48 
49 @django_view
50 @ajax_request
51 @admin_cm_permission
52 ##
53 #
54 # Ajax view returning network list.
55 #
56 def cma_networks_ajax_get_table(request, user_id, only_unused):
57  if request.method == 'GET':
58  networks = prep_data(('admin_cm/network/list_user_networks/', {'user_id': int(user_id), 'only_unused': int(only_unused)}), request.session)
59  return messages_ajax.success(networks)
60 
61 
62 @django_view
63 @ajax_request
64 @admin_cm_permission
65 ##
66 #
67 # Ajax view fetching network details.
68 #
69 def cma_networks_ajax_network_details(request, network_id, template_name='admin_cm/ajax/network_details.html'):
70  if request.method == 'POST':
71  net = prep_data(('admin_cm/network/list_leases/', {'network_id': network_id}), request.session)
72 
73  return messages_ajax.success(render_to_string(template_name, {'id': int(network_id),
74  'item': net},
75  context_instance=RequestContext(request)))
76 
77 
78 @django_view
79 @ajax_request
80 @admin_cm_permission
81 ##
82 #
83 # Ajax view fetching pool list.
84 #
86  if request.method == 'GET':
87  pools = prep_data('admin_cm/network/list_available_networks/', request.session)
88 
89  for pool in pools:
90  pool['stateName'] = unicode(pool_states_reversed[pool['state']])
91 
92  return messages_ajax.success(pools)
93