Files
masakari-dashboard/masakaridashboard/hosts/forms.py
Vadym Markov eb4d103c3f Django 4.x: fix some import error
* ugettext_lazy is removed

In Django 3.0 ugettext_lazy/ungettext_lazy have been deprecated in favor
of gettext_lazy/ngettext_lazy [0].

* urlunquote is removed

In Django 3.0 django.utils.http.urlquote/urlquote_plus/urlunquote/urlunquote
have been deprecated in favor of the functions that they're aliases for:
urllib.parse.quote/quote_plus/unquote/unquote_plus [0].

We are now using Django 4.2, so we should update our code
with the gettext_lazy/ngettext_lazy aliases.

[0] https://docs.djangoproject.com/en/3.0/releases/3.0/#id3

Change-Id: I2fe090fe170dd832deb9cf454a0400303d2e3d92
2024-01-24 15:06:50 +08:00

72 lines
2.6 KiB
Python

# Copyright (c) 2018 NTT DATA
#
# 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.
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import messages
from masakaridashboard.api import api
class UpdateHostForm(forms.SelfHandlingForm):
uuid = forms.CharField(widget=forms.HiddenInput())
failover_segment_id = forms.CharField(widget=forms.HiddenInput())
name = forms.CharField(
label=_('Host Name'),
widget=forms.TextInput(attrs={'readonly': 'readonly'}))
reserved = forms.ChoiceField(
label=_('Reserved'),
choices=[('False', 'False'),
('True', 'True')],
widget=forms.Select(
attrs={'class': 'switchable',
'data-slug': 'available host'}),
required=False)
type = forms.CharField(
label=_('Type'),
widget=forms.TextInput(attrs={'maxlength': 255}))
control_attributes = forms.CharField(
label=_('Control Attribute'),
widget=forms.TextInput())
on_maintenance = forms.ChoiceField(
label=_('On Maintenance'),
choices=[('False', 'False'),
('True', 'True')],
widget=forms.Select(
attrs={'class': 'switchable',
'data-slug': 'available host'}),
required=False
)
def handle(self, request, data):
try:
attrs = {'name': data['name'],
'reserved': data['reserved'],
'type': data['type'],
'control_attributes': data['control_attributes'],
'on_maintenance': data['on_maintenance']}
api.update_host(request, data['uuid'],
data["failover_segment_id"], attrs)
msg = _('Successfully updated host.')
messages.success(request, msg)
except Exception:
msg = _('Failed to update host.')
redirect = reverse('horizon:masakaridashboard:hosts:index')
exceptions.handle(request, msg, redirect=redirect)
return True