Repository: django-import-export/django-import-export

Issue:
Resource is not being created with resource kwargs when showing export fields on admin UI
**Describe the bug**
I have a `UserAdmin` class that extends `ExportMixin` and declares the method `get_list_display` to change displayed fields according to the user on request. I want to reflect this on exported data, so the user can only export fields that are displayed to him on admin UI.

To do this, I override `get_export_resource_kwargs` method to send the list of displayed fields on admin to my `UserResource` class. 

All of this worked like a charm since until version 3.3.3. However, on version 3.3.4, this fields are displayed on admin UI alongside export form. The problem is, when you're creating the list of fields to show on admin UI, you instantiate resource classes without calling  `get_export_resource_kwargs`. This makes it impossible for me to know which fields the user that made the request can export.

**Versions:**
 - Django Import Export >= 3.3.4
 - Python 3.11.7
 - Django 4.2.9

**Expected behavior**
The following code of method `export_action` from `ExportMixin` class on `admin.py`:

```python
context["fields_list"] = [
    (
        res.get_display_name(),
        [
            field.column_name
            for field in res(model=self.model).get_user_visible_fields()
        ],
    )
    for res in self.get_export_resource_classes()
]
```

Should be like this:
```python
context["fields_list"] = [
    (
        res.get_display_name(),
        [
            field.column_name
            for field in res(model=self.model, **self.get_export_resource_kwargs(request)).get_user_visible_fields()
        ],
    )
    for res in self.get_export_resource_classes()
]
```



Discussion:
Thanks for reporting, I'll take a look.

> I want to reflect this on exported data, so the user can only export fields that are displayed to him on admin UI.

This sounds like a feature which is added in v4.  You might want to take a look.  More details [here](https://github.com/django-import-export/django-import-export/pull/1734).

Resolving patch:
diff --git a/import_export/admin.py b/import_export/admin.py
--- a/import_export/admin.py
+++ b/import_export/admin.py
@@ -855,7 +855,9 @@ def export_action(self, request, *args, **kwargs):
                 res.get_display_name(),
                 [
                     field.column_name
-                    for field in res(model=self.model).get_user_visible_fields()
+                    for field in res(
+                        model=self.model, **self.get_export_resource_kwargs(request)
+                    ).get_user_visible_fields()
                 ],
             )
             for res in self.get_export_resource_classes()


Test patch:
diff --git a/tests/core/tests/test_admin_integration.py b/tests/core/tests/test_admin_integration.py
--- a/tests/core/tests/test_admin_integration.py
+++ b/tests/core/tests/test_admin_integration.py
@@ -675,6 +675,16 @@ def test_export_displays_resources_fields(self):
             ],
         )
 
+    @mock.patch("core.admin.BookAdmin.get_export_resource_kwargs")
+    def test_export_passes_export_resource_kwargs(
+        self, mock_get_export_resource_kwargs
+    ):
+        # issue 1738
+        mock_get_export_resource_kwargs.return_value = {"a": 1}
+        response = self.client.get("/admin/core/book/export/")
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(2, mock_get_export_resource_kwargs.call_count)
+
     def test_export(self):
         response = self.client.get("/admin/core/book/export/")
         self.assertEqual(response.status_code, 200)