Browse Source

Fix delete buttons

This commit fixes the delete buttons in all of the GBPUI panels where checked items were deleted even when using individual (row) delete actions.

Change-Id: I4ac44bda1baf28b5056d07adf1236b9a43fbad4c
Closes-Bug: 1707896
Marek Lycka 1 year ago
parent
commit
f4deab2aae

+ 17
- 3
gbpui/panels/application_policy/tables.py View File

@@ -15,6 +15,8 @@ from django.utils.translation import ugettext_lazy as _
15 15
 
16 16
 from horizon import tables
17 17
 
18
+from gbpui import client
19
+
18 20
 
19 21
 class AddAppPolicyLink(tables.LinkAction):
20 22
     name = "addpolicy_rule_set"
@@ -35,13 +37,16 @@ class UpdateAppPolicyLink(tables.LinkAction):
35 37
         return base_url
36 38
 
37 39
 
38
-class DeleteAppPolicyLink(tables.DeleteAction):
40
+class DeletePolicyRuleSetLink(tables.DeleteAction):
39 41
     name = "deletepolicyruleset"
40 42
     action_present = _("Delete")
41 43
     action_past = _("Scheduled deletion of %(data_type)s")
42 44
     data_type_singular = _("Policy Rule Set")
43 45
     data_type_plural = _("Policy Rule Sets")
44 46
 
47
+    def action(self, request, object_id):
48
+        client.policy_rule_set_delete(request, object_id)
49
+
45 50
 
46 51
 class AddPolicyRuleLink(tables.LinkAction):
47 52
     name = "addpolicyrules"
@@ -69,6 +74,9 @@ class DeletePolicyRuleLink(tables.DeleteAction):
69 74
     data_type_singular = _("Policy Rule")
70 75
     data_type_plural = _("Policy Rules")
71 76
 
77
+    def action(self, request, object_id):
78
+        client.policyrule_delete(request, object_id)
79
+
72 80
 
73 81
 class AddPolicyClassifierLink(tables.LinkAction):
74 82
     name = "addpolicyclassifiers"
@@ -96,6 +104,9 @@ class DeletePolicyClassifierLink(tables.DeleteAction):
96 104
     data_type_singular = _("Policy Classifier")
97 105
     data_type_plural = _("Policy Classifiers")
98 106
 
107
+    def action(self, request, object_id):
108
+        client.policyclassifier_delete(request, object_id)
109
+
99 110
 
100 111
 class AddPolicyActionLink(tables.LinkAction):
101 112
     name = "addpolicyactions"
@@ -123,6 +134,9 @@ class DeletePolicyActionLink(tables.DeleteAction):
123 134
     data_type_singular = _("Policy Action")
124 135
     data_type_plural = _("Policy Actions")
125 136
 
137
+    def action(self, request, object_id):
138
+        client.policyaction_delete(request, object_id)
139
+
126 140
 
127 141
 class ApplicationPoliciesTable(tables.DataTable):
128 142
     name = tables.Column("name",
@@ -137,8 +151,8 @@ class ApplicationPoliciesTable(tables.DataTable):
137 151
     class Meta(object):
138 152
         name = "application_policies_table"
139 153
         verbose_name = _("Policy Rule Set")
140
-        table_actions = (AddAppPolicyLink, DeleteAppPolicyLink)
141
-        row_actions = (UpdateAppPolicyLink, DeleteAppPolicyLink)
154
+        table_actions = (AddAppPolicyLink, DeletePolicyRuleSetLink)
155
+        row_actions = (UpdateAppPolicyLink, DeletePolicyRuleSetLink)
142 156
 
143 157
 
144 158
 class PolicyRulesTable(tables.DataTable):

+ 1
- 53
gbpui/panels/application_policy/views.py View File

@@ -9,20 +9,12 @@
9 9
 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 10
 # License for the specific language governing permissions and limitations
11 11
 # under the License.
12
-
13
-import re
14
-
15 12
 from django.core.urlresolvers import reverse
16
-from django.utils.translation import ugettext_lazy as _
17 13
 
18
-from horizon import exceptions
19 14
 from horizon import forms
20
-from horizon import messages
21 15
 from horizon import tabs
22 16
 from horizon import workflows
23 17
 
24
-from gbpui import client
25
-
26 18
 import forms as policy_rule_set_forms
27 19
 import tabs as policy_rule_set_tabs
28 20
 import workflows as policy_rule_set_workflows
@@ -37,54 +29,10 @@ AddPolicyRule = policy_rule_set_workflows.AddPolicyRule
37 29
 AddPolicyClassifier = policy_rule_set_workflows.AddPolicyClassifier
38 30
 
39 31
 
40
-class IndexView(tabs.TabView):
32
+class IndexView(tabs.TabbedTableView):
41 33
     tab_group_class = (PolicyRuleSetTabs)
42 34
     template_name = 'project/application_policy/details_tabs.html'
43 35
 
44
-    def post(self, request, *args, **kwargs):
45
-        obj_ids = request.POST.getlist('object_ids')
46
-        action = request.POST['action']
47
-        obj_type = re.search('delete([a-z]+)', action).group(1)
48
-        if not obj_ids:
49
-            obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
50
-        if obj_type == 'policyaction':
51
-            for obj_id in obj_ids:
52
-                try:
53
-                    client.policyaction_delete(request, obj_id)
54
-                    messages.success(request, _('Deleted action %s') % obj_id)
55
-                except Exception as e:
56
-                    msg = _('Unable to delete action. %s') % (str(e))
57
-                    exceptions.handle(request, msg)
58
-        if obj_type == 'policyclassifier':
59
-            for obj_id in obj_ids:
60
-                try:
61
-                    client.policyclassifier_delete(request, obj_id)
62
-                    messages.success(
63
-                        request, _('Deleted classifer %s') % obj_id)
64
-                except Exception as e:
65
-                    msg = _('Unable to delete action. %s') % (str(e))
66
-                    exceptions.handle(request, msg)
67
-        if obj_type == 'policyrule':
68
-            for obj_id in obj_ids:
69
-                try:
70
-                    client.policyrule_delete(request, obj_id)
71
-                    messages.success(request,
72
-                                     _('Deleted rule %s') % obj_id)
73
-                except Exception as e:
74
-                    msg = _('Unable to delete action. %s') % (str(e))
75
-                    exceptions.handle(request, msg)
76
-        if obj_type == 'policyruleset':
77
-            for obj_id in obj_ids:
78
-                try:
79
-                    client.policy_rule_set_delete(request, obj_id)
80
-                    messages.success(request,
81
-                                     _('Deleted rule %s') % obj_id)
82
-                except Exception as e:
83
-                    msg = _('Unable to delete action. %s') % (str(e))
84
-                    exceptions.handle(request, msg)
85
-
86
-        return self.get(request, *args, **kwargs)
87
-
88 36
 
89 37
 class AddPolicyRuleSetView(workflows.WorkflowView):
90 38
     workflow_class = AddPolicyRuleSet

+ 56
- 21
gbpui/panels/network_policy/tables.py View File

@@ -15,6 +15,8 @@ from django.utils.translation import ugettext_lazy as _
15 15
 
16 16
 from horizon import tables
17 17
 
18
+from gbpui import client
19
+
18 20
 
19 21
 class CreateL2PolicyLink(tables.LinkAction):
20 22
     name = "create_l2policy"
@@ -30,7 +32,7 @@ class EditL2PolicyLink(tables.LinkAction):
30 32
 
31 33
     def get_link_url(self, l2policy):
32 34
         base_url = reverse("horizon:project:network_policy:update_l2policy",
33
-                kwargs={'l2policy_id': l2policy.id})
35
+                           kwargs={'l2policy_id': l2policy.id})
34 36
         return base_url
35 37
 
36 38
 
@@ -41,11 +43,16 @@ class DeleteL2PolicyLink(tables.DeleteAction):
41 43
     data_type_singular = _("L2Policy")
42 44
     data_type_plural = _("L2Policies")
43 45
 
46
+    def action(self, request, object_id):
47
+        client.l2policy_delete(request, object_id)
48
+
44 49
 
45 50
 class L2PolicyTable(tables.DataTable):
46
-    name = tables.Column("name",
47
-            verbose_name=_("Name"),
48
-            link="horizon:project:network_policy:l2policy_details")
51
+    name = tables.Column(
52
+        "name",
53
+        verbose_name=_("Name"),
54
+        link="horizon:project:network_policy:l2policy_details"
55
+    )
49 56
     description = tables.Column("description", verbose_name=_("Description"))
50 57
     id = tables.Column("id", verbose_name=_("ID"))
51 58
     l3_policy_id = tables.Column(
@@ -74,7 +81,7 @@ class EditL3PolicyLink(tables.LinkAction):
74 81
 
75 82
     def get_link_url(self, l3policy):
76 83
         base_url = reverse("horizon:project:network_policy:update_l3policy",
77
-                kwargs={'l3policy_id': l3policy.id})
84
+                           kwargs={'l3policy_id': l3policy.id})
78 85
         return base_url
79 86
 
80 87
 
@@ -85,11 +92,16 @@ class DeleteL3PolicyLink(tables.DeleteAction):
85 92
     data_type_singular = _("L3 Policy")
86 93
     data_type_plural = _("L3 Policies")
87 94
 
95
+    def action(self, request, object_id):
96
+        client.l3policy_delete(request, object_id)
97
+
88 98
 
89 99
 class L3PolicyTable(tables.DataTable):
90
-    name = tables.Column("name",
91
-            verbose_name=_("Name"),
92
-            link="horizon:project:network_policy:l3policy_details")
100
+    name = tables.Column(
101
+        "name",
102
+        verbose_name=_("Name"),
103
+        link="horizon:project:network_policy:l3policy_details"
104
+    )
93 105
     description = tables.Column("description", verbose_name=_("Description"))
94 106
     id = tables.Column("id", verbose_name=_("ID"))
95 107
     ip_version = tables.Column("ip_version", verbose_name=_("IP Version"))
@@ -97,7 +109,7 @@ class L3PolicyTable(tables.DataTable):
97 109
     subnet_prefix_length = tables.Column(
98 110
         "subnet_prefix_length", verbose_name=_("Subnet Prefix Length"))
99 111
     external_segments = tables.Column("external_segments",
100
-        verbose_name=_("External Segment"))
112
+                                      verbose_name=_("External Segment"))
101 113
 
102 114
     class Meta(object):
103 115
         name = "l3policy_table"
@@ -131,13 +143,20 @@ class DeleteServicePolicyLink(tables.DeleteAction):
131 143
     data_type_singular = _("ServicePolicy")
132 144
     data_type_plural = _("ServicePolicies")
133 145
 
146
+    def action(self, request, object_id):
147
+        client.delete_networkservice_policy(request, object_id)
148
+
134 149
 
135 150
 class ServicePolicyTable(tables.DataTable):
136
-    name = tables.Column("name", verbose_name=_("Name"),
137
-            link="horizon:project:network_policy:service_policy_details")
151
+    name = tables.Column(
152
+        "name",
153
+        verbose_name=_("Name"),
154
+        link="horizon:project:network_policy:service_policy_details"
155
+    )
138 156
     description = tables.Column("description", verbose_name=_("Description"))
139 157
     network_service_params = tables.Column('network_service_params',
140
-                                    verbose_name=_("Network Service Params"))
158
+                                           verbose_name=_(
159
+                                               "Network Service Params"))
141 160
 
142 161
     class Meta(object):
143 162
         name = "service_policy_table"
@@ -161,8 +180,12 @@ class EditExternalConnectivityLink(tables.LinkAction):
161 180
     def get_link_url(self, external_connectivity):
162 181
         urlstring = \
163 182
             "horizon:project:network_policy:update_externalconnectivity"
164
-        base_url = reverse(urlstring,
165
-            kwargs={'external_connectivity_id': external_connectivity.id})
183
+        base_url = reverse(
184
+            urlstring,
185
+            kwargs={
186
+                'external_connectivity_id': external_connectivity.id
187
+            }
188
+        )
166 189
         return base_url
167 190
 
168 191
 
@@ -173,10 +196,16 @@ class DeleteExternalConnectivityLink(tables.DeleteAction):
173 196
     data_type_singular = _("ExternalConnectivity")
174 197
     data_type_plural = _("ExternalConnectivities")
175 198
 
199
+    def action(self, request, object_id):
200
+        client.delete_externalconnectivity(request, object_id)
201
+
176 202
 
177 203
 class ExternalConnectivityTable(tables.DataTable):
178
-    name = tables.Column("name", verbose_name=_("Name"),
179
-        link="horizon:project:network_policy:external_connectivity_details")
204
+    name = tables.Column(
205
+        "name",
206
+        verbose_name=_("Name"),
207
+        link="horizon:project:network_policy:external_connectivity_details"
208
+    )
180 209
     description = tables.Column("description", verbose_name=_("Description"))
181 210
     ip_version = tables.Column("ip_version", verbose_name=_("IP Version"))
182 211
     cidr = tables.Column("cidr", verbose_name=_("CIDR"))
@@ -185,9 +214,9 @@ class ExternalConnectivityTable(tables.DataTable):
185 214
         name = "external_connectivity_table"
186 215
         verbose_name = _("External Connectivity")
187 216
         table_actions = (CreateExternalConnectivityLink,
188
-            DeleteExternalConnectivityLink,)
217
+                         DeleteExternalConnectivityLink,)
189 218
         row_actions = (EditExternalConnectivityLink,
190
-            DeleteExternalConnectivityLink,)
219
+                       DeleteExternalConnectivityLink,)
191 220
 
192 221
 
193 222
 class CreateNATPoolLink(tables.LinkAction):
@@ -204,6 +233,9 @@ class DeleteNATPoolLink(tables.DeleteAction):
204 233
     data_type_singular = _("NAT Pool")
205 234
     data_type_plural = _("NAT Pools")
206 235
 
236
+    def action(self, request, object_id):
237
+        client.delete_natpool(request, object_id)
238
+
207 239
 
208 240
 class EditNATPoolLink(tables.LinkAction):
209 241
     name = "update_nat_pool"
@@ -214,13 +246,16 @@ class EditNATPoolLink(tables.LinkAction):
214 246
         urlstring = \
215 247
             "horizon:project:network_policy:update_natpool"
216 248
         base_url = reverse(urlstring,
217
-            kwargs={'nat_pool_id': nat_pool.id})
249
+                           kwargs={'nat_pool_id': nat_pool.id})
218 250
         return base_url
219 251
 
220 252
 
221 253
 class NATPoolTable(tables.DataTable):
222
-    name = tables.Column("name", verbose_name=_("Name"),
223
-        link="horizon:project:network_policy:nat_pool_details")
254
+    name = tables.Column(
255
+        "name",
256
+        verbose_name=_("Name"),
257
+        link="horizon:project:network_policy:nat_pool_details"
258
+    )
224 259
     description = tables.Column("description", verbose_name=_("Description"))
225 260
     ip_version = tables.Column("ip_version", verbose_name=_("IP Version"))
226 261
     cidr = tables.Column("ip_pool", verbose_name=_("IP Pool"))

+ 1
- 66
gbpui/panels/network_policy/views.py View File

@@ -9,15 +9,11 @@
9 9
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 10
 #    License for the specific language governing permissions and limitations
11 11
 #    under the License.
12
-
13
-import re
14
-
15 12
 from django.core.urlresolvers import reverse
16 13
 from django.utils.translation import ugettext_lazy as _
17 14
 
18 15
 from horizon import exceptions
19 16
 from horizon import forms
20
-from horizon import messages
21 17
 from horizon import tables
22 18
 from horizon import tabs
23 19
 
@@ -28,54 +24,10 @@ import tables as np_tables
28 24
 import tabs as np_tabs
29 25
 
30 26
 
31
-class IndexView(tabs.TabView):
27
+class IndexView(tabs.TabbedTableView):
32 28
     tab_group_class = (np_tabs.L3PolicyTabs)
33 29
     template_name = 'project/network_policy/details_tabs.html'
34 30
 
35
-    def post(self, request, *args, **kwargs):
36
-        obj_ids = request.POST.getlist('object_ids')
37
-        action = request.POST['action']
38
-        obj_type = re.search('delete([0-9a-z]+)', action).group(1)
39
-        if not obj_ids:
40
-            obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
41
-        if obj_type == 'spolicy':
42
-            for obj_id in obj_ids:
43
-                try:
44
-                    client.delete_networkservice_policy(request, obj_id)
45
-                    messages.success(request,
46
-                            _('Deleted service policy %s') % obj_id)
47
-                except Exception as e:
48
-                    msg = _('Unable to delete action. %s') % (str(e))
49
-                    exceptions.handle(request, msg)
50
-        if obj_type == 'l3policy':
51
-            for obj_id in obj_ids:
52
-                try:
53
-                    client.l3policy_delete(request, obj_id)
54
-                    messages.success(request,
55
-                            _('Deleted L3 policy %s') % obj_id)
56
-                except Exception as e:
57
-                    msg = _('Unable to delete action. %s') % (str(e))
58
-                    exceptions.handle(request, msg)
59
-        if obj_type == 'externalconnectivity':
60
-            for obj_id in obj_ids:
61
-                try:
62
-                    client.delete_externalconnectivity(request, obj_id)
63
-                    messages.success(request,
64
-                            _('Deleted External Connectivity %s') % obj_id)
65
-                except Exception as e:
66
-                    msg = _('Unable to delete action. %s') % (str(e))
67
-                    exceptions.handle(request, msg)
68
-        if obj_type == 'natpool':
69
-            for obj_id in obj_ids:
70
-                try:
71
-                    client.delete_natpool(request, obj_id)
72
-                    messages.success(request,
73
-                            _('Deleted NAT Pool %s') % obj_id)
74
-                except Exception as e:
75
-                    msg = _('Unable to delete action. %s') % (str(e))
76
-                    exceptions.handle(request, msg)
77
-        return self.get(request, *args, **kwargs)
78
-
79 31
 
80 32
 class AddL3policyView(forms.ModalFormView):
81 33
     form_class = np_forms.AddL3PolicyForm
@@ -106,23 +58,6 @@ class L3PolicyDetailsView(tables.MultiTableView):
106 58
     table_classes = (np_tables.L2PolicyTable,)
107 59
     template_name = 'project/network_policy/l3policy_details.html'
108 60
 
109
-    def post(self, request, *args, **kwargs):
110
-        obj_ids = request.POST.getlist('object_ids')
111
-        action = request.POST['action']
112
-        obj_type = re.search('delete([0-9a-z]+)', action).group(1)
113
-        if not obj_ids:
114
-            obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
115
-        if obj_type == 'l2policy':
116
-            for obj_id in obj_ids:
117
-                try:
118
-                    client.l2policy_delete(request, obj_id)
119
-                    messages.success(request,
120
-                            _('Deleted L2 policy %s') % obj_id)
121
-                except Exception as e:
122
-                    msg = _('Unable to delete action. %s') % (str(e))
123
-                    exceptions.handle(request, msg)
124
-        return self.get(request, *args, **kwargs)
125
-
126 61
     def get_l2policy_table_data(self):
127 62
         l2_policies = []
128 63
         try:

+ 44
- 25
gbpui/panels/network_services/tables.py View File

@@ -13,6 +13,7 @@
13 13
 from django.core.urlresolvers import reverse
14 14
 from django.utils.translation import ugettext_lazy as _
15 15
 
16
+from gbpui import client
16 17
 from horizon import tables
17 18
 
18 19
 
@@ -30,7 +31,7 @@ class EditServiceChainSpecLink(tables.LinkAction):
30 31
 
31 32
     def get_link_url(self, scspec):
32 33
         base_url = reverse("horizon:project:network_services:update_sc_spec",
33
-                kwargs={'scspec_id': scspec.id})
34
+                           kwargs={'scspec_id': scspec.id})
34 35
         return base_url
35 36
 
36 37
 
@@ -41,23 +42,27 @@ class DeleteServiceChainSpecLink(tables.DeleteAction):
41 42
     data_type_singular = _("Service Chain Spec")
42 43
     data_type_plural = _("Service Chain Specs")
43 44
 
45
+    def action(self, request, object_id):
46
+        client.delete_servicechain_spec(request, object_id)
47
+
44 48
 
45 49
 class ServiceChainSpecTable(tables.DataTable):
46
-    name = tables.Column("name",
47
-                     verbose_name=_("Name"),
48
-                     link="horizon:project:network_services:sc_spec_details")
50
+    name = tables.Column(
51
+        "name",
52
+        verbose_name=_("Name"),
53
+        link="horizon:project:network_services:sc_spec_details"
54
+    )
49 55
     description = tables.Column("description",
50 56
                                 verbose_name=_("Description"))
51 57
     nodes = tables.Column("nodes", verbose_name=_("Nodes"))
52
-    status = tables.Column("status", verbose_name=_("Status"))
53 58
 
54 59
     class Meta(object):
55 60
         name = "service_chain_spec_table"
56 61
         verbose_name = _("Service Chain Specs")
57 62
         table_actions = (CreateServiceChainSpecLink,
58
-                            DeleteServiceChainSpecLink,)
63
+                         DeleteServiceChainSpecLink,)
59 64
         row_actions = (EditServiceChainSpecLink,
60
-                        DeleteServiceChainSpecLink,)
65
+                       DeleteServiceChainSpecLink,)
61 66
 
62 67
 
63 68
 class CreateServiceChainNodeLink(tables.LinkAction):
@@ -74,7 +79,7 @@ class EditServiceChainNodeLink(tables.LinkAction):
74 79
 
75 80
     def get_link_url(self, scnode):
76 81
         base_url = reverse("horizon:project:network_services:update_sc_node",
77
-                kwargs={'scnode_id': scnode.id})
82
+                           kwargs={'scnode_id': scnode.id})
78 83
         return base_url
79 84
 
80 85
 
@@ -85,24 +90,28 @@ class DeleteServiceChainNodeLink(tables.DeleteAction):
85 90
     data_type_singular = _("Service Chain Node")
86 91
     data_type_plural = _("Service Chain Nodes")
87 92
 
93
+    def action(self, request, object_id):
94
+        client.delete_servicechain_node(request, object_id)
95
+
88 96
 
89 97
 class ServiceChainNodeTable(tables.DataTable):
90
-    name = tables.Column("name",
91
-                     verbose_name=_("Name"),
92
-                     link="horizon:project:network_services:sc_node_details")
98
+    name = tables.Column(
99
+        "name",
100
+        verbose_name=_("Name"),
101
+        link="horizon:project:network_services:sc_node_details"
102
+    )
93 103
     description = tables.Column("description",
94 104
                                 verbose_name=_("Description"))
95 105
     service_profile = tables.Column("service_profile",
96
-                                 verbose_name=_("Service Profile"))
97
-    status = tables.Column("status", verbose_name=_("Status"))
106
+                                    verbose_name=_("Service Profile"))
98 107
 
99 108
     class Meta(object):
100 109
         name = "service_chain_node_table"
101 110
         verbose_name = _("Service Chain Node")
102 111
         table_actions = (CreateServiceChainNodeLink,
103
-                DeleteServiceChainNodeLink,)
112
+                         DeleteServiceChainNodeLink,)
104 113
         row_actions = (EditServiceChainNodeLink,
105
-                DeleteServiceChainNodeLink,)
114
+                       DeleteServiceChainNodeLink,)
106 115
 
107 116
 
108 117
 class CreateServiceChainInstanceLink(tables.LinkAction):
@@ -130,11 +139,16 @@ class DeleteServiceChainInstanceLink(tables.DeleteAction):
130 139
     data_type_singular = _("ServiceChainInstance")
131 140
     data_type_plural = _("ServiceChainInstances")
132 141
 
142
+    def action(self, request, object_id):
143
+        client.delete_servicechain_instance(request, object_id)
144
+
133 145
 
134 146
 class ServiceChainInstanceTable(tables.DataTable):
135
-    name = tables.Column("name",
136
-            verbose_name=_("Name"),
137
-            link="horizon:project:network_services:sc_instance_details")
147
+    name = tables.Column(
148
+        "name",
149
+        verbose_name=_("Name"),
150
+        link="horizon:project:network_services:sc_instance_details"
151
+    )
138 152
     description = tables.Column("description",
139 153
                                 verbose_name=_("Description"))
140 154
     provider_ptg = tables.Column(
@@ -146,7 +160,6 @@ class ServiceChainInstanceTable(tables.DataTable):
146 160
     servicechain_spec = tables.Column(
147 161
         "servicechain_spec", verbose_name=_("Service Chain Spec"))
148 162
     classifier = tables.Column("classifier", verbose_name=_("Classifier"))
149
-    status = tables.Column("status", verbose_name=_("Status"))
150 163
 
151 164
     class Meta(object):
152 165
         name = "service_chain_instance_table"
@@ -167,21 +180,27 @@ class DeleteServiceProfileLink(tables.DeleteAction):
167 180
     data_type_singular = _("ServiceProfile")
168 181
     data_type_plural = _("ServiceProfiles")
169 182
 
183
+    def action(self, request, object_id):
184
+        client.delete_service_profile(request, object_id)
185
+
170 186
 
171 187
 class ServiceProfileTable(tables.DataTable):
172
-    name = tables.Column("name", verbose_name=_("Name"),
173
-        link="horizon:project:network_services:service_profile_details")
188
+    name = tables.Column(
189
+        "name",
190
+        verbose_name=_("Name"),
191
+        link="horizon:project:network_services:service_profile_details"
192
+    )
174 193
     description = tables.Column("description",
175
-        verbose_name=_("Description"))
194
+                                verbose_name=_("Description"))
176 195
     service_type = tables.Column("service_type",
177
-        verbose_name=_("Service Type"))
196
+                                 verbose_name=_("Service Type"))
178 197
     insertion_mode = tables.Column("insertion_mode",
179
-        verbose_name=_("Insertion Mode"))
198
+                                   verbose_name=_("Insertion Mode"))
180 199
     vendor = tables.Column("vendor", verbose_name=_("Vendor"))
181 200
 
182 201
     class Meta(object):
183 202
         name = "service_profile_table"
184 203
         verbose_name = _("Service Profile")
185 204
         table_actions = (CreateServiceProfileLink,
186
-                DeleteServiceProfileLink,)
205
+                         DeleteServiceProfileLink,)
187 206
         row_actions = (DeleteServiceProfileLink,)

+ 5
- 56
gbpui/panels/network_services/views.py View File

@@ -9,68 +9,17 @@
9 9
 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 10
 #    License for the specific language governing permissions and limitations
11 11
 #    under the License.
12
-import re
13
-
14
-from django.utils.translation import ugettext_lazy as _
15
-
16
-from horizon import exceptions
17 12
 from horizon import forms
18
-from horizon import messages
19 13
 from horizon import tabs
20 14
 
21 15
 import forms as ns_forms
22 16
 import tabs as ns_tabs
23 17
 
24
-from gbpui import client
25 18
 
26
-
27
-class IndexView(tabs.TabView):
19
+class IndexView(tabs.TabbedTableView):
28 20
     tab_group_class = (ns_tabs.ServiceChainTabs)
29 21
     template_name = 'project/network_services/details_tabs.html'
30 22
 
31
-    def post(self, request, *args, **kwargs):
32
-        obj_ids = request.POST.getlist('object_ids')
33
-        action = request.POST['action']
34
-        obj_type = re.search('delete([a-z]+)', action).group(1)
35
-        if not obj_ids:
36
-            obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
37
-        if obj_type == 'scnode':
38
-            for obj_id in obj_ids:
39
-                try:
40
-                    client.delete_servicechain_node(request, obj_id)
41
-                    messages.success(request, _('Deleted %s') % obj_id)
42
-                except Exception as e:
43
-                    exceptions.handle(request,
44
-                                      _('Unable to delete . %s') % e)
45
-        if obj_type == 'scinstance':
46
-            for obj_id in obj_ids:
47
-                try:
48
-                    client.delete_servicechain_instance(request, obj_id)
49
-                    messages.success(
50
-                        request, _('Deleted  %s') % obj_id)
51
-                except Exception as e:
52
-                    exceptions.handle(request,
53
-                                      _('Unable to delete . %s') % e)
54
-        if obj_type == 'scspec':
55
-            for obj_id in obj_ids:
56
-                try:
57
-                    client.delete_servicechain_spec(request, obj_id)
58
-                    messages.success(request,
59
-                                     _('Deleted %s') % obj_id)
60
-                except Exception as e:
61
-                    exceptions.handle(request,
62
-                                      _('Unable to delete . %s') % e)
63
-        if obj_type == 'serviceprofile':
64
-            for obj_id in obj_ids:
65
-                try:
66
-                    client.delete_service_profile(request, obj_id)
67
-                    messages.success(request,
68
-                                     _('Deleted %s') % obj_id)
69
-                except Exception as e:
70
-                    exceptions.handle(request,
71
-                                      _('Unable to delete . %s') % e)
72
-        return self.get(request, *args, **kwargs)
73
-
74 23
 
75 24
 class ServiceProfileDetailsView(tabs.TabView):
76 25
     tab_group_class = (ns_tabs.ServiceProfileDetailsTabGroup)
@@ -147,8 +96,8 @@ class ServiceChainSpecDetailsView(tabs.TabView):
147 96
 
148 97
 class CreateServiceChainInstanceView(forms.ModalFormView):
149 98
     form_class = ns_forms.CreateServiceChainInstanceForm
150
-    template_name = "project/network_services/"\
151
-        "create_service_chain_instance.html"
99
+    template_name = "project/network_services/" \
100
+                    "create_service_chain_instance.html"
152 101
 
153 102
     def get_context_data(self, **kwargs):
154 103
         context = super(
@@ -158,8 +107,8 @@ class CreateServiceChainInstanceView(forms.ModalFormView):
158 107
 
159 108
 class UpdateServiceChainInstanceView(forms.ModalFormView):
160 109
     form_class = ns_forms.UpdateServiceChainInstanceForm
161
-    template_name = "project/network_services/"\
162
-            "update_service_chain_instance.html"
110
+    template_name = "project/network_services/" \
111
+                    "update_service_chain_instance.html"
163 112
 
164 113
     def get_context_data(self, **kwargs):
165 114
         context = super(

+ 28
- 14
gbpui/panels/policytargets/tables.py View File

@@ -46,6 +46,9 @@ class DeletePTGLink(tables.DeleteAction):
46 46
     data_type_singular = _("Group")
47 47
     data_type_plural = _("Groups")
48 48
 
49
+    def action(self, request, object_id):
50
+        client.policy_target_delete(request, object_id)
51
+
49 52
 
50 53
 class AddPTGLink(tables.LinkAction):
51 54
     name = "addpolicy_target"
@@ -55,12 +58,14 @@ class AddPTGLink(tables.LinkAction):
55 58
 
56 59
 
57 60
 class PTGsTable(tables.DataTable):
58
-    name = tables.Column("name",
59
-                    verbose_name=_("Name"),
60
-                    link="horizon:project:policytargets:policy_targetdetails")
61
+    name = tables.Column(
62
+        "name",
63
+        verbose_name=_("Name"),
64
+        link="horizon:project:policytargets:policy_targetdetails"
65
+    )
61 66
     description = tables.Column("description", verbose_name=_("Description"))
62 67
     provided_policy_rule_sets = tables.Column("provided_policy_rule_sets",
63
-                                         sortable=False,
68
+                                              sortable=False,
64 69
                                          verbose_name=_("Provided Rule Sets"))
65 70
     consumed_policy_rule_sets = tables.Column("consumed_policy_rule_sets",
66 71
                                          sortable=False,
@@ -102,14 +107,19 @@ class DeleteExternalPTGLink(tables.DeleteAction):
102 107
     data_type_singular = _("Group")
103 108
     data_type_plural = _("Groups")
104 109
 
110
+    def action(self, request, object_id):
111
+        client.ext_policy_target_delete(request, object_id)
112
+
105 113
 
106 114
 class ExternalPTGsTable(tables.DataTable):
107
-    name = tables.Column("name",
108
-                verbose_name=_("Name"),
109
-                link="horizon:project:policytargets:ext_policy_targetdetails")
115
+    name = tables.Column(
116
+        "name",
117
+        verbose_name=_("Name"),
118
+        link="horizon:project:policytargets:ext_policy_targetdetails"
119
+    )
110 120
     description = tables.Column("description", verbose_name=_("Description"))
111 121
     provided_policy_rule_sets = tables.Column("provided_policy_rule_sets",
112
-                                         sortable=False,
122
+                                              sortable=False,
113 123
                                          verbose_name=_("Provided Rule Sets"))
114 124
     consumed_policy_rule_sets = tables.Column("consumed_policy_rule_sets",
115 125
                                          sortable=False,
@@ -231,9 +241,11 @@ class RemoveProvidedLink(tables.LinkAction):
231 241
 
232 242
 
233 243
 class ProvidedContractsTable(tables.DataTable):
234
-    name = tables.Column("name",
235
-             link="horizon:project:application_policy:policy_rule_set_details",
236
-             verbose_name=_("Name"))
244
+    name = tables.Column(
245
+        "name",
246
+        link="horizon:project:application_policy:policy_rule_set_details",
247
+        verbose_name=_("Name")
248
+    )
237 249
     description = tables.Column("description", verbose_name=_("Description"))
238 250
     policy_rules = tables.Column("policy_rules",
239 251
                                  sortable=False,
@@ -290,9 +302,11 @@ class RemoveConsumedLink(tables.LinkAction):
290 302
 
291 303
 
292 304
 class ConsumedContractsTable(tables.DataTable):
293
-    name = tables.Column("name",
294
-             link="horizon:project:application_policy:policy_rule_set_details",
295
-             verbose_name=_("Name"))
305
+    name = tables.Column(
306
+        "name",
307
+        link="horizon:project:application_policy:policy_rule_set_details",
308
+        verbose_name=_("Name")
309
+    )
296 310
     description = tables.Column("description",
297 311
                                 verbose_name=_("Description"))
298 312
     policy_rules = tables.Column("policy_rules",

+ 99
- 44
gbpui/panels/policytargets/views.py View File

@@ -11,15 +11,14 @@
11 11
 #    under the License.
12 12
 
13 13
 import json
14
-import re
15 14
 
15
+from django.core.urlresolvers import reverse
16 16
 from django.core.urlresolvers import reverse_lazy
17 17
 from django.http import HttpResponse  # noqa
18 18
 from django.utils.translation import ugettext_lazy as _
19 19
 
20 20
 from horizon import exceptions
21 21
 from horizon import forms
22
-from horizon import messages
23 22
 from horizon import tabs
24 23
 from horizon.utils import memoized
25 24
 from horizon import workflows
@@ -42,40 +41,14 @@ AddPTG = policy_target_workflows.AddPTG
42 41
 AddExternalPTG = policy_target_workflows.AddExternalPTG
43 42
 
44 43
 
45
-class IndexView(tabs.TabView):
44
+class IndexView(tabs.TabbedTableView):
46 45
     tab_group_class = (PTGTabs)
47 46
     template_name = 'project/policytargets/details_tabs.html'
48
-
49
-    def post(self, request, *args, **kwargs):
50
-        obj_ids = request.POST.getlist('object_ids')
51
-        action = request.POST['action']
52
-        obj_type = re.search('delete([a-z]+)', action).group(1)
53
-        if not obj_ids:
54
-            obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
55
-        if obj_type == 'policytarget':
56
-            for obj_id in obj_ids:
57
-                try:
58
-                    client.policy_target_delete(request, obj_id)
59
-                    messages.success(request,
60
-                                 _('Deleted Group %s') % obj_id)
61
-                except Exception as e:
62
-                    exceptions.handle(request,
63
-                                  _('Unable to delete Group. %s') % e)
64
-        if obj_type == 'externalpolicytarget':
65
-            for obj_id in obj_ids:
66
-                try:
67
-                    client.ext_policy_target_delete(request, obj_id)
68
-                    messages.success(request,
69
-                                 _('Deleted External Group %s') % obj_id)
70
-                except Exception as e:
71
-                    exceptions.handle(request,
72
-                                  _('Unable to delete External Group. %s') % e)
73
-        return self.get(request, *args, **kwargs)
47
+    page_title = _("Groups")
74 48
 
75 49
 
76 50
 class AddPTGView(workflows.WorkflowView):
77 51
     workflow_class = AddPTG
78
-    template_name = "project/policytargets/addpolicy_target.html"
79 52
 
80 53
 
81 54
 class AddExternalPTGView(workflows.WorkflowView):
@@ -85,6 +58,7 @@ class AddExternalPTGView(workflows.WorkflowView):
85 58
 class PTGDetailsView(tabs.TabbedTableView):
86 59
     tab_group_class = (policy_target_tabs.PTGMemberTabs)
87 60
     template_name = 'project/policytargets/group_details.html'
61
+    page_title = _("Group: {{ policy_target.name }}")
88 62
 
89 63
     def get_context_data(self, **kwargs):
90 64
         context = super(PTGDetailsView, self).get_context_data(**kwargs)
@@ -100,6 +74,7 @@ class PTGDetailsView(tabs.TabbedTableView):
100 74
 class ExternalPTGDetailsView(tabs.TabbedTableView):
101 75
     tab_group_class = (policy_target_tabs.ExternalPTGMemberTabs)
102 76
     template_name = 'project/policytargets/group_details.html'
77
+    page_title = _("Group: {{ policy_target.name }}")
103 78
 
104 79
     def get_context_data(self, **kwargs):
105 80
         context = super(ExternalPTGDetailsView, self).get_context_data(
@@ -126,16 +101,25 @@ class LaunchVMView(workflows.WorkflowView):
126 101
 
127 102
 class UpdatePTGView(forms.ModalFormView):
128 103
     form_class = policy_target_forms.UpdatePolicyTargetForm
129
-    template_name = "project/policytargets/update_policy_target.html"
104
+    form_id = "update_policy_target_form"
105
+    modal_header = _("Edit Group")
106
+    template_name = "gbpui/form_with_description.html"
130 107
     context_object_name = 'policy_target'
108
+    submit_label = _("Save Changes")
109
+    submit_url = "horizon:project:policytargets:updatepolicy_target"
131 110
     success_url = reverse_lazy("horizon:project:policytargets:index")
111
+    page_title = _("Edit Group")
112
+    help_text = _("You may update policy details here.")
132 113
 
133 114
     def get_context_data(self, **kwargs):
134 115
         context = super(UpdatePTGView, self).get_context_data(**kwargs)
135
-        context["policy_target_id"] = self.kwargs['policy_target_id']
116
+        obj_id = self.kwargs['policy_target_id']
117
+        context["policy_target_id"] = obj_id
136 118
         obj = self._get_object()
137 119
         if obj:
138 120
             context['name'] = obj.name
121
+        context["submit_url"] = reverse(self.submit_url, args=(obj_id,))
122
+        context["help_text"] = self.help_text
139 123
         return context
140 124
 
141 125
     @memoized.memoized_method
@@ -157,16 +141,25 @@ class UpdatePTGView(forms.ModalFormView):
157 141
 
158 142
 class UpdateExternalPTGView(forms.ModalFormView):
159 143
     form_class = policy_target_forms.UpdateExternalPolicyTargetForm
160
-    template_name = "project/policytargets/update_external_policy_target.html"
144
+    form_id = "update_policy_target_form"
145
+    modal_header = _("Edit Group")
146
+    template_name = "gbpui/form_with_description.html"
161 147
     context_object_name = 'external_policy_target'
148
+    submit_label = _("Save Changes")
149
+    submit_url = "horizon:project:policytargets:update_ext_policy_target"
162 150
     success_url = reverse_lazy("horizon:project:policytargets:index")
151
+    page_title = _("Edit Group")
152
+    help_text = _("You may update external policy details here.")
163 153
 
164 154
     def get_context_data(self, **kwargs):
165 155
         context = super(UpdateExternalPTGView, self).get_context_data(**kwargs)
166
-        context["ext_policy_target_id"] = self.kwargs['ext_policy_target_id']
156
+        obj_id = self.kwargs['ext_policy_target_id']
157
+        context["ext_policy_target_id"] = obj_id
167 158
         obj = self._get_object()
168 159
         if obj:
169 160
             context['name'] = obj.name
161
+        context["submit_url"] = reverse(self.submit_url, args=(obj_id,))
162
+        context["help_text"] = self.help_text
170 163
         return context
171 164
 
172 165
     @memoized.memoized_method
@@ -188,7 +181,15 @@ class UpdateExternalPTGView(forms.ModalFormView):
188 181
 
189 182
 class ExtAddProvidedPRSView(forms.ModalFormView):
190 183
     form_class = policy_target_forms.ExtAddProvidedPRSForm
191
-    template_name = "project/policytargets/ext_add_provided_prs.html"
184
+    form_id = "ext_add_provided_form"
185
+    modal_header = _("Add Provided PRS")
186
+    template_name = "gbpui/form_with_description.html"
187
+    submit_label = _("Save Changes")
188
+    submit_url = "horizon:project:policytargets:ext_add_provided_prs"
189
+    page_title = _("Add Provided PRS")
190
+    help_text = _(
191
+        "Add provided policy rule set. Press Ctrl to select multiple items."
192
+    )
192 193
 
193 194
     def get_context_data(self, **kwargs):
194 195
         context = super(ExtAddProvidedPRSView, self).get_context_data(**kwargs)
@@ -201,8 +202,15 @@ class ExtAddProvidedPRSView(forms.ModalFormView):
201 202
 
202 203
 class ExtRemoveProvidedPRSView(forms.ModalFormView):
203 204
     form_class = policy_target_forms.ExtRemoveProvidedPRSForm
204
-    template_name = \
205
-        "project/policytargets/ext_remove_provided_prs.html"
205
+    form_id = "ext_remove_provided_form"
206
+    modal_header = _("Remove Provided PRS")
207
+    template_name = "gbpui/form_with_description.html"
208
+    submit_label = _("Save Changes")
209
+    submit_url = "horizon:project:policytargets:ext_remove_provided_prs"
210
+    page_title = _("Remove Provided PRS")
211
+    help_text = _(
212
+        "Remove provided policy rule set. Press Ctrl to select multiple items."
213
+    )
206 214
 
207 215
     def get_context_data(self, **kwargs):
208 216
         context = super(ExtRemoveProvidedPRSView, self).get_context_data(
@@ -216,7 +224,15 @@ class ExtRemoveProvidedPRSView(forms.ModalFormView):
216 224
 
217 225
 class AddProvidedPRSView(forms.ModalFormView):
218 226
     form_class = policy_target_forms.AddProvidedPRSForm
219
-    template_name = "project/policytargets/add_provided_prs.html"
227
+    form_id = "add_provided_form"
228
+    modal_header = _("Add Provided PRS")
229
+    template_name = "gbpui/form_with_description.html"
230
+    submit_label = _("Save Changes")
231
+    submit_url = "horizon:project:policytargets:add_provided_prs"
232
+    page_title = _("Add Provided PRS")
233
+    help_text = _(
234
+        "Add provided policy rule set. Press Ctrl to select multiple items."
235
+    )
220 236
 
221 237
     def get_context_data(self, **kwargs):
222 238
         context = super(AddProvidedPRSView, self).get_context_data(**kwargs)
@@ -229,7 +245,15 @@ class AddProvidedPRSView(forms.ModalFormView):
229 245
 
230 246
 class RemoveProvidedPRSView(forms.ModalFormView):
231 247
     form_class = policy_target_forms.RemoveProvidedPRSForm
232
-    template_name = "project/policytargets/remove_provided_prs.html"
248
+    form_id = "remove_provided_form"
249
+    modal_header = _("Remove Provided PRS")
250
+    template_name = "gbpui/form_with_description.html"
251
+    submit_label = _("Save Changes")
252
+    submit_url = "horizon:project:policytargets:remove_provided_prs"
253
+    page_title = _("Remove Provided PRS")
254
+    help_text = _(
255
+        "Remove provided policy rule set. Press Ctrl to select multiple items."
256
+    )
233 257
 
234 258
     def get_context_data(self, **kwargs):
235 259
         context = super(RemoveProvidedPRSView, self).get_context_data(**kwargs)
@@ -242,7 +266,15 @@ class RemoveProvidedPRSView(forms.ModalFormView):
242 266
 
243 267
 class ExtAddConsumedPRSView(forms.ModalFormView):
244 268
     form_class = policy_target_forms.ExtAddConsumedPRSForm
245
-    template_name = "project/policytargets/ext_add_consumed_prs.html"
269
+    form_id = "ext_add_consumed_form"
270
+    modal_header = _("Add Policy Rule Set")
271
+    template_name = "gbpui/form_with_description.html"
272
+    submit_label = _("Save Changes")
273
+    submit_url = "horizon:project:policytargets:ext_add_consumed_prs"
274
+    page_title = _("Add Policy Rule Set")
275
+    help_text = _(
276
+        "Add consumed policy rule set. Press Ctrl to select multiple items."
277
+    )
246 278
 
247 279
     def get_context_data(self, **kwargs):
248 280
         context = super(ExtAddConsumedPRSView, self).get_context_data(**kwargs)
@@ -255,8 +287,15 @@ class ExtAddConsumedPRSView(forms.ModalFormView):
255 287
 
256 288
 class ExtRemoveConsumedPRSView(forms.ModalFormView):
257 289
     form_class = policy_target_forms.ExtRemoveConsumedPRSForm
258
-    template_name = \
259
-        "project/policytargets/ext_remove_consumed_prs.html"
290
+    form_id = "remove_contract_form"
291
+    modal_header = _("Remove Policy Rule Set")
292
+    template_name = "gbpui/form_with_description.html"
293
+    submit_label = _("Save Changes")
294
+    submit_url = "horizon:project:policytargets:ext_remove_consumed_prs"
295
+    page_title = _("Remove Policy Rule Set")
296
+    help_text = _(
297
+        "Remove consumed policy rule set. Press Ctrl to select multiple items."
298
+    )
260 299
 
261 300
     def get_context_data(self, **kwargs):
262 301
         context = super(ExtRemoveConsumedPRSView, self).get_context_data(
@@ -270,7 +309,15 @@ class ExtRemoveConsumedPRSView(forms.ModalFormView):
270 309
 
271 310
 class AddConsumedPRSView(forms.ModalFormView):
272 311
     form_class = policy_target_forms.AddConsumedPRSForm
273
-    template_name = "project/policytargets/add_consumed_prs.html"
312
+    form_id = "add_consumed_form"
313
+    modal_header = _("Add ")
314
+    template_name = "gbpui/form_with_description.html"
315
+    submit_label = _("Save Changes")
316
+    submit_url = "horizon:project:policytargets:add_consumed_prs"
317
+    page_title = _("Add ")
318
+    help_text = _(
319
+        "Add consumed policy rule set. Press Ctrl to select multiple items."
320
+    )
274 321
 
275 322
     def get_context_data(self, **kwargs):
276 323
         context = super(AddConsumedPRSView, self).get_context_data(**kwargs)
@@ -283,7 +330,15 @@ class AddConsumedPRSView(forms.ModalFormView):
283 330
 
284 331
 class RemoveConsumedPRSView(forms.ModalFormView):
285 332
     form_class = policy_target_forms.RemoveConsumedPRSForm
286
-    template_name = "project/policytargets/remove_consumed_prs.html"
333
+    form_id = "remove_contract_form"
334
+    modal_header = _("Remove Policy Rule Set")
335
+    template_name = "gbpui/form_with_description.html"
336
+    submit_label = _("Save Changes")
337
+    submit_url = "horizon:project:policytargets:remove_consumed_prs"
338
+    page_title = _("Remove Policy Rule Set")
339
+    help_text = _(
340
+        "Remove consumed policy rule set. Press Ctrl to select multiple items."
341
+    )
287 342
 
288 343
     def get_context_data(self, **kwargs):
289 344
         context = super(RemoveConsumedPRSView, self).get_context_data(**kwargs)

Loading…
Cancel
Save