| 1 |
# Copyright 2014 Intel Corporation |
| 2 |
# All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
from django.urls import reverse |
| 17 |
from django.utils.translation import gettext_lazy as _ |
| 18 |
from horizon import exceptions |
| 19 |
from horizon import tabs |
| 20 |
|
| 21 |
from blazar_dashboard.api import client |
| 22 |
|
| 23 |
RESERVATION_GENERALS = ( |
| 24 |
'id', |
| 25 |
'lease_id', |
| 26 |
'resource_id', |
| 27 |
'resource_type', |
| 28 |
'status', |
| 29 |
'missing_resources', |
| 30 |
'resources_changed', |
| 31 |
'created_at', |
| 32 |
'updated_at' |
| 33 |
) |
| 34 |
|
| 35 |
|
| 36 |
class OverviewTab(tabs.Tab): |
| 37 |
name = _("Overview") |
| 38 |
slug = "overview" |
| 39 |
template_name = "project/leases/_detail_overview.html" |
| 40 |
|
| 41 |
def get_context_data(self, request): |
| 42 |
lease_id = self.tab_group.kwargs['lease_id'] |
| 43 |
try: |
| 44 |
lease = client.lease_get(self.request, lease_id) |
| 45 |
except Exception: |
| 46 |
redirect = reverse('horizon:project:leases:index') |
| 47 |
msg = _('Unable to retrieve lease details.') |
| 48 |
exceptions.handle(request, msg, redirect=redirect) |
| 49 |
|
| 50 |
return {'lease': lease, |
| 51 |
'reservation_generals': RESERVATION_GENERALS} |
| 52 |
|
| 53 |
|
| 54 |
class LeaseDetailTabs(tabs.TabGroup): |
| 55 |
slug = "lease_details" |
| 56 |
tabs = (OverviewTab,) |