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.user.iso_image
22 #
23 # @author Krzysztof Danielowski
24 # @author Piotr Wójcik
25 #
26 
27 from django.template import RequestContext
28 from django.template.loader import render_to_string
29 from django.utils.translation import ugettext as _
30 from django.views.decorators.csrf import csrf_protect
31 
32 from wi.commontags.templatetags.templatetags import filesizeformatmb
33 from wi.forms.iso_image import UploadISOForm
34 from wi.utils import messages_ajax
35 from wi.utils.decorators import django_view, user_permission
36 from wi.utils.messages_ajax import ajax_request
37 from wi.utils.views import prep_data
38 
39 
40 @django_view
41 @ajax_request
42 @user_permission
43 ##
44 #
45 # Ajax view returning iso images list.
46 #
48  if request.method == 'GET':
49  rest_data = prep_data('user/iso_image/get_list/', request.session)
50 
51  for item in rest_data:
52  item['size'] = filesizeformatmb(item['size'])
53  return messages_ajax.success(rest_data)
54 
55 
56 @django_view
57 @ajax_request
58 @user_permission
59 @csrf_protect
60 ##
61 #
62 # Ajax view for uploading iso image from a http link.
63 #
64 def res_ajax_upload_iso_http(request, template_name='generic/form.html', form_class=UploadISOForm):
65  rest_data = prep_data({'disk_controllers': 'user/iso_image/get_disk_controllers/'}, request.session)
66 
67  if request.method == 'POST':
68  form = form_class(data=request.POST, rest_data=rest_data)
69  if form.is_valid():
70  dictionary = form.cleaned_data
71 
72  prep_data({'images': ('user/iso_image/download/', dictionary)}, request.session)
73 
74  return messages_ajax.success(_("ISO image upload started."))
75  else:
76  form = form_class(rest_data=rest_data)
77  return messages_ajax.success(render_to_string(template_name, {'form': form,
78  'confirmation': _('Upload ISO image'),
79  'text': _('Only ISO 9660 image format is supported at the moment. Please specify ISO image parameters:')},
80  context_instance=RequestContext(request)),
81  status=1)
82