Commit Graph

48 Commits

Author SHA1 Message Date
Akihiro Motoki cd7c1b5110 Address RemovedInDjango40Warning (2)
django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(),
ungettext(), and ungettext_lazy() are deprecated in favor of the
functions that they’re aliases for: django.utils.translation.gettext(),
gettext_lazy(), gettext_noop(), ngettext(), and ngettext_lazy().

https://docs.djangoproject.com/en/4.0/releases/3.0/#id3

Change-Id: I77878f84e9d10cf6a136dada81eabf4e18676250
2022-02-04 16:22:07 +09:00
Akihiro Motoki a9d5273f3c Address RemovedInDjango40Warning (1)
force_text() is deprecated in favor of force_str()
smart_text() is deprecated in favor of smart_str()

https://docs.djangoproject.com/en/4.0/releases/3.0/#django-utils-encoding-force-text-and-smart-text

Change-Id: Ic462fa8c3dfa26e8196df19fef5044036a9e97b4
2022-01-31 22:42:41 +09:00
shubhamdang cb8ff87090 Added a condition to check whether value is in present in choices for ThemableSelectWidget.
Sometimes value is populated with uuid of resources but that resource is not present in openstack,
So it is good to change initial_value with one of the values from choices.

Closes-Bug: #1928953
Change-Id: Ia33aaf7019d73f96c27e75ee24d80dcbf3e8ceb2
2021-05-19 15:11:21 +00:00
YuehuiLei 87f498bee5 Drop the usage of unicode prefix from unicode strings
All strings are considered as unicode strings in python 3,
so we no longer need "u" prefix (u'...').

Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
Change-Id: I796d2fcdca066475bbf29d25cbf2aa67b2b2178b
2021-02-12 13:05:27 -06:00
Akihiro Motoki e5d09edc20 Use python3-style super()
In python3, super() does not always require a class and self reference.
In other words, super() is enough for most cases.
This is much simpler and it is time to switch it to the newer style.

pylint provides a check for this.
Let's enable 'super-with-arguments' check.

NOTE: _prepare_mappings() method of FormRegion in
openstack_dashboard/test/integration_tests/regions/forms.py is refactored.
super() (without explicit class and self referece) does not work when
a subclass method calls a same method in a parent class multiple times.
It looks better to prepare a separate method to provide a common logic.

Change-Id: Id9512a14be9f20dbd5ebd63d446570c7b7c825ff
2020-10-15 14:37:20 +09:00
Akihiro Motoki 692778f8cf pylint: Address no-else-return warning
This pylint check 'no-else-return' might be debatable.
but as far as I checked it works in most cases.

Change-Id: Ie8574d4a529454c6e050fa62a7a17ea097d00240
2020-09-27 12:44:16 +09:00
Ivan Kolodyazhny 1fc70d7504 Remove python_2_unicode_compatible usage
Since we don't support Python 2 anymore, we don't need
to use python_2_unicode_compatible decorator.

Change-Id: I2aafc8d07ba95571b381ff65ba9e5c0044e2d959
2020-03-09 14:54:07 +02:00
Ivan Kolodyazhny e976461d85 Remove six usage from horizon package
We don't support Python 2 anymore so we don't need this
compatibility library.

six.reraise usages are left as is until it'll be moved to some
base lib like oslo.utils to not re-implenent this method in
Horizon.

This patch also removes Python2-specific base test case methods
assertItemsEqual and assertNotRegexpMatches in flavor of new
Python 3 analogues.

Change-Id: I0b567382edf4d68674a7b8d0b02333fb57293958
2020-01-15 12:36:11 +02:00
Stephen Finucane d2dc6fa665 django22: Add 'renderer' argument
As noted in the Django 2.1 release notes [1]:

  Support for Widget.render() methods without the renderer argument is
  removed.

Simply add the argument.

[1] https://docs.djangoproject.com/en/2.1/releases/2.1/#features-removed-in-2-1

Change-Id: I48ac79464cf10011c1b2d45556aea5b107f2fc7f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2019-08-27 11:19:25 +01:00
Yves-Gwenael Bourhis 9c30ca9c13 Preserve form field order in python 3
In python 3, the ExternalUploadMeta metaclass does not preserve the
order of the fields of the class it is modifying.
First we add a __prepare__() method which returns an empty
collections.OrderedDict.
That mapping records the methods and attributes of the class it is
metaclassing as they are defined within the body of the class statement.
Then we send a collections.OrderedDict to create the new class.

Change-Id: I7223ae5bd931202c95602ec9674ae86b4708368d
Closes-Bug: #1835724
2019-07-16 17:28:34 +02:00
BubaVV 8ccbd83577 Remove obsolete creation_counter field
creation_counter is never used in fields.py and was deprecated in
Django 2.x. Fields of object are keeped internally as ordered
dictionary, so we don't need any additional tools to manage it

Related Django bug:
https://code.djangoproject.com/ticket/23919#comment:95

Change-Id: I530a47ad8bfed6aef63d0a678a69fa09288f123e
2019-02-08 10:30:46 +00:00
Akihiro Motoki b06657b07d Fix gate failures by a new pycodestyle
pycodestyle 2.5.0 introduces E117 over-indented.
This commit fixes E117 errors.

pycodestyle 2.5.0 also drops pep8.py. As a result,
horizon/test/unit/hacking/test_checks.py starts to fail.
The equivalent elements are provided by pycodestyle.py,
so we can consume pycodestyle instead of pep8 module.

Change-Id: Ib103998f42ce7c901a10669b771a898783ca1a92
2019-01-30 17:02:20 +09:00
Akihiro Motoki 9518f7a5e7 pylint: fix unexpected-keyword-arg error
horizon/forms/fields.py:
ThemableCheckboxSelectMultiple.__init__ does not have
arguments "name" and "value". They were specified before somehow.

openstack_dashboard/dashboards/project/instances/forms.py:
messages.error() does not have "redirect" argument.
We need to redirect explicitly.

Change-Id: Ib51abf136fb49e3be65005c5f48715f004379178
2019-01-17 03:29:56 +09:00
Zuul d0a1a16415 Merge "pylint: fix unnecessary-pass warning" 2019-01-16 14:25:19 +00:00
Akihiro Motoki 4dd8e3d407 pylint: fix bad-mcs-classmethod-argument warning
Change-Id: Idfa421774ac23f673007fe7a7381c5199ccda5e0
2019-01-16 13:16:55 +09:00
Akihiro Motoki f6e1338cde pylint: fix unnecessary-pass warning
Change-Id: Ie2e5c6482a19553f6c73c50555d65834bb62ca9e
2019-01-16 13:10:16 +09:00
Akihiro Motoki e477eafa45 django2: Replace django.core.urlresolves with django.urls
(In Django 2.0) The django.core.urlresolvers module is removed
in favor of its new location, django.urls.
It was depreacted in Django 1.10:
https://docs.djangoproject.com/en/2.0/releases/1.10/#id3

blueprint django2-support
Change-Id: I46ab5c325491274b8eaffbf848e5d80f83c2fd26
2018-02-17 01:36:48 +09:00
peiy ef52e8e763 comment was wrongly declared
horizon/forms/fields.py def build_attrs
there is a string message non sense,
I think it was a comment.

Change-Id: I445fe96acd5c0dd3904dfc442f57a364e7c5bcde
Signed-off-by: peiy <peiy@rc.inesa.com>
2018-01-25 09:42:55 +08:00
Ivan Kolodyazhny c13d6da80e Add render method to ThemableCheckboxSelectMultiple
Django 1.11+ doesn't have RenderMixin class for widgets, so we have to
implement render method for ThemableCheckboxSelectMultiple to get it
rendered in a correct way with all supported Django versions until we
find a better solution for our widgets implementation.

Change-Id: I656afb162e130f2b77853368945b74330bedf747
Closes-Bug: #1715066
2017-10-12 04:39:27 +00:00
Luigi Toscano 5b53b8c17d Pass renderer to SelectWidget.render()
Required for Django 1.11 compatibility. Apparently
DynamicSelectWidget.render() receives it (through kwargs) and
tries to pass the parameter to its parent's method, but then
it fails (leading to exceptions in the rendering).

Closes-Bug: #1707660
Change-Id: I25e294a1c2f721a2f57dd50acb4c5e408b6187f9
2017-07-31 16:50:17 +02:00
adrian-turjak 52150749a6 Fixes to allow us to use Django 1.11
Mostly the issue with Horizon was we were using some
undocumented widgets that were cut for version 1.11
django. This patch adds their code into our repo for
now, but we need to do a proper rewrite of our widgets
for Queens to use current widgets in Django.

Also edits some tests because the functionality changed
in Django 1.11

Implements: blueprint dj111
Co-Authored-By: Rob Cresswell <robert.cresswell@outlook.com>
Change-Id: I444d45f274662f4f33701c16cce4ae80cb546654
2017-07-20 01:08:56 +12:00
Akihiro Motoki 0c836454b2 Switch render() arguments to the new way
Previously template.render() takes Context or RequestContext object
but after Django 1.8 the method takes a dict and request as separate
arguments. The old way will be dropped in Django 1.10.
This commit update the usage based on the Django 1.8 release notes [1].

commit 95d78a140f addresses this
deprecations but it turns out all similar places are not switched.
I searched the code base more carefully and found more.
I hope this clean up all of them.

After this change, extra_context which was passed to (Request)Context
previously is no longer available in HttpResponse object.
Volume unit test is tightly coupled with the context information
and checks rendered actions using the context. Thus the corresponding
tests no longer work. Since we can use only HttpResponse.content
(which is a rendered HTML), the new tests just check various strings
like ID, link and label of a specific action.
This is tricky, but this is now the only thing we can do.

[1] https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/#get-template-and-select-template

Change-Id: I350c22dc3d7db7b93ca4b823dac1e3d88beef1a7
2017-06-21 19:32:03 +00:00
Akihiro Motoki 95629a337e Fix H405 (multi line docstring) warnings (horizon)
H405: multi line docstring summary not separated with an empty line

Partial-Bug: #1696996
Change-Id: I58f71206def1a25f3eda04b9297f1aa7d3caa646
2017-06-09 16:04:57 +00:00
Bence Romsics 9853a2edaa New input field with validation: MACAddressField
Plus refactor Allowed Address Pairs form to use it.

The new input field is introduced because a follow-up patch wants to use
MAC address input fields at multiple places and this seems more reusable
than a CharField with regex validation. This is also a bit more generic,
because it accepts multiple MAC address formats (all formats supported
by netaddr). Then normalize the MAC address to the most usual format.

Change-Id: Ie2cbfdfbfb46a50d71d325e42f7d614710c6df3b
Partially-Implements: blueprint neutron-trunk-ui
2017-03-22 18:57:30 +09:00
Akihiro Motoki 61091388e9 hacking: noqa cleanup in horizon
attribute-level imports are not checked by hacking module now.
most noqa is used to disable warnings on attribute-level imports.
This commit drops noqa for this purpose.

After this, there are 8 noqa under horizon/ :)

In addition to this, the following changes are made.

horizon/exceptions.py: The following imports are dropped.
They are not used anywhere.
  from django.http import HttpRequest
  from django.views.debug import CLEANSED_SUBSTITUTE

horizon/forms/__init__.py:
Some entries were missing in __all__. They are added.

Change-Id: I33b504ef6c396f0675e8a340867e2ca59c77c684
2017-03-17 19:38:47 +00:00
Shu Yingya 870c9b7460 Remove unused import
This package imports but never used.

Change-Id: I7c9ce4e236eb3ab75867ec20b2a5ad8d7a0fc5be
2017-01-03 05:58:10 +00:00
jolie 796625863d Replaces uuid.uuid4 with uuidutils.generate_uuid()
Change-Id: I72e502a07d971de7e5c85519c80c4d054863eabe
Closes-Bug: #1082248
2016-11-08 18:19:34 +08:00
Timur Sufiev 93af461e40 [Django] Allow to upload the image directly to Glance service
Since large Glance images even temporarily stored on dashboard side
tend to fill up Web Server filesystem, it is desirable to route image
payload directly to Glance service (which usually streams it to
storage backend, which in turn has plenty of space).

To make it possible we need to trick Django into thinking that a file
was selected inside FileInput, while its contents are not actually
transferred to Django server. Then, once image is created client-side
code needs to know the exact url the image payload needs to be
transferred to. Both tasks are solved via using ExternalFileField /
ExternalUploadMeta classes which allow to work around the usual Django
form processing workflow with minimal changes to CreateImage form
business logic.

The client-side code relies on CORS being enabled for Glance service
(otherwise browser would forbid the PUT request to a location
different from the one form content came from). In a Devstack setup
you'll need to edit [cors] section of glance-api.conf file, setting
`allowed_origin` setting to the full hostname of the web server (say,
http://<HOST_IP>/dashboard) and restart glance-api process.

A progress bar is implemented to track the progress of a file upload,
in case a really huge image is transferred.

The new machinery could be easily switched on/off with a single
setting `HORIZON_IMAGES_UPLOAD_MODE` set to 'direct' / 'legacy'.

Related-Bug: #1467890
Closes-Bug: #1403129
Implements blueprint: horizon-glance-large-image-upload
Change-Id: I01d02f75268186b43066df6fd966aa01c08e01d7
2016-08-16 14:30:38 +03:00
Diana Whitten 01720bd43c Horizon selects are now themable: DynamicTypedChoiceField
The DynamicTypedChoiceField is now a themable select. Floating
ips have been updated to use it.

Change-Id: I41e25f86cb0eaa6d0aadd18a5dc953b047c1581d
Partially-implements: blueprint horizon-theme-css-reorg
2016-08-03 15:58:54 -07:00
Diana Whitten 2b67ae681b Horizon selects are now themable: Launch Instance
Horizon was using a standard select input.  Unfortunately, this type
of input is only customizable to a small extent.

Co-Authored-By: Ryan Peters <rjpeter2@gmail.com>
Co-Authored-By: Matthew Wood <woodm1979@gmail.com>
Co-Authored-By: Brian Tully <brian.tully@hp.com>

Change-Id: Iaf8427c3fff6d2fbfae944731fd9f6f754ed7c31
Partially-implements: blueprint horizon-theme-css-reorg
2016-06-08 18:25:23 +00:00
Diana Whitten 20c17d28d3 Horizon selects are now themable: Volumes
Horizon was using a standard select input.  Unfortunately, this
type of input is only customizable to a small extent.

I/We have created a new input type for forms to use that is a bootstrap
dropdown.  This will allow bootstrap themes to affect selects the same
way they do for check boxes and radio buttons and the like.

Material's inputs are a bit special, so custom css was added to keep
style parity with Bootswatch's Paper.

co-authored-by: brian.tully@hp.com
co-authored-by: hurgleburgler@gmail.com

ThemableSelect widget template has been modified so that shadow select
element does not contain any classes (which are usually used for
customizing appearance - since it's hidden, it doesn't need
that). Given that we could match legacy select element as 'div >
select.form-control' with no possibility that SelectFormFieldRegion
(legacy select widget region) will bind a hidden part of
ThemableSelect widget and intercept all commands send to
ThemableSelectFormFieldRegion. ThemableSelectFormFieldRegion was
modified to still use legacy widget wrapper for getting 'name' and
'value' properties, while doing all other things on its own, not using
Selenium wrapper for <select>.

Co-Authored-By: Timur Sufiev <tsufiev@mirantis.com>

Change-Id: Ie921b3adc2e1d3388d3c2aa1f76afe3af6ceb87b
Partially-implements: blueprint horizon-theme-css-reorg
2016-06-01 09:32:28 -07:00
Diana Whitten 259973dd06 Horizon Checkboxes are now themeable.
Horizon checkboxes were using a standard checkbox. Unfortunately,
this type of checkbox is only customizable through Chrome, and
even then, its not completely flexible.

The default checkboxes have now been altered to allow for a highly
customized experience through the use of CSS pseudo elements and
Icon Fonts. This allows the color, size and unselected and selected
states of the checkbox to be customized.

The 'default' theme uses the standard Font Awesome checked and
unchecked icons.  The 'material' now uses the Material Design
checkbox design.

It was also noticed (and fixed) that the help-icon on the forms
were not the same color as its corresponding text.

Partially-Implements: blueprint horizon-theme-css-reorg

Change-Id: I52602357d831a5e978fe6916b37b0cde9edb2b9b
2016-03-02 19:17:09 -07:00
Rob Cresswell f2b2289b4a Drop Django 1.7 support
Django 1.7 support ends in December 2015
(https://www.djangoproject.com/download/#supported-versions), so it
will not be supported by Mitaka release.

This patch removes many of the deprecation warnings:-

`RedirectView.permanent` change:
https://docs.djangoproject.com/en/1.8/ref/class-based-views/base/

`url` change:
https://docs.djangoproject.com/en/1.8/internals/deprecation/
See version 1.5 notes for the url and ssi template tag change

`django.forms.utils` change:
https://docs.djangoproject.com/en/1.8/internals/deprecation/
See version 1.9 notes

`firstof` change:
https://docs.djangoproject.com/en/1.8/internals/deprecation/
See version 1.8 notes for cycle and firstof template tags

Change-Id: If546c087e73d189daa92e5bd63f0533fcf19089f
Partially-Implements: blueprint drop-dj17
2015-11-16 11:55:38 +00:00
Victor Stinner 27e3f6c537 py3: Replace basestring with six.string_types
Patch generated by the command:

  sixer.py basestring horizon/ openstack_dashboard/ tools/

Partial-Implements: blueprint porting-python3
Change-Id: I6fd251243a058457f69907eb1111f559a224e1cb
2015-08-19 17:18:32 -07:00
David Lyle efafd2ba96 Fixing docstring formatting errors and warnings
Correcting numerous errors and warnings for doc generation.

Partial-Bug: #1486222
Change-Id: I6d6b20a433aa9965a1bafbd098e64b19886e5fca
2015-08-18 17:14:22 -06:00
Akihiro Motoki 5dfca25190 Fix E128 errors in horizon/
E128 continuation line under-indented for visual indent

Partial-Bug: #1375929
Change-Id: If4cc09995a74b68a6b037ea8999cebe09c750e65
2014-10-15 13:50:07 +09:00
Akihiro Motoki c228358258 Fix E127 errors in horizon/
E127 continuation line over-indented for visual indent

Partial-Bug: #1375931
Change-Id: Ib9ae85a767a85a360e5a720d8392a20069a8c873
2014-10-01 19:49:41 +09:00
Cindy Lu 7dc3c56628 Add additional attributes to choices in ChoiceField
This feature enables user to customize choices in a  drop down
list of a form by adding additional properties to the 'choices'
attribute of ChoiceField class.
Currently, the ChoiceField class has an attribute choices which
takes a list of 2 element tuple by default.
    self.field[<field name>].choices = ([
                                   (option_value1, option_label1),
                                   (option_value2, option_label2)
                                       ])
With this implementation,users can specify an additional transform
function in the forms.fields.SelectWidget class called
transform_html_attrs. Given the option label for a given choice,
transform_html_attrs will return a dictionary containing the html
attributes and their values

Implements: blueprint add-attributes-to-form-field-choices
Change-Id: I8ba997c58b485a33676cf9f350be00a1f365256f
2014-09-22 19:29:03 +00:00
Felipe Reyes af49cf1f15 Replace force_unicode with force_text
Django changed the name to force_unicode and it's only available in
python2 as an alias of force_text. The new name is available since
Django 1.4.2

Closes-Bug: #1345642
Change-Id: Ida8c545ceec7c31999f2497d540a0dc5a653d286
2014-08-06 14:34:53 +02:00
woodm1979 28e5874eb7 Cleaned up dict.update(single elem dict) code
There's several places in the code where this type of thing exists:
    form_data.update({'vpnservice_id': vpnservice.id})
better would be this:
    form_data['vpnservice_id'] = vpnservice.id
This type of thing bothers me, so I'm going to clean it up.

Also fixed the two cases of:
    if <some_string>.find(<some_other_string>) != -1:
which should clearly use the "in" operator instead.

Change-Id: Ic72a5b0a17c211f3949edc69732c1101c24590ec
Closes-Bug: 1339849
2014-07-14 09:05:51 -06:00
He Yongli e790ac070e Remove extraneous vim configuration comments
Remove vim setting:
comment - # vim: tabstop=4 shiftwidth=4 softtabstop=4

at the top of source code files, except for files in
openstack/common.

Change-Id: I9a5c6b17c6ef7ecec601f4503dfc7b31fc72e90a
Close-bug: #1229324
2014-05-06 15:30:10 +08:00
Jenkins 4c1775f27d Merge "Fix DynamicSelectWidget.get_add_item_url() method." 2014-04-18 22:43:15 +00:00
Timur Sufiev 88c0436fa1 Fix DynamicSelectWidget.get_add_item_url() method.
Do not wrap self.add_item_link_args in an additional list because it
makes impossible to pass more than one arg (i.e. tuple or list of
args) to url resolver.

Change-Id: Idf6d5d1f27c9176f1de93a475e0f1abbae5ee275
Closes-Bug: #1297317
2014-04-07 18:07:42 +04:00
Maxime Vidori cbb52ebc66 Group specific fields in horizon.form module
According to the Django architecture, all fields are grouped in
the django.form module, Horizon fields were dispatched in two modules
utils and form. This patch cleanup the loading of Horizon specific
fields.

Change-Id: Ib18848a8cc06dbd5984ec02d7cd647145124ced4
Closes-Bug: #1287634
2014-03-04 11:13:59 +01:00
Paul Belanger da8c69afa6 Gate on H4xx docstrings for pep8
In an effort to help horizon more friendly to OpenStack hacking
guidelines, we now gate on H40* violations.

Change-Id: Id07294543660368d2f7f5ac363710176ab23b874
Signed-off-by: Paul Belanger <paul.belanger@polybeacon.com>
2013-11-23 12:51:07 -05:00
Matthias Runge cea720e793 Sort imports alphabetically
This patch also re-organizes imports to import one per line.

Change-Id: Ia958e3a30a48d4308d08d51df243c1272425c316
Fixes: bug 1188529
Fixes: bug 1188537
2013-06-14 12:05:55 +02:00
Kelsey Tripp e1635b695d project workflow: project membership UI
* Update Project workflow now includes a tab to update project members
* Can add/remove existing users from project and update roles
* Can add a new user via inline object creation
* Can filter both lists!
* Changed css/jquery to make things appear more like other tables
* Fixed a few JS bugs
* "Fixed" exception handling for now, although it naively redirects the
   user out of the workflow

partially implements blueprint tenant-creation-workflow

Change-Id: I38589bf3ee4c33c49df982417d995c141f4e6709
2012-08-08 17:09:12 -07:00
Gabriel Hurley df5a13c5ec Inline object creation.
Allows the creation of related objects during a workflow.
For example, this patch implements importing keypairs during
the launch instance workflow and allocating floating IP
addresses during the floating IP associate workflow.

This required several significant changes:

  * SelfHandlingForm should no long return a redirect.
    Instead, it should return either the object it
    created/acted on, or else a boolean such as True.

  * The ModalFormView now differentiates between GET
    and POST.

  * Due to the previous two items, SelfHandlingForm
    was mostly gutted (no more maybe_handle, etc.).

  * Modals now operate via a "stack" where only the
    top modal is visible at any given time and closing
    one causes the next one to become visible.

In the process of these large changes there was a large
amount of general code cleanup, especially in the javascript
code and the existing SelfHandlingForm subclasses/ModalFormView
subclasses. Many small bugs were fixed along with the cleanup.

Implements blueprint inline-object-creation.

Fixes bug 994677.
Fixes bug 1025977.
Fixes bug 1027342.
Fixes bug 1025919.

Change-Id: I1808b34cbf6f813eaedf767a6364e815c0c5e969
2012-07-22 17:07:27 -07:00