From a84bb00210243ee64fa4523c96af8b71f1fe6467 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Mon, 26 Nov 2018 23:55:12 +0530 Subject: [PATCH 1/9] Django 2.0 support in Admin TypeError at /admin/categories/category/ __init__() missing 1 required positional argument: 'sortable_by' --- categories/editor/tree_editor.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index ff2c135..3997325 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -148,6 +148,13 @@ class TreeEditor(admin.ModelAdmin): self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self) + elif django.VERSION[0] == 2: + params = ( + request, self.model, list_display, + self.list_display_links, self.list_filter, self.date_hierarchy, + self.search_fields, self.list_select_related, + self.list_per_page, self.list_max_show_all, + self.list_editable, self.sortable_by, self) else: params = ( request, self.model, list_display, From 6019c0dd4f53cdb4bc4a58fa17e7993d8057fbf3 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Tue, 27 Nov 2018 21:21:00 +0530 Subject: [PATCH 2/9] Bug Fix : sortable was last argument --- categories/editor/tree_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index 3997325..8310fcd 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -154,7 +154,7 @@ class TreeEditor(admin.ModelAdmin): self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_max_show_all, - self.list_editable, self.sortable_by, self) + self.list_editable, self, self.sortable_by) else: params = ( request, self.model, list_display, From c53bc77b8294312f1c571fd1f63a8623581a3027 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Tue, 27 Nov 2018 21:36:22 +0530 Subject: [PATCH 3/9] Adding opts to context for Django version 2 and above --- categories/editor/tree_editor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index 8310fcd..72c40c3 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -148,7 +148,7 @@ class TreeEditor(admin.ModelAdmin): self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self) - elif django.VERSION[0] == 2: + elif django.VERSION[0] >= 2: params = ( request, self.model, list_display, self.list_display_links, self.list_filter, self.date_hierarchy, @@ -250,6 +250,8 @@ class TreeEditor(admin.ModelAdmin): } if django.VERSION[0] == 1 and django.VERSION[1] < 4: context['root_path'] = self.admin_site.root_path + elif django.VERSION[0] >= 2: + context['opts'] = self..model._meta else: selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count) From e39b5d24a864efcd2f6024263f02cdacf586c075 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Tue, 27 Nov 2018 21:45:05 +0530 Subject: [PATCH 4/9] Updated tree editor for typo --- categories/editor/tree_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index 72c40c3..d9b1427 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -251,7 +251,7 @@ class TreeEditor(admin.ModelAdmin): if django.VERSION[0] == 1 and django.VERSION[1] < 4: context['root_path'] = self.admin_site.root_path elif django.VERSION[0] >= 2: - context['opts'] = self..model._meta + context['opts'] = self.model._meta else: selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count) From 1dc6d473ff9f6a57edde3281e670b5259312ee6d Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Tue, 27 Nov 2018 23:56:21 +0530 Subject: [PATCH 5/9] Test Cases fix --- categories/editor/tree_editor.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index d9b1427..19fe3f9 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -148,20 +148,20 @@ class TreeEditor(admin.ModelAdmin): self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self) - elif django.VERSION[0] >= 2: - params = ( - request, self.model, list_display, - self.list_display_links, self.list_filter, self.date_hierarchy, - self.search_fields, self.list_select_related, - self.list_per_page, self.list_max_show_all, - self.list_editable, self, self.sortable_by) - else: + elif django.VERSION[0] == 1 or ( django.VERSION[0] == 2 and django.VERSION[1] < 1): params = ( request, self.model, list_display, self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_max_show_all, self.list_editable, self) + else: + params = ( + request, self.model, list_display, + self.list_display_links, self.list_filter, self.date_hierarchy, + self.search_fields, self.list_select_related, + self.list_per_page, self.list_max_show_all, + self.list_editable, self, self.sortable_by) cl = TreeChangeList(*params) except IncorrectLookupParameters: # Wacky lookup parameters were given, so redirect to the main @@ -250,9 +250,7 @@ class TreeEditor(admin.ModelAdmin): } if django.VERSION[0] == 1 and django.VERSION[1] < 4: context['root_path'] = self.admin_site.root_path - elif django.VERSION[0] >= 2: - context['opts'] = self.model._meta - else: + elif django.VERSION[0] == 1 or ( django.VERSION[0] == 2 and django.VERSION[1] < 1): selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count) context.update({ @@ -260,6 +258,9 @@ class TreeEditor(admin.ModelAdmin): 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)}, 'selection_note_all': selection_note_all % {'total_count': cl.result_count}, }) + else: + context['opts'] = self.model._meta + context.update(extra_context or {}) return render_to_response(self.change_list_template or [ 'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()), From 3993038f951f784a527f0174f4ce01fccb92b876 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 28 Nov 2018 00:10:16 +0530 Subject: [PATCH 6/9] py27-lint test fix --- categories/editor/tree_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index 19fe3f9..31b8ab0 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -260,7 +260,7 @@ class TreeEditor(admin.ModelAdmin): }) else: context['opts'] = self.model._meta - + context.update(extra_context or {}) return render_to_response(self.change_list_template or [ 'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()), From 579aa2a8bf3c8ce3bbb3fd0b2a6db66d90fe3ad7 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 28 Nov 2018 00:27:55 +0530 Subject: [PATCH 7/9] Fixing model for TOXENV=py36-django110 --- example/simpletext/models.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/example/simpletext/models.py b/example/simpletext/models.py index 28aca89..41c1838 100755 --- a/example/simpletext/models.py +++ b/example/simpletext/models.py @@ -21,12 +21,14 @@ class SimpleText(models.Model): def __unicode__(self): return self.name - # If using the get_absolute_url method, put the following line at the top of this file: - from django.db.models import permalink - @permalink def get_absolute_url(self): - return ('simpletext_detail_view_name', [str(self.id)]) + try: + from django.db.models import permalink + return permalink('simpletext_detail_view_name', [str(self.id)]) + except ImportError: + from django.urls import reverse + return reverse('simpletext_detail_view_name', args=[str(self.id)]) class SimpleCategory(CategoryBase): From 6aacff3f4c27ac68ebda14a803bee9f3d70fd5d9 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 28 Nov 2018 00:31:46 +0530 Subject: [PATCH 8/9] Fix for TOXENV=py27-lint --- categories/editor/tree_editor.py | 4 ++-- example/simpletext/models.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index 31b8ab0..5b8c6fe 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -148,7 +148,7 @@ class TreeEditor(admin.ModelAdmin): self.list_display_links, self.list_filter, self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self) - elif django.VERSION[0] == 1 or ( django.VERSION[0] == 2 and django.VERSION[1] < 1): + elif django.VERSION[0] == 1 or (django.VERSION[0] == 2 and django.VERSION[1] < 1): params = ( request, self.model, list_display, self.list_display_links, self.list_filter, self.date_hierarchy, @@ -250,7 +250,7 @@ class TreeEditor(admin.ModelAdmin): } if django.VERSION[0] == 1 and django.VERSION[1] < 4: context['root_path'] = self.admin_site.root_path - elif django.VERSION[0] == 1 or ( django.VERSION[0] == 2 and django.VERSION[1] < 1): + elif django.VERSION[0] == 1 or (django.VERSION[0] == 2 and django.VERSION[1] < 1): selection_note_all = ungettext('%(total_count)s selected', 'All %(total_count)s selected', cl.result_count) context.update({ diff --git a/example/simpletext/models.py b/example/simpletext/models.py index 41c1838..0fe96d1 100755 --- a/example/simpletext/models.py +++ b/example/simpletext/models.py @@ -21,7 +21,6 @@ class SimpleText(models.Model): def __unicode__(self): return self.name - def get_absolute_url(self): try: from django.db.models import permalink From d542684e3685f86c02937a0df05449eda18ae041 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 28 Nov 2018 00:48:19 +0530 Subject: [PATCH 9/9] Fix for TOXENV=py27-lint --- categories/fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/categories/fields.py b/categories/fields.py index c7418b5..1926de9 100644 --- a/categories/fields.py +++ b/categories/fields.py @@ -19,7 +19,7 @@ class CategoryFKField(ForeignKey): try: from south.modelsinspector import add_introspection_rules - add_introspection_rules([], ["^categories\.fields\.CategoryFKField"]) - add_introspection_rules([], ["^categories\.fields\.CategoryM2MField"]) + add_introspection_rules([], [r"^categories\.fields\.CategoryFKField"]) + add_introspection_rules([], [r"^categories\.fields\.CategoryM2MField"]) except ImportError: pass