Skip to content

Commit

Permalink
fixes for django 4
Browse files Browse the repository at this point in the history
  • Loading branch information
assem-ch committed Feb 14, 2022
1 parent 111d9f8 commit 6c21764
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 56 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: python
python:
- 3.6
- 3.7
- 3.8
- 3.9
env:
- DJANGO="==3.0"
- DJANGO="==3.1"
- DJANGO="==4.0"
before_install:
- export DJANGO_SETTINGS_MODULE=jet.tests.settings
install:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Contributing
============

Django JET is open-source and every member of the community can contribute to it. We are happy to see patches
Django JET reboot is open-source and every member of the community can contribute to it. We are happy to see patches
and improvements with Django JET. But please keep in mind that there are some guidelines you should follow.

.. _requirements:
Expand Down
2 changes: 1 addition & 1 deletion docs/dashboard_custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Set Up Custom Dashboard

.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard import modules
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
Expand Down
19 changes: 11 additions & 8 deletions docs/dashboard_custom_module.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

=======================
Custom Dashboard Module
=======================
Expand Down Expand Up @@ -140,7 +141,7 @@ in ``dashboard_modules_views.py`` file inside your application:

.. code-block:: python
from django.conf.urls import url
from django.urls import path
from django.contrib import messages
from django.shortcuts import redirect
from jet.dashboard import dashboard
Expand All @@ -155,10 +156,10 @@ in ``dashboard_modules_views.py`` file inside your application:
return redirect(request.META.get('HTTP_REFERER'))
# This method registers view's url
# This method registers view's path
dashboard.urls.register_urls([
url(
r'^update_database/',
path(
'update_database/',
update_database,
name='update-database'
),
Expand All @@ -169,16 +170,18 @@ You should import this file before dashboard urls have been imported in you main
.. code-block:: python
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import include
from django.urls import path
from django.contrib import admin
# Import dashboard module views
from core import dashboard_modules_views
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^jet/', include('jet.urls', 'jet')),
url(r'^jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
path('admin/', include(admin.site.urls)),
path('jet/', include('jet.urls', 'jet')),
path('jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
...
]
Expand Down
4 changes: 2 additions & 2 deletions docs/dashboard_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Usage Example
-------------
.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
from jet.dashboard.dashboard_modules import google_analytics
Expand Down Expand Up @@ -137,7 +137,7 @@ Usage Example
-------------
.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
from jet.dashboard.dashboard_modules import yandex_metrika
Expand Down
2 changes: 1 addition & 1 deletion jet/dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def init_with_context(self, context):
.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard import modules
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
Expand Down
2 changes: 1 addition & 1 deletion jet/dashboard/dashboard_modules/google_analytics_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
try:
from django.core.urlresolvers import reverse
except ImportError: # Django 1.11
from django.urls import reverse
from django.urls import reverse, re_path

from django.urls import re_path
from django.contrib import messages
Expand Down
13 changes: 5 additions & 8 deletions jet/dashboard/dashboard_modules/yandex_metrika.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
from jet.dashboard.modules import DashboardModule
from django.utils.translation import gettext_lazy as _
from django.conf import settings
try:
from django.utils.encoding import force_text
except ImportError:
from django.utils.encoding import force_str as force_text
from django.utils.encoding import force_str

try:
from urllib import request
Expand Down Expand Up @@ -107,12 +104,12 @@ def render(self, name, value, attrs=None):
if value and len(value) > 0:
link = '<a href="%s">%s</a>' % (
reverse('jet-dashboard:yandex-metrika-revoke', kwargs={'pk': self.module.model.pk}),
force_text(_('Revoke access'))
force_str(_('Revoke access'))
)
else:
link = '<a href="%s">%s</a>' % (
reverse('jet-dashboard:yandex-metrika-grant', kwargs={'pk': self.module.model.pk}),
force_text(_('Grant access'))
force_str(_('Grant access'))
)

if value is None:
Expand All @@ -139,10 +136,10 @@ def set_module(self, module):
def set_counter_choices(self, module):
counters = module.counters()
if counters is not None:
self.fields['counter'].choices = (('', '-- %s --' % force_text(_('none'))),)
self.fields['counter'].choices = (('', '-- %s --' % force_str(_('none'))),)
self.fields['counter'].choices.extend(map(lambda x: (x['id'], x['site']), counters))
else:
label = force_text(_('grant access first')) if module.access_token is None else force_text(_('counters loading failed'))
label = force_str(_('grant access first')) if module.access_token is None else force_str(_('counters loading failed'))
self.fields['counter'].choices = (('', '-- %s -- ' % label),)


Expand Down
10 changes: 5 additions & 5 deletions jet/dashboard/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class LinkList(DashboardModule):
.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard import modules
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
Expand Down Expand Up @@ -278,7 +278,7 @@ class AppList(DashboardModule):
.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard import modules
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
Expand Down Expand Up @@ -351,7 +351,7 @@ class ModelList(DashboardModule):
.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard import modules
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
Expand Down Expand Up @@ -425,7 +425,7 @@ class RecentActions(DashboardModule):
.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard import modules
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
Expand Down Expand Up @@ -533,7 +533,7 @@ class Feed(DashboardModule):
.. code-block:: python
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from jet.dashboard import modules
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
Expand Down
21 changes: 9 additions & 12 deletions jet/dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import django
try:
from django.conf.urls import url
except ImportError:
from django.urls import re_path as url
from django.urls import re_path

try:
from django.views.i18n import JavaScriptCatalog
Expand All @@ -18,42 +15,42 @@
app_name = 'dashboard'

urlpatterns = [
url(
re_path(
r'^module/(?P<pk>\d+)/$',
UpdateDashboardModuleView.as_view(),
name='update_module'
),
url(
re_path(
r'^update_dashboard_modules/$',
update_dashboard_modules_view,
name='update_dashboard_modules'
),
url(
re_path(
r'^add_user_dashboard_module/$',
add_user_dashboard_module_view,
name='add_user_dashboard_module'
),
url(
re_path(
r'^update_dashboard_module_collapse/$',
update_dashboard_module_collapse_view,
name='update_dashboard_module_collapse'
),
url(
re_path(
r'^remove_dashboard_module/$',
remove_dashboard_module_view,
name='remove_dashboard_module'
),
url(
re_path(
r'^load_dashboard_module/(?P<pk>\d+)/$',
load_dashboard_module_view,
name='load_dashboard_module'
),
url(
re_path(
r'^reset_dashboard/$',
reset_dashboard_view,
name='reset_dashboard'
),
url(
re_path(
r'^jsi18n/$',
javascript_catalog,
{'packages': 'jet'},
Expand Down
2 changes: 1 addition & 1 deletion jet/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def field_choices(self, field, request, model_admin):
from django import forms
from django.contrib.admin.widgets import AdminDateWidget
from rangefilter.filter import DateRangeFilter as OriginalDateRangeFilter
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _


class DateRangeFilter(OriginalDateRangeFilter):
Expand Down
4 changes: 2 additions & 2 deletions jet/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from django.test import TestCase, RequestFactory
from django.utils.encoding import smart_text
from django.utils.encoding import smart_str
from jet.filters import RelatedFieldAjaxListFilter
from jet.tests.models import RelatedToTestModel, TestModel

Expand Down Expand Up @@ -57,5 +57,5 @@ def test_related_field_ajax_list_filter_with_initial(self):

self.assertIsInstance(choices, list)
self.assertEqual(len(choices), 1)
self.assertEqual(choices[0], (initial.pk, smart_text(initial)))
self.assertEqual(choices[0], (initial.pk, smart_str(initial)))

8 changes: 4 additions & 4 deletions jet/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.conf.urls import include, url
from django.conf.urls import include
from django.contrib import admin

admin.autodiscover()

from django.urls import path

urlpatterns = [
url(r'^jet/', include('jet.urls', 'jet')),
url(r'^jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
path(r'jet/', include('jet.urls', 'jet')),
path(r'jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
path(r'admin/doc/', include('django.contrib.admindocs.urls')),
path('admin/', admin.site.urls),
]

14 changes: 13 additions & 1 deletion jet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def get_model_queryset(admin_site, model, request, preserved_filters=None):
list_select_related = model_admin.get_list_select_related(request) \
if hasattr(model_admin, 'get_list_select_related') else model_admin.list_select_related



actions = model_admin.get_actions(request)
if actions:
list_display = ['action_checkbox'] + list(list_display)
Expand All @@ -221,17 +223,27 @@ def get_model_queryset(admin_site, model, request, preserved_filters=None):

change_list_args = [
request, model, list_display, list_display_links, list_filter,
model_admin.date_hierarchy, search_fields, list_select_related,
model_admin.date_hierarchy, search_fields, list_select_related,
model_admin.list_per_page, model_admin.list_max_show_all,
model_admin.list_editable, model_admin]


try:
sortable_by = model_admin.get_sortable_by(request)
change_list_args.append(sortable_by)
except AttributeError:
# django version < 2.1
pass

try:
search_help_text = model_admin.get_sortable_by(request) \
if hasattr(model_admin, 'get_search_help_text') else model_admin.search_help_text
change_list_args.append(search_help_text)
except AttributeError:
# django version < 4.0
pass


try:
cl = ChangeList(*change_list_args)
queryset = cl.get_queryset(request)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"jquery.cookie": "1.4.1",
"jquery.mousewheel": "3.1.9",
"merge-stream": "1.0.0",
"perfect-scrollbar": "git://github.com/noraesae/perfect-scrollbar#0.6.5",
"perfect-scrollbar": "git://github.com/noraesae/perfect-scrollbar#0.6.14",
"postcss-pxtorem": "3.3.1",
"select2": "4.0.0",
"timepicker": "git://github.com/geex-arts/timepicker",
Expand Down
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ def get_install_requires():
'Intended Audience :: System Administrators',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.9',
'Environment :: Web Environment',
'Topic :: Software Development',
'Topic :: Software Development :: User Interfaces',
Expand Down

0 comments on commit 6c21764

Please sign in to comment.