cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
iso_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.wi.views.admin_cm.iso_image
22 # @author Krzysztof Danielowski
23 # @author Piotr Wójcik
24 # @date 03.02.2012
25 #
26 
27 from django.template import RequestContext
28 from django.template.defaultfilters import force_escape
29 from django.template.loader import render_to_string
30 from django.utils.translation import ugettext as _
31 from django.views.decorators.csrf import csrf_protect
32 
33 from wi.commontags.templatetags.templatetags import filesizeformatmb
34 from wi.forms.user import CopyToUserForm
35 from wi.utils import messages_ajax
36 from wi.utils.decorators import admin_cm_permission
37 from wi.utils.decorators import django_view
38 from wi.utils.messages_ajax import ajax_request
39 from wi.utils.views import prep_data
40 
41 
42 @django_view
43 @ajax_request
44 @admin_cm_permission
45 ##
46 #
47 # Ajax view for fetching ISO images list.
48 #
50  if request.method == 'GET':
51  iso = prep_data('admin_cm/iso_image/get_list/', request.session)
52 
53  for item in iso:
54  item['size'] = filesizeformatmb(item['size'])
55 
56  return messages_ajax.success(iso)
57 
58 
59 @django_view
60 @ajax_request
61 @admin_cm_permission
62 @csrf_protect
63 ##
64 #
65 # Ajax view for changing the image owner.
66 #
67 def cma_ajax_copy_iso(request, id1, template_name='generic/form.html', form_class=CopyToUserForm):
68  rest_data = prep_data({'users': ('admin_cm/user/get_list/', {'short': True})}, request.session)
69 
70  if request.method == 'POST':
71  form = form_class(data=request.POST, files=request.FILES, rest_data=rest_data)
72  if form.is_valid():
73  dictionary = form.cleaned_data
74  dictionary['src_image_id'] = int(id1)
75  dictionary['dest_user_id'] = int(dictionary['dest_user_id'])
76 
77  prep_data(('admin_cm/iso_image/copy/', dictionary), request.session)
78 
79  return messages_ajax.success(_("<b>%(desc)s</b> copied.") % {'desc': force_escape(request.REQUEST.get('desc'))})
80  else:
81  form = form_class(rest_data=rest_data)
82  return messages_ajax.success(render_to_string(template_name, {'form': form,
83  'confirmation': _('Copy'),
84  'text': _('Select user:')
85  },
86  context_instance=RequestContext(request)),
87  status=1)
88