bug fixing
This commit is contained in:
parent
9019084cca
commit
a07a67419f
4 changed files with 23 additions and 10 deletions
|
@ -11,7 +11,7 @@ from openstack_dashboard.dashboards.yuyu.core.pricing_admin.forms import BasePri
|
|||
|
||||
|
||||
class FlavorPriceForm(BasePriceForm):
|
||||
flavor = forms.ThemableChoiceField(label=_("Flavor"))
|
||||
flavor = forms.ThemableChoiceField(label=_("Flavor"), required=True)
|
||||
|
||||
USE_CASE = FlavorPriceUseCase()
|
||||
NAME = "Flavor Price"
|
||||
|
@ -29,7 +29,7 @@ class FlavorPriceForm(BasePriceForm):
|
|||
|
||||
|
||||
class VolumePriceForm(BasePriceForm):
|
||||
volume_type = forms.ThemableChoiceField(label=_("Volume Type"))
|
||||
volume_type = forms.ThemableChoiceField(label=_("Volume Type"), required=True)
|
||||
|
||||
USE_CASE = VolumePriceUseCase()
|
||||
NAME = "Volume Price"
|
||||
|
@ -60,6 +60,7 @@ class SnapshotPriceForm(BasePriceForm):
|
|||
USE_CASE = SnapshotPriceUseCase()
|
||||
NAME = "Snapshot Price"
|
||||
|
||||
|
||||
class ImagePriceForm(BasePriceForm):
|
||||
USE_CASE = ImagePriceUseCase()
|
||||
NAME = "Image Price"
|
||||
|
|
|
@ -59,7 +59,7 @@ class FlavorPriceAddFormView(forms.ModalFormView):
|
|||
added_ids = []
|
||||
flavors = []
|
||||
try:
|
||||
added_ids = map(lambda x: x['flavor_id'], self.flavor_price_uc.list(self.request))
|
||||
added_ids = list(map(lambda x: x['flavor_id'], self.flavor_price_uc.list(self.request)))
|
||||
flavors = api.nova.flavor_list(self.request)
|
||||
except neutron_exc.ConnectionFailed:
|
||||
exceptions.handle(self.request)
|
||||
|
@ -73,7 +73,7 @@ class FlavorPriceAddFormView(forms.ModalFormView):
|
|||
flavor_list.append((flavor.id, flavor.name))
|
||||
|
||||
if not flavor_list:
|
||||
flavor_list = [(None, _("No flavors available"))]
|
||||
flavor_list = [('', _("No flavors available"))]
|
||||
return {'flavor_list': flavor_list}
|
||||
|
||||
|
||||
|
@ -131,7 +131,7 @@ class VolumePriceAddFormView(forms.ModalFormView):
|
|||
added_ids = []
|
||||
volumes = []
|
||||
try:
|
||||
added_ids = map(lambda x: x['volume_type_id'], self.volume_price_uc.list(self.request))
|
||||
added_ids = list(map(lambda x: x['volume_type_id'], self.volume_price_uc.list(self.request)))
|
||||
volumes = api.cinder.volume_type_list(self.request)
|
||||
except neutron_exc.ConnectionFailed:
|
||||
exceptions.handle(self.request)
|
||||
|
@ -145,7 +145,7 @@ class VolumePriceAddFormView(forms.ModalFormView):
|
|||
volume_list.append((d.id, d.name))
|
||||
|
||||
if not volume_list:
|
||||
volume_list = [(None, _("No volume type available"))]
|
||||
volume_list = [('', _("No volume type available"))]
|
||||
return {'volume_type_list': volume_list}
|
||||
|
||||
|
||||
|
|
|
@ -115,12 +115,24 @@ class UsageCostView(tables.MultiTableView):
|
|||
context['invoice'] = self.request.invoice
|
||||
return context
|
||||
|
||||
def _get_flavor_name(self, flavor_id):
|
||||
try:
|
||||
return api.nova.flavor_get(self.request, flavor_id).name
|
||||
except Exception:
|
||||
return 'Invalid Flavor'
|
||||
|
||||
def _get_volume_name(self, volume_type_id):
|
||||
try:
|
||||
return api.cinder.volume_type_get(self.request, volume_type_id).name
|
||||
except Exception:
|
||||
return 'Invalid Volume'
|
||||
|
||||
def get_instance_cost_data(self):
|
||||
try:
|
||||
datas = map(lambda x: {
|
||||
"id": x['id'],
|
||||
"name": x['name'],
|
||||
"flavor": api.nova.flavor_get(self.request, x['flavor_id']).name,
|
||||
"flavor": self._get_flavor_name(x['flavor_id']),
|
||||
"usage": timesince(
|
||||
dateutil.parser.isoparse(x['start_date']),
|
||||
dateutil.parser.isoparse(x['adjusted_end_date'])
|
||||
|
@ -144,7 +156,7 @@ class UsageCostView(tables.MultiTableView):
|
|||
dateutil.parser.isoparse(x['start_date']),
|
||||
dateutil.parser.isoparse(x['adjusted_end_date'])
|
||||
),
|
||||
'type': api.cinder.volume_type_get(self.request, x['volume_type_id']).name,
|
||||
'type': self._get_volume_name(x['volume_type_id']),
|
||||
'size': x['space_allocation_gb'],
|
||||
"cost": Money(amount=x['price_charged'], currency=x['price_charged_currency'])
|
||||
}, self.request.invoice.get('volumes', []))
|
||||
|
|
|
@ -8,8 +8,8 @@ from horizon import messages
|
|||
|
||||
|
||||
class BasePriceForm(forms.SelfHandlingForm):
|
||||
hourly_price = MoneyField(label=_("Hourly Price"))
|
||||
monthly_price = MoneyField(label=_("Monthly Price"), required=False)
|
||||
hourly_price = MoneyField(label=_("Hourly Price"), min_value=0, max_digits=10)
|
||||
monthly_price = MoneyField(label=_("Monthly Price"), min_value=0, max_digits=10, required=False)
|
||||
|
||||
USE_CASE: PricingUseCase = None
|
||||
NAME = ""
|
||||
|
|
Loading…
Add table
Reference in a new issue