Commit Graph

197 Commits

Author SHA1 Message Date
Akihiro Motoki 7052b7f065 Address RemovedInDjango40Warning (7)
HttpRequest.is_ajax() was marked as deprecated since Django 3.1 and will be
removed in Django 4.0 [1].

While the current implementation of is_ajax() relies on a jQuery-specific way
of signifying AJAX as noted in the Django relnotes, horizon works with this.
Thus this commit copies the existing logic of HttpRequest.is_ajax() to the
horizon repo (as horizon.utils.http.is_ajax()) and consumes it.

https: //docs.djangoproject.com/en/4.0/releases/3.1/#features-deprecated-in-3-1
Change-Id: I3def53033524985818a891a1b9d4659fad4ba2ba
2022-02-04 16:27:32 +09:00
Akihiro Motoki e4444e6979 Address RemovedInDjango40Warning (4)
In Django 3.0, django.utils.http.urlquote(), urlquote_plus(),
urlunquote(), and urlunquote_plus() are deprecated in favor of
the functions that they’re aliases for: urllib.parse.quote(),
quote_plus(), unquote(), and unquote_plus().

https: //docs.djangoproject.com/en/4.0/releases/3.0/
Change-Id: I37fcd917cbf87b4d3141cfbdd2675aa38f33f2a4
2022-02-04 16:27:18 +09:00
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
Akihiro Motoki 7d894e44eb Support Django 3.2 support (3)
In Django 3.2, assertQuerysetEqual started to compare querystes directly.
As the migration check it checks the first element of the compared items
have a same type. "values()" method of OrderedDict does not return an object
which allows the index access in Python3, so this change breaks our UT.
We need to ensure to pass a list to assertQuerysetEqual.
The commit changes the related codes to ensure a list for such cases.

[1] 3f7b327562

Change-Id: If0a9d17c30de73a9870d0ebf3b3a82a14179c23d
2021-09-15 19:38:13 +00:00
manchandavishal 6efaee23d5 import "collections.abc" explicitly
Collections Abstract Base Classes have been moved to the
collections.abc module, which was part of the collections
module before[1] [2]. Usage from the collections module
directly is deprecated and will be removed from 3.10.
This commit updates to import abc module explicitly
wherever required as the same will no longer be visible/directly
used from the collections module.

[1] https://docs.python.org/3/library/collections.abc.html
[2] http://paste.openstack.org/show/802512/

Change-Id: I173f4d647474c21c5d062280bd5703edffb4978e
2021-03-04 18:47:37 +00: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
Akihiro Motoki ac3d139c06 Cleanup python 2.7 handling logic
We have several codes to handle the differences between py2 and py3.
py2 support has been dropped so there is no need for them now.

Change-Id: I30080f4e1a5ac04860c4341d966ee53131eb2022
2020-02-21 09:02:37 +09:00
Akihiro Motoki 4fc1b9c424 Remove six.reraise usage
six.reraise can be converted into "raise new_exc from original_exc"
introduced in python3.

In case of horizon.exceptions.handle(), six.reraise was used to
raise the original exception again, so we can convert it into "raise".

six is removed from requirements.txt.
Note that we need to keep six in lower-constraints.txt
as dependent libraries still use six.

Change-Id: I0672a516083727c245f1d4fa5b10eed9cd81a726
2020-01-17 07:31:26 +09: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
Akihiro Motoki 9b99f17100 Define default settings explicitly (horizon)
test_parse_isotime_filter in test_filters is updated to match
TIME_ZONE=UTC. Previously TIME_ZONE was not set in horizon.test.settings
and the default value America/Chicago was used. Horizon uses UTC as the
default value of TIME_ZONE, so it is better to use UTC for testing too.

horizon settings in openstack_dashboard.settings are moved to
under horizon.

Part of blueprint ini-based-configuration
Change-Id: I9abdbbe0dcefc08ffea61143e3c0a87ed87b2e2a
2019-09-12 15:05:56 +09:00
Zuul 63a28d40b2 Merge "Handle move of ABCs to collections.abc" 2019-09-10 16:43:52 +00:00
Stephen Finucane 4ece14b28a Handle move of ABCs to collections.abc
Resolves the following warning:

  DeprecationWarning: Using or importing the ABCs from 'collections'
  instead of from 'collections.abc' is deprecated, and in 3.8 it will
  stop working

Change-Id: Ib2214e7560cda1ef510c08859d5ee0726eb66b7b
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2019-09-10 19:21:20 +09:00
Stephen Finucane 885b4c5a6a Handle deprecation of inspect.getargspec
getargspec has been deprecated in py3 with plans to remove it in py3.6.
The recommendation is to move to inspect.signature, but the results of
that call are different than the existing one.

There is also getfullargspec available under py3 that was originally
deprecated, but for the sake of handling 2/3 code, it has been
un-deprecated. This call uses inspect internally, but returns a mostly
compatible result with what getargspec did. This handles getargspec
deprecation by just using getfullargspec instead if it is available

Change-Id: Id0104f7e2b4c43725cb6bcd5e0cd905b19e3133e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2019-09-10 19:09:06 +09:00
David Lyle 78de547871 Fix policy function check error
Change in I8a346e55bb98e4e22e0c14a614c45d493d20feb4 to make
POLICY_CHECK_FUNCTION a string rather than a function was incomplete.

The case in horizon/tables/base.py is problematic in particular and results in
raising the TypeError: 'str' object is not callable error.

There is another instance that is not problematic, but is changed for
consistency sake.

Change-Id: Ifc616e322eb38ec7e5ac218f7f3c5ccec52e40f4
Closes-Bug: #1818292
2019-03-01 14:21:07 -07:00
wangliangyu 3ac9037677 Table checkbox display problem when updating row
Multi-process:
  If there only one table action, DeleteAction.
  Assume the first time retrieving an empty table in one
  process, the checkbox is hidden.
  In the other process, creating a item, like a instance.
  Now, the checkbox is shown in second process.
  Then updating the item state in first process, the checkbox
  will be hidden. In second process, the checkbox will be shown.

  For above case, we need set the checkbox visibility every time
  when updating single row by ajax.

Change-Id: Ib230ad775070ee089c8f82e7df3ec30c1cda7aa0
Closes-Bug: #1799151
2019-02-09 16:52:44 +09:00
Zuul c9536342c2 Merge "pylint: fix len-as-condition warning" 2019-01-16 14:25:39 +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 c076db20c8 pylint: fix len-as-condition warning
Change-Id: Ib89c1854ad42b96e4caf281160d568fe98430afe
2019-01-16 12:56:20 +09:00
Zuul 6299fdbdc0 Merge "pylint: fix several warnings" 2019-01-15 11:22:36 +00:00
Akihiro Motoki 86d1826a29 pylint: ignore access-member-before-definition explicitly
In case of Cell.status property, the code has a good readability,
so it sounds reasonable to ignore access-member-before-definition,
although access-member-before-definition itself is a useful check.

Change-Id: Ic6f2ec42bac41c62265e6b0e744c256007093ce6
2019-01-15 01:05:49 +09:00
Akihiro Motoki 6e1348d05f pylint: fix several warnings
openstack_dashboard/theme_settings.py:63:8: W1201: Specify string format arguments as logging function parameters (logging-not-lazy)
openstack_dashboard/settings.py:412:24: W0122: Use of exec (exec-used)
openstack_dashboard/dashboards/identity/domains/workflows.py:476:44: W0640: Cell variable group_id defined in loop (cell-var-from-loop)
openstack_dashboard/dashboards/identity/projects/workflows.py:906:49: W0640: Cell variable group_id defined in loop (cell-var-from-loop)
openstack_dashboard/dashboards/admin/networks/views.py:42:0: W0404: Reimport 'views' (imported line 28) (reimported)
openstack_dashboard/api/swift.py:204:0: W0102: Dangerous default value {} as argument (dangerous-default-value)
openstack_dashboard/api/swift.py:214:0: W0102: Dangerous default value {} as argument (dangerous-default-value)
openstack_dashboard/api/cinder.py:248:30: W0631: Using possibly undefined loop variable 'cinder_url' (undefined-loop-variable)
openstack_auth/backend.py:123:28: W0631: Using possibly undefined loop variable 'plugin' (undefined-loop-variable)
openstack_auth/backend.py:129:39: W0631: Using possibly undefined loop variable 'plugin' (undefined-loop-variable)
openstack_auth/backend.py:131:39: W0631: Using possibly undefined loop variable 'plugin' (undefined-loop-variable)
openstack_auth/views.py:39:0: W0611: Unused Login imported from openstack_auth.forms (unused-import)
horizon/exceptions.py:348:8: W0125: Using a conditional statement with a constant value (using-constant-test)
horizon/tables/base.py:353:12: W0715: Exception arguments suggest string formatting might be intended (raising-format-tuple)

Change-Id: Icf4f22abda77c9dbf98c780de876b7836c31d669
2019-01-15 00:22:27 +09:00
Akihiro Motoki 59beb951a3 pylint: Fix consider-using-(dict|set)-comprehension
Change-Id: I81c694c17106c179a53326a12e78cfa899872970
2019-01-13 00:59:05 +09:00
Zuul 6666df6de6 Merge "Truncate table size column cause the exception" 2018-10-24 07:43:28 +00:00
Ameed Ashour 7f12136393 Truncate table size column cause the exception
The truncate filter treat an integer as a string and failing.

Co-Authored-By: Ivan Kolodyazhny <e0ne@e0ne.info>
Change-Id: I1a66c3080544e0af8ba02c530351ab4b2d7f9bbd
Closes-Bug: #1504397
2018-10-03 14:13:28 +00:00
Akihiro Motoki aa1ca195f9 Drop use_mox from horizon test helpers
We announced in the Rocky cycle that use_mox will be dropped
in the beginning of Stein cycle. This commit drops use_mox and
cleans up mox related stuffs in horizon and openstack_dashboard codes.

Note that openstack_auth is under the mock migration,
so we cannot mox3 from test-requirements.txt.

blueprint mock-framework-in-unit-tests

Change-Id: I189daf2d678bef0fa8219acaab5cf45bbe54178f
2018-08-18 17:11:15 +09:00
Qian Min Chen 2fa872aac2 Remove the redundant "required=True"
The django form field default is "required=True", so this patch
remove the redundant "required=True" in the form.

Change-Id: I3d91ae0638b69d56c1f1b72913ee4995db249007
2018-07-23 09:42:41 +08:00
Akihiro Motoki 11eb4e9d3e Fix W503 warnings
W503 line break before binary operator

Looking at the code base, it sounds okay to follow this check.

Change-Id: Id511e0104dc6de5b204021661d4a8776ca6d3658
2018-04-11 18:13:47 +09:00
Zuul f5802ce28b Merge "table: Show checkbox only when there is BatchAction" 2018-03-27 16:01:56 +00: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
wangliangyu e97623e158 table: Show checkbox only when there is BatchAction
Checkbox in a table assumes BatchAction.
 This commit checks whether at least one BatchAction is
 included as table actions and displays checkboxes
 only when BatchAction is available.

Change-Id: Ia1cba6c59f5d40f7df7f4b98a9f459a6934cfbb7
Closes-Bug: #1744742
2018-01-22 23:45:09 +08:00
Dmitry Ratushyy 9e1eb5f5d7 Fix actions inside instance details view page
At the current moment user can not suspend an
instance from the instance "Details" page if the
instance does not belong to the first page of the
instances list. This is fixed.

Co-Authored-By: Ivan Kolodyazhny <e0ne@e0ne.info>
Co-Authored-By: Vladislav Kuzmin <vkuzmin@mirantis.com>
Change-Id: I4d805e4a65e838242af38677cbb9efefc498a96f
Closes-Bug: #1553142
2017-09-07 01:08:41 +04:00
Jenkins 5f72d0433e Merge "Switch render() arguments to the new way" 2017-07-03 08:31:24 +00:00
Akihiro Motoki 563908e2c0 doc: cleanup formatting
* Clean up unnecessary vertical quotes at the left side
  caused by extra spaces at the beginning of lines.
* Do not use backquotes in the title lines
  (ref/run_tests.rst, ref/horizon.rst)
  When backquotes are used in the first-level title,
  it will be included in the navigation at the top-right corner
  https://docs.openstack.org/developer/horizon/contributor/ref/index.html
* Remove duplicated contents:: directive in ref/run_tests.sh.
  openstackdocstheme generates the toc by default, so having contents::
  directive leads to duplicated toc in a page.

Change-Id: Icc641927ad7cd7a8d79632c64a3ce212f0dc0b64
2017-06-29 17:59:09 +09: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
Jenkins 30a00a0dc3 Merge "Ensure log messages are not translated" 2017-04-27 22:39:12 +00:00
Jenkins 86028ea5a6 Merge "Move all RC download buttons under a single menu" 2017-04-26 21:05:33 +00:00
Akihiro Motoki ced987815d Ensure log messages are not translated
Previously translated messages are included in log messages
and it was determined what language is chosen by users.
It makes difficult for operators to understand log messgaes.

This commit tries to use English messages for all log messages.
The following policies are applied based on the past discussions
in the bug 1406333 and related reviews.

- English messages are used for log messages.
- log messages include exception messages if possible
  to help operators identify what happens.
- Use ID rather than name for log messages
  as ID is much more unique compared to name.
- LOG.debug() in success code path are deleted.
  We don't log success messages in most places and API calls to
  back-end services can be logged from python bindings.

Change-Id: Ie554463908327435d886d0d0f1671fd327c0cd00
Closes-Bug: #1406333
2017-04-11 10:24:01 +00:00
Akihiro Motoki 1f7e639102 Move all RC download buttons under a single menu
In the API access page, we now see three or four
"Download OpenStack RC" buttons.
This commit packs them into a single menu.

To complete the goal, a new option called "table_actions_menu_label"
is newly introduced to DataTable.

Also the condition to disable an action dropdown menu is changed
so that the action dropdown is not disabled when "multi_select"
feature is not used in a corresponding table.
Otherwise, the dropdown menu is always disabled and there is
no way to enable it in a DataTable with multi_select=False.

Change-Id: I229c69b09c45bb20b3df48c9901d76b89fd27ee4
Closes-Bug: #1680563
2017-04-10 12:03:30 +00:00
Jenkins 87f1291de5 Merge "Fix the existence check in DataTable Column" 2017-04-07 06:45:03 +00:00
Gábor Antal 34a3aa0ba8 Handle log message interpolation by the logger
According to OpenStack Guideline[1], logged string message should be
interpolated by the logger.

[1]: http://docs.openstack.org/developer/oslo.i18n/guidelines.html#adding-variables-to-log-messages
Change-Id: I51f50935f1eeffe4960562d6309dfdf05814e595
Closes-Bug: #1596829
2017-03-31 20:59:16 +09:00
Akihiro Motoki 5dadf41c5d Fix the existence check in DataTable Column
Previously DataTable Column checks whether a field exists or not
by checking a result of dict.get(). This has a side effect that
the check complains a field does not exist even when the field
value is None. This commit change the logic to use hasattr to
handle a field with None.

Change-Id: I6ef5ccf90aefd3c407f91a5f3a633d8f68593339
Closes-Bug: #1675912
2017-03-24 20:09:32 +00: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
Jenkins 0744e8e594 Merge "DataTable column level policy" 2016-12-08 21:23:31 +00:00
Richard Jones f2eaafcc9c Fix mox trapped errors
Some mox errors were being caught by a too-broad
except clause

Change-Id: I0352e231425b42456552e7cffd91722ccbb95055
Closes-Bug: 1644709
2016-11-25 16:58:47 +11:00
Akihiro Motoki 35d2becdd6 Fix docstring warnings
Partial-Bug: #1411719
Partial-Bug: #1486222

Change-Id: I2d649295e7425ab73f09f3a5d91076350bf7ed7a
2016-09-24 20:44:48 +09:00
Jenkins 9250ef9678 Merge "Replace table row 'status_unknown' class with 'warning' class" 2016-09-14 22:31:38 +00:00
Rob Cresswell 041af0fd0a Replace table row 'status_unknown' class with 'warning' class
The default bootstrap styling for table rows uses the same classes as
alerts (warning, danger etc). Rather than layering additional logic
around this with a new class, we should just fall back to the documented
boostrap method.

Also resets the warning colour to its default bootstrap variable, rather
than carrying an altered version.

Change-Id: I3472244fcbbd121a8de48d78084554760dab6385
Closes-Bug: 1615632
2016-09-08 09:57:06 +00:00