cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
storage_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.forms.storage_image
22 #
23 # @author Krzysztof Danielowski
24 # @author Piotr Wójcik
25 #
26 
27 from django import forms
28 from django.utils.translation import ugettext_lazy as _
29 
30 from wi.utils import parsing
31 from wi.utils.forms import attrs_dict, BetterForm
32 from wi.utils.states import image_platforms_reversed
33 from wi.utils.widgets import SelectWithDisabled
34 
35 
36 ##
37 #
38 # Form for <b>disk edition</b>.
39 #
40 class EditDiskForm(forms.Form):
41 
42  name = forms.CharField(widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=45)),
43  label=_('Disk name'))
44 
45  description = forms.CharField(required=False,
46  widget=forms.Textarea(attrs=dict(attrs_dict, maxlength=512, rows=3, cols=20)),
47  label=_('Disk description'))
48 
49  def __init__(self, *args, **kwargs):
50  rest_data = kwargs.pop('rest_data')
51  super(EditDiskForm, self).__init__(*args, **kwargs)
52 
53  self.fields['disk_controller'] = forms.ChoiceField(choices=parsing.parse_generic_enabled(rest_data, 'disk_controllers'),
54  widget=SelectWithDisabled(attrs=dict()),
55  label=_("Bus"))
56  self.fields['disk_controller'].widget.attrs['class'] = 'medium'
57 
58  ##
59  #
60  # Cast 'disk_controller' to int.
61  #
63  return int(self.cleaned_data['disk_controller'])
64 
65 
66 ##
67 #
68 # Form for <b>disk addition</b>.
69 #
71  size = forms.IntegerField(max_value=2000000, min_value=2, label=_('Disk size [MB]'))
72 
73  def __init__(self, *args, **kwargs):
74  super(AddDiskForm, self).__init__(*args, **kwargs)
75  rest_data = kwargs.pop('rest_data')
76 
77  self.fields['filesystem'] = forms.ChoiceField(choices=parsing.parse_generic(rest_data, 'supported_filesystems'),
78  widget=SelectWithDisabled(attrs=dict()),
79  label=_('File system'))
80  self.fields['filesystem'].widget.attrs['class'] = 'medium'
81 
82  ##
83  #
84  # Cast 'filesystem' to int.
85  #
86  def clean_filesystem(self):
87  return int(self.cleaned_data['filesystem'])
88 
89 
90 ##
91 #
92 # Form for <b>disk's ulpoad</b>.
93 #
94 class UploadDiskForm(BetterForm):
95  ##
96  #
97  # Fieldset names definition.
98  #
99  class Meta:
100  fieldsets = (('description', {'fields': ('name', 'description'), 'legend': _('Disk description')}),
101  ('settings', {'fields': ('path', 'disk_controller', 'filesystem'), 'legend': _('Settings')}),)
102 
103  def __init__(self):
104  pass
105 
106  name = forms.CharField(widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=45)),
107  label=_('Name'))
108  description = forms.CharField(required=False,
109  widget=forms.Textarea(attrs=dict(attrs_dict, maxlength=512, rows=3, cols=20)),
110  label=_('Description'))
111  path = forms.CharField(widget=forms.Textarea(attrs=dict(attrs_dict, maxlength=500, rows=3, cols=20)),
112  label=_('Link to disk image (http:// or ftp://)'))
113 
114  def __init__(self, *args, **kwargs):
115  rest_data = kwargs.pop('rest_data')
116  super(UploadDiskForm, self).__init__(*args, **kwargs)
117 
118  self.fields['disk_controller'] = forms.ChoiceField(choices=parsing.parse_generic_enabled(rest_data, 'disk_controllers'),
119  widget=SelectWithDisabled(attrs=dict()),
120  label=_("Bus"))
121  self.fields['disk_controller'].widget.attrs['class'] = 'medium'
122 
123  ##
124  #
125  # Cast 'disk_controller' to int.
126  #
128  return int(self.cleaned_data['disk_controller'])
129 
130 
131 ##
132 #
133 # Form for <b>adding HTTP to image</b>.
134 #
135 class ConvertImageForm(forms.Form):
136 
137  platform = forms.ChoiceField(choices=image_platforms_reversed.items(),
138  label=_('Platform'))
139 
140  def __init__(self, *args, **kwargs):
141  rest_data = kwargs.pop('rest_data')
142  super(ConvertImageForm, self).__init__(*args, **kwargs)
143  self.fields['platform'].widget.attrs['class'] = 'medium'
144 
145  self.fields['disk_controller'] = forms.ChoiceField(choices=parsing.parse_generic_enabled(rest_data, 'disk_controllers'),
146  widget=SelectWithDisabled(attrs=dict()),
147  label=_('Bus'))
148  self.fields['disk_controller'].widget.attrs['class'] = 'medium'
149 
150  self.fields['video_device'] = forms.ChoiceField(choices=parsing.parse_generic(rest_data, 'video_devices'),
151  widget=SelectWithDisabled(attrs=dict()),
152  label=_('Video'))
153  self.fields['video_device'].widget.attrs['class'] = 'medium'
154 
155  self.fields['network_device'] = forms.ChoiceField(choices=parsing.parse_generic(rest_data, 'network_devices'),
156  widget=SelectWithDisabled(attrs=dict()),
157  label=_("Net"))
158  self.fields['network_device'].widget.attrs['class'] = 'medium'
159 
160  ##
161  #
162  # Cast 'disk_controller' to int.
163  #
165  return int(self.cleaned_data['disk_controller'])
166 
167  ##
168  #
169  # Cast 'video_device' to int.
170  #
172  return int(self.cleaned_data['video_device'])
173 
174  ##
175  #
176  # Cast 'network_device' to int.
177  #
179  return int(self.cleaned_data['network_device'])
180 
181  ##
182  #
183  # Cast 'platform' to int.
184  #
185  def clean_platform(self):
186  return int(self.cleaned_data['platform'])
187