cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
system_image.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.clm.views.admin_cm.system_image
22 # @alldecoratedby{src.clm.utils.decorators.admin_cm_log}
23 #
24 
25 from clm.models.group import Group
26 from clm.models.user import User
27 from clm.utils.cm import CM
28 from clm.utils.decorators import admin_cm_log, cm_request
29 from clm.utils.exception import CLMException
30 from common.states import image_access, group_states
31 
32 
33 @admin_cm_log(log=False, pack=True)
34 ##
35 #
36 # @clmview_admin_cm
37 # @param_post{access,int} number representing image access, @seealso{src.common.states.image_access}
38 # @param_post{group_id,int} required for group access
39 # @param_post{user_id,int}
40 #
41 def get_list(cm_id, caller_id, **data):
42  if data['access'] == image_access['group']:
43  groups = Group.objects.all()
44  if data.get('group_id', None):
45  groups = groups.filter(usergroup__user_id__exact=data['user_id']).filter(usergroup__status__exact=group_states['ok'])
46 
47  data['group_id'] = []
48  r = {}
49  for g in groups:
50  data['group_id'].append(int(g.id))
51  r[g.id] = {'name': g.name, 'images': []}
52 
53  resp = CM(cm_id).send_request("admin_cm/system_image/get_list/", caller_id=caller_id, **data)
54 
55  d = {}
56  for img in resp['data']:
57  if str(img['user_id']) not in d:
58  try:
59  u = User.objects.get(pk=img['user_id'])
60  d[str(img['user_id'])] = u.first + " " + u.last
61  except:
62  raise CLMException('user_get')
63  img['owner'] = d[str(img['user_id'])]
64 
65  if data['access'] == image_access['group']:
66  d = {}
67  for img in resp['data']:
68  r[img['group_id']]['images'].append(img)
69 
70  if img['user_id'] not in d:
71  try:
72  u = User.objects.get(pk=img['user_id'])
73  d[img['user_id']] = u.first + " " + u.last
74  except:
75  raise CLMException('user_get')
76  img['owner'] = d[img['user_id']]
77  r = [{'group_id': k, 'name': v['name'], 'images': v['images']} for k, v in r.iteritems()]
78 
79  return r
80 
81  return resp['data']
82 
83 
84 @admin_cm_log(log=False, pack=False)
85 @cm_request
86 ##
87 #
88 # @clmview_admin_cm
89 # @cm_request_transparent{system_image.get_by_id()}
90 #
91 def get_by_id(cm_response, **data):
92  return cm_response
93 
94 
95 @admin_cm_log(log=True, pack=False)
96 @cm_request
97 ##
98 #
99 # @clmview_admin_cm
100 # @cm_request_transparent{system_image.delete()}
101 #
102 def delete(cm_response, **data):
103  return cm_response
104 
105 
106 @admin_cm_log(log=True, pack=False)
107 @cm_request
108 ##
109 #
110 # @clmview_admin_cm
111 # @cm_request_transparent{system_image.edit()}
112 #
113 def edit(cm_response, **data):
114  return cm_response
115 
116 
117 @admin_cm_log(log=True, pack=False)
118 @cm_request
119 ##
120 #
121 # @clmview_admin_cm
122 # @cm_request_transparent{system_image.download()}
123 #
124 def download(cm_response, **data):
125  return cm_response
126 
127 
128 @admin_cm_log(log=True, pack=False)
129 @cm_request
130 ##
131 #
132 # @clmview_admin_cm
133 # @cm_request_transparent{system_image.copy()}
134 #
135 def copy(cm_response, **data):
136  return cm_response
137 
138 
139 @admin_cm_log(log=True, pack=False)
140 @cm_request
141 ##
142 #
143 # @clmview_admin_cm
144 # @cm_request_transparent{system_image.set_public()}
145 #
146 def set_public(cm_response, **data):
147  return cm_response
148 
149 
150 @admin_cm_log(log=True, pack=False)
151 @cm_request
152 ##
153 #
154 # @clmview_admin_cm
155 # @cm_request_transparent{system_image.set_private()}
156 #
157 def set_private(cm_response, **data):
158  return cm_response
159