~ubuntu-branches/ubuntu/utopic/horizon/utopic

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/admin/volumes/extras/views.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-07-25 11:39:09 UTC
  • mfrom: (1.1.42)
  • Revision ID: package-import@ubuntu.com-20140725113909-b8920pdy87itn1ro
Tags: 1:2014.2~b2-0ubuntu1
* New upstream release.
* debian/patches/ubuntu_settings.patch: Refresed
* debian/patches/fix-dashboard-manage.patch: Refreshed
* debian/patches/fix-dashboard-django-wsgi.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
2
# not use this file except in compliance with the License. You may obtain
 
3
# a copy of the License at
 
4
#
 
5
#      http://www.apache.org/licenses/LICENSE-2.0
 
6
#
 
7
# Unless required by applicable law or agreed to in writing, software
 
8
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
9
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
10
# License for the specific language governing permissions and limitations
 
11
# under the License.
 
12
 
 
13
from django.core.urlresolvers import reverse
 
14
from django.utils.translation import ugettext_lazy as _
 
15
 
 
16
from horizon import exceptions
 
17
from horizon import forms
 
18
from horizon import tables
 
19
 
 
20
from openstack_dashboard import api
 
21
 
 
22
from openstack_dashboard.dashboards.admin.volumes.extras \
 
23
    import forms as project_forms
 
24
from openstack_dashboard.dashboards.admin.volumes.extras \
 
25
    import tables as project_tables
 
26
 
 
27
 
 
28
class ExtraSpecMixin(object):
 
29
    def get_context_data(self, **kwargs):
 
30
        context = super(ExtraSpecMixin, self).get_context_data(**kwargs)
 
31
        try:
 
32
            context['vol_type'] = api.cinder.volume_type_get(self.request,
 
33
                                                    self.kwargs['type_id'])
 
34
        except Exception:
 
35
            exceptions.handle(self.request,
 
36
                              _("Unable to retrieve volume type details."))
 
37
        if 'key' in self.kwargs:
 
38
            context['key'] = self.kwargs['key']
 
39
        return context
 
40
 
 
41
 
 
42
class IndexView(ExtraSpecMixin, forms.ModalFormMixin, tables.DataTableView):
 
43
    table_class = project_tables.ExtraSpecsTable
 
44
    template_name = 'admin/volumes/extras/index.html'
 
45
 
 
46
    def get_data(self):
 
47
        try:
 
48
            type_id = self.kwargs['type_id']
 
49
            extras_list = api.cinder.volume_type_extra_get(self.request,
 
50
                                                           type_id)
 
51
            extras_list.sort(key=lambda es: (es.key,))
 
52
        except Exception:
 
53
            extras_list = []
 
54
            exceptions.handle(self.request,
 
55
                              _('Unable to retrieve extra spec list.'))
 
56
        return extras_list
 
57
 
 
58
 
 
59
class CreateView(ExtraSpecMixin, forms.ModalFormView):
 
60
    form_class = project_forms.CreateExtraSpec
 
61
    template_name = 'admin/volumes/extras/create.html'
 
62
 
 
63
    def get_initial(self):
 
64
        return {'type_id': self.kwargs['type_id']}
 
65
 
 
66
    def get_success_url(self):
 
67
        return "/admin/volumes/%s/extras/" % (self.kwargs['type_id'])
 
68
 
 
69
 
 
70
class EditView(ExtraSpecMixin, forms.ModalFormView):
 
71
    form_class = project_forms.EditExtraSpec
 
72
    template_name = 'admin/volumes/extras/edit.html'
 
73
    success_url = 'horizon:admin:volumes:extras:index'
 
74
 
 
75
    def get_success_url(self):
 
76
        return reverse(self.success_url,
 
77
                       args=(self.kwargs['type_id'],))
 
78
 
 
79
    def get_initial(self):
 
80
        type_id = self.kwargs['type_id']
 
81
        key = self.kwargs['key']
 
82
        try:
 
83
            extra_specs = api.cinder.volume_type_extra_get(self.request,
 
84
                                                           type_id,
 
85
                                                           raw=True)
 
86
        except Exception:
 
87
            extra_specs = {}
 
88
            exceptions.handle(self.request,
 
89
                              _('Unable to retrieve volume type extra spec '
 
90
                                'details.'))
 
91
        return {'type_id': type_id,
 
92
                'key': key,
 
93
                'value': extra_specs.get(key, '')}