This repository has been archived by the owner on May 18, 2024. It is now read-only.
/
views.py
100 lines (77 loc) · 3.46 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Copyright (c) 2013 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from django.core.urlresolvers import reverse_lazy
from horizon import forms
from horizon import tables
from horizon import tabs
from horizon import workflows
from saharadashboard.api.client import client as saharaclient
from saharadashboard.cluster_templates import forms as cluster_forms
from saharadashboard.cluster_templates.tables import ClusterTemplatesTable
import saharadashboard.cluster_templates.tabs as _tabs
import saharadashboard.cluster_templates.workflows.copy as copy_flow
import saharadashboard.cluster_templates.workflows.create as create_flow
LOG = logging.getLogger(__name__)
class ClusterTemplatesView(tables.DataTableView):
table_class = ClusterTemplatesTable
template_name = 'cluster_templates/cluster_templates.html'
def get_data(self):
sahara = saharaclient(self.request)
cluster_templates = sahara.cluster_templates.list()
return cluster_templates
class ClusterTemplateDetailsView(tabs.TabView):
tab_group_class = _tabs.ClusterTemplateDetailsTabs
template_name = 'cluster_templates/details.html'
def get_context_data(self, **kwargs):
context = super(ClusterTemplateDetailsView, self)\
.get_context_data(**kwargs)
return context
def get_data(self):
pass
class UploadFileView(forms.ModalFormView):
form_class = cluster_forms.UploadFileForm
template_name = 'cluster_templates/upload_file.html'
success_url = reverse_lazy('horizon:sahara:cluster_templates:index')
class CreateClusterTemplateView(workflows.WorkflowView):
workflow_class = create_flow.CreateClusterTemplate
success_url = \
"horizon:sahara:cluster_templates:create-cluster-template"
classes = ("ajax-modal")
template_name = "cluster_templates/create.html"
class ConfigureClusterTemplateView(workflows.WorkflowView):
workflow_class = create_flow.ConfigureClusterTemplate
success_url = "horizon:sahara:cluster_templates"
template_name = "cluster_templates/configure.html"
class CopyClusterTemplateView(workflows.WorkflowView):
workflow_class = copy_flow.CopyClusterTemplate
success_url = "horizon:sahara:cluster_templates"
template_name = "cluster_templates/configure.html"
def get_context_data(self, **kwargs):
context = super(CopyClusterTemplateView, self)\
.get_context_data(**kwargs)
context["template_id"] = kwargs["template_id"]
return context
def get_object(self, *args, **kwargs):
if not hasattr(self, "_object"):
template_id = self.kwargs['template_id']
sahara = saharaclient(self.request)
template = sahara.cluster_templates.get(template_id)
self._object = template
return self._object
def get_initial(self):
initial = super(CopyClusterTemplateView, self).get_initial()
initial.update({'template_id': self.kwargs['template_id']})
return initial