From 068aa4f74138a0e8d185c4aac37d6a82c8a27126 Mon Sep 17 00:00:00 2001 From: Olga Matyla <73503512+matyldv@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:50:37 +0100 Subject: [PATCH] Django 2.1 (#3863) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Django 2.1 * Bump drf * Fix tests_functional * Fix custom fields tests * Fix jQuery error in tabularFormset --------- Co-authored-by: Paweł Szulc --- requirements/base.txt | 6 +++--- src/ralph/admin/templates/admin/includes/javascripts.html | 5 +++-- src/ralph/admin/tests/tests_functional.py | 3 +++ src/ralph/admin/widgets.py | 6 +++--- src/ralph/assets/api/filters.py | 4 ++-- src/ralph/assets/api/views.py | 2 +- src/ralph/lib/custom_fields/tests/admin.py | 4 +++- src/ralph/lib/custom_fields/tests/test_admin.py | 2 +- src/ralph/lib/mixins/fields.py | 8 ++++---- src/ralph/lib/mixins/forms.py | 4 ++-- src/ralph/security/api.py | 2 +- 11 files changed, 26 insertions(+), 20 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index ab77273883..123a32a4c1 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,6 +1,6 @@ -r openstack.txt -r hermes.txt -Django==2.0.13 +Django==2.1.15 Faker==0.9.0 Markdown<3.0 # headerid extension removed in 3.0 - see #3313 for details Pillow==6.2.2 @@ -8,7 +8,7 @@ Unidecode==0.04.18 dj.choices==0.11.0 django-cryptography==0.3 django-extensions==2.2.9 -django-filter==1.0.4 +django-filter==2.0.0 django-import-export==1.2.0 django-money==0.12.3 django-mptt==0.11 @@ -18,7 +18,7 @@ django-sitetree==1.13.0 django-taggit-serializer==0.1.7 django-taggit==0.22.2 django-threadlocals==0.8 -djangorestframework==3.7.5 +djangorestframework==3.8.2 djangorestframework_xml==1.2.0 drf-nested-routers==0.11.1 factory-boy==2.11.1 diff --git a/src/ralph/admin/templates/admin/includes/javascripts.html b/src/ralph/admin/templates/admin/includes/javascripts.html index f042f77ba3..64aee38634 100644 --- a/src/ralph/admin/templates/admin/includes/javascripts.html +++ b/src/ralph/admin/templates/admin/includes/javascripts.html @@ -81,9 +81,10 @@ var group_id = $(this).data('group-id'), prefix = $(this).data('prefix'), add_text = $(this).data('add-text'), - delete_text = $(this).data('delete-text'); + delete_text = $(this).data('delete-text'), + selector = "#" + group_id + "-group .tabular.inline-related tbody tr"; (function($) { - $("#" + group_id + "-group .tabular.inline-related tbody tr").tabularFormset({ + $(selector).tabularFormset(selector, { prefix: prefix, addText: add_text, deleteText: delete_text diff --git a/src/ralph/admin/tests/tests_functional.py b/src/ralph/admin/tests/tests_functional.py index 5e6959a4dc..57f466e9f4 100644 --- a/src/ralph/admin/tests/tests_functional.py +++ b/src/ralph/admin/tests/tests_functional.py @@ -12,6 +12,7 @@ from ralph.admin.views.extra import RalphDetailView, RalphListView from ralph.admin.views.main import RalphChangeList from ralph.tests.admin import CarAdmin, ManufacturerAdmin +from ralph.tests.factories import UserFactory from ralph.tests.mixins import ClientMixin, ReloadUrlsMixin from ralph.tests.models import Car, Foo, TestManufacturer @@ -254,12 +255,14 @@ def _change_list_factory( model=model, model_admin=model_admin(model, ralph_site), request=request, + sortable_by=model_admin.sortable_by, ) def _get_ordering_list(self, model, model_admin, params, list_display): from django.contrib.admin.views.main import ORDER_VAR get_params = '{}={}'.format(ORDER_VAR, '.'.join(map(str, params))) request = RequestFactory().get('/?' + get_params) + request.user = UserFactory() cl = self._change_list_factory( model=Car, model_admin=CarAdmin, diff --git a/src/ralph/admin/widgets.py b/src/ralph/admin/widgets.py index 5f5eaf2b35..d906cc12dd 100644 --- a/src/ralph/admin/widgets.py +++ b/src/ralph/admin/widgets.py @@ -42,9 +42,9 @@ def media(self): static(path) for path in js ]) - def render(self, name, value, attrs=None): + def render(self, name, value, attrs=None, renderer=None): attrs['class'] = self.css_class - return super().render(name, value, attrs=attrs) + return super().render(name, value, attrs=attrs, renderer=renderer) class AdminDateWidget(DatepickerWidgetMixin, forms.DateInput): @@ -256,7 +256,7 @@ def render_search_fields_info(self, search_fields): rows.append("- {}\n".format(field)) return ''.join(rows) - def render(self, name, value, attrs=None): + def render(self, name, value, attrs=None, renderer=None): model_options = ( self.rel_to._meta.app_label, self.rel_to._meta.model_name ) diff --git a/src/ralph/assets/api/filters.py b/src/ralph/assets/api/filters.py index 87fd1bf1f7..0c4101a810 100644 --- a/src/ralph/assets/api/filters.py +++ b/src/ralph/assets/api/filters.py @@ -6,9 +6,9 @@ class NetworkableObjectFilters(django_filters.FilterSet): Base filter for all networkable objects for example with IP address. """ configuration_path = django_filters.CharFilter( - name='configuration_path__path' + field_name='configuration_path__path' ) - ip = django_filters.CharFilter(name='ethernet_set__ipaddress__address') + ip = django_filters.CharFilter(field_name='ethernet_set__ipaddress__address') class Meta: fields = [ diff --git a/src/ralph/assets/api/views.py b/src/ralph/assets/api/views.py index b82db4d11c..7fd492dfd4 100644 --- a/src/ralph/assets/api/views.py +++ b/src/ralph/assets/api/views.py @@ -41,7 +41,7 @@ class EnvironmentViewSet(RalphAPIViewSet): class ServiceFilterSet(django_filters.FilterSet): - active = BooleanFilter(name="active") + active = BooleanFilter(field_name="active") class Meta: model = models.Service diff --git a/src/ralph/lib/custom_fields/tests/admin.py b/src/ralph/lib/custom_fields/tests/admin.py index 475c6622fd..8bb45fbdc4 100644 --- a/src/ralph/lib/custom_fields/tests/admin.py +++ b/src/ralph/lib/custom_fields/tests/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from ..admin import CustomFieldValueAdminMixin +from ..admin import CustomFieldAdmin, CustomFieldValueAdminMixin +from ..models import CustomField from .models import ModelA, ModelB, SomeModel site = admin.AdminSite(name="cf_admin") @@ -24,3 +25,4 @@ class ModelBAdmin(CustomFieldValueAdminMixin, admin.ModelAdmin): site.register(SomeModel, SomeModelAdmin) site.register(ModelA, ModelAAdmin) site.register(ModelB, ModelBAdmin) +site.register(CustomField, CustomFieldAdmin) diff --git a/src/ralph/lib/custom_fields/tests/test_admin.py b/src/ralph/lib/custom_fields/tests/test_admin.py index d3172f1630..5dc56d4219 100644 --- a/src/ralph/lib/custom_fields/tests/test_admin.py +++ b/src/ralph/lib/custom_fields/tests/test_admin.py @@ -65,7 +65,7 @@ def test_get_customfield_formfield_for_string_field(self): # default_value should be placed self.assertContains( response, - '' + '' ) def test_add_new_custom_field_value_for_existing_object(self): diff --git a/src/ralph/lib/mixins/fields.py b/src/ralph/lib/mixins/fields.py index be3fbfeca3..642de66bda 100644 --- a/src/ralph/lib/mixins/fields.py +++ b/src/ralph/lib/mixins/fields.py @@ -176,8 +176,8 @@ def clean(self, value, model_instance): class TicketIdFieldWidget(AdminTextInputWidget): - def render(self, name, value, attrs=None): - html = super().render(name, value, attrs) + def render(self, name, value, attrs=None, renderer=None): + html = super().render(name, value, attrs, renderer) if value: url = '{}{}'.format(settings.ISSUE_TRACKER_URL, value) final_attrs = {'href': smart_urlquote(url), 'target': '_blank'} @@ -256,7 +256,7 @@ def get_limit_models(self): class TagWidget(forms.TextInput): - def render(self, name, value, attrs=None): + def render(self, name, value, attrs=None, renderer=None): if value is not None and not isinstance(value, six.string_types): value = ', '.join(sorted([ (t if ',' not in t else '"%s"' % t) for t in value @@ -264,7 +264,7 @@ def render(self, name, value, attrs=None): if attrs is None: attrs = {} attrs['class'] = 'vTextField' - return super(TagWidget, self).render(name, value, attrs) + return super(TagWidget, self).render(name, value, attrs, renderer) class TaggitTagField(TagField): diff --git a/src/ralph/lib/mixins/forms.py b/src/ralph/lib/mixins/forms.py index 895d55cdf8..f7184f812e 100644 --- a/src/ralph/lib/mixins/forms.py +++ b/src/ralph/lib/mixins/forms.py @@ -40,13 +40,13 @@ def _get_other_field(self, name, value): name=OTHER_NAME.format(name), value=value.get(OTHER) or '' ) - def render(self, name, value, attrs=None): + def render(self, name, value, attrs=None, renderer=None): show_other = value and value.get('value') == OTHER choice_value = (value.get('value') if value else '') or '' return mark_safe( '
{}{}
'.format( self.css_class, - super().render(name, choice_value, attrs=attrs), + super().render(name, choice_value, attrs=attrs, renderer=renderer), self._get_other_field(name, value) if show_other else '' ) ) diff --git a/src/ralph/security/api.py b/src/ralph/security/api.py index 149ea05c63..0575a7a328 100644 --- a/src/ralph/security/api.py +++ b/src/ralph/security/api.py @@ -89,7 +89,7 @@ def to_internal_value(self, data): class IPFilter(django_filters.FilterSet): ip = django_filters.CharFilter( - name='base_object__ethernet_set__ipaddress__address' + field_name='base_object__ethernet_set__ipaddress__address' ) class Meta: