Skip to content

Commit

Permalink
Display correct import order on Admin UI (#1849)
Browse files Browse the repository at this point in the history
* Fix admin UI display of field import order

* added test for default field order

* updated changelog

* removed redundant fixture
  • Loading branch information
matthewhegarty committed May 21, 2024
1 parent f447a00 commit 33da17a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog
- Release note documentation updated (`1840 <https://github.com/django-import-export/django-import-export/pull/1840>`_)
- Refactored ``DateWidget`` & ``DateTimeWidget`` to remove code duplication (`1839 <https://github.com/django-import-export/django-import-export/pull/1839>`_)
- Added missing migration to example app (`1843 <https://github.com/django-import-export/django-import-export/pull/1843>`_)
- Fix admin UI display of field import order (`1849 <https://github.com/django-import-export/django-import-export/pull/1849>`_)

4.0.3 (2024-05-16)
------------------
Expand Down
2 changes: 1 addition & 1 deletion import_export/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ def get_export_headers(self, fields=None):
return [force_str(field.column_name) for field in export_fields]

def get_user_visible_fields(self):
return self.get_fields()
return self.get_import_fields()

def iter_queryset(self, queryset):
if not isinstance(queryset, QuerySet):
Expand Down
42 changes: 42 additions & 0 deletions tests/core/tests/admin_integration/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,3 +1007,45 @@ def test_import_preview_order(self):
"</tr>"
)
self.assertRegex(str(response.content), target_row_re)


class DefaultFieldsImportOrderTest(AdminTestMixin, TestCase):
"""
Display correct import order based on default 'fields' declaration (issue 1845).
Ensure that the prompt text on the import page renders the
fields in the correct order.
"""

def test_import_preview_order(self):
response = self.client.get(self.ebook_import_url)
# test display rendered in correct order
target_re = (
r"This importer will import the following fields:[\\n\s]+"
r"<code>id, author_email, name, published_date</code>[\\n\s]+"
)
self.assertRegex(str(response.content), target_re)


class DeclaredImportOrderTest(AdminTestMixin, TestCase):
"""
Display correct import order when 'import_order' is declared (issue 1845).
Ensure that the prompt text on the import page renders the
fields in the correct order.
"""

def setUp(self):
super().setUp()
EBookResource._meta.import_order = ("id", "name", "published", "author_email")

def tearDown(self):
super().tearDown()
EBookResource._meta.import_order = ()

def test_import_preview_order(self):
response = self.client.get(self.ebook_import_url)
# test display rendered in correct order
target_re = (
r"This importer will import the following fields:[\\n\s]+"
r"<code>id, name, published_date, author_email</code>[\\n\s]+"
)
self.assertRegex(str(response.content), target_re)

0 comments on commit 33da17a

Please sign in to comment.