Skip to content

Commit

Permalink
Merge 2b36781 into a9de5b1
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhegarty committed Sep 27, 2023
2 parents a9de5b1 + 2b36781 commit 094d436
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 163 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ django-import-export
.. image:: https://static.pepy.tech/personalized-badge/django-import-export?period=month&units=international_system&left_color=black&right_color=blue&left_text=Downloads/month
:target: https://pepy.tech/project/django-import-export

.. image:: https://img.shields.io/twitter/url/https/twitter.com/django_import.svg?style=social&label=Follow%20%40django_import
:alt: Follow us on X

django-import-export is a Django application and library for importing
and exporting data from a variety of formats. Includes Django Admin site integration.

Expand Down
2 changes: 1 addition & 1 deletion docs/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ You can define your resource to take the associated instance as a param, and the
def __init__(self, publisher_id):
self.publisher_id = publisher_id

def before_save_instance(self, instance, using_transactions, dry_run):
def before_save_instance(self, instance, row, **kwargs):
instance.publisher_id = self.publisher_id

class Meta:
Expand Down
35 changes: 35 additions & 0 deletions docs/api_mixins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
======
Mixins
======

.. currentmodule:: import_export.mixins

BaseImportExportMixin
---------------------

.. autoclass:: import_export.mixins.BaseImportExportMixin
:members:

BaseImportMixin
---------------

.. autoclass:: import_export.mixins.BaseImportMixin
:members:

BaseExportMixin
---------------

.. autoclass:: import_export.mixins.BaseExportMixin
:members:

ExportViewMixin
---------------

.. autoclass:: import_export.mixins.ExportViewMixin
:members:

ExportViewFormMixin
-------------------

.. autoclass:: import_export.mixins.ExportViewFormMixin
:members:
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Changelog
=========

Please refer to :doc:`release notes<release_notes>`.

4.0.0-alpha.5 (2023-09-22)
--------------------------

- Refactor ``resources.py`` to standardise method args (#1641)
- dynamic widget parameters for CharField fixes 'NOT NULL constraint' error in xlsx (#1485)
- refactor to export HTML / formulae escaping updates (#1638)

Expand Down
4 changes: 2 additions & 2 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ There is a workaround, which is to set a temporary flag on the instance being sa

class BookResource(resources.ModelResource):

def before_save_instance(self, instance, using_transactions, dry_run):
def before_save_instance(self, instance, row, **kwargs):
# during 'confirm' step, dry_run is True
instance.dry_run = dry_run
instance.dry_run = kwargs.get("dry_run", False)

class Meta:
model = Book
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exporting data with included admin integration.
celery
testing
faq
release_notes
changelog

.. toctree::
Expand All @@ -54,6 +55,7 @@ exporting data with included admin integration.
api_widgets
api_fields
api_instance_loaders
api_mixins
api_tmp_storages
api_results
api_forms
Expand Down
230 changes: 230 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
=============
Release Notes
=============

v4
==

v4 of import-export (released Q4 2023) contains a number of minor changes to the API.

If you have customized import-export by overriding methods, then you will have to
modify your installation before working with v4. If you have not overridden any
methods then you should not be affected by these changes and no changes to your code
should be necessary.

In both cases, please test thoroughly before deploying v4 to production.

Refer to
`this PR <https://github.com/django-import-export/django-import-export/pull/1641/>`_
for more information.

This guide describes the major changes and how to upgrade.

API changes
===========

The API changes mostly change method arguments, although some method names have changed.

Methods which process row data have been updated so that method args are standardized.
This has been done to resolve inconsistency issues where the parameters differed between
method calls, and to allow easier extensibility.

:class:`import_export.resources.Resource`
-----------------------------------------

Renamed methods
^^^^^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Previous
- New
- Summary

* - ``import_obj(self, obj, data, dry_run, **kwargs)``
- ``import_instance(self, instance, row, **kwargs)``
- * ``obj`` param renamed to ``instance``
* ``data`` param renamed to ``row``
* ``dry_run`` param now in ``kwargs``

* - ``after_import_instance(self, instance, new, row_number=None, **kwargs)``
- ``after_init_instance(self, instance, new, row, **kwargs)``
- * ``row`` added as mandatory arg
* ``row_number`` now in ``kwargs``

Parameter changes
^^^^^^^^^^^^^^^^^

This section describes methods in which the parameters have changed.

.. list-table::
:header-rows: 1

* - Previous
- New
- Summary

* - ``before_import(self, dataset, using_transactions, dry_run, **kwargs)``
- ``before_import(self, dataset, **kwargs)``
- * ``using_transactions`` param now in ``kwargs``
* ``dry_run`` param now in ``kwargs``

* - ``after_import(self, dataset, result, using_transactions, dry_run, **kwargs)``
- ``after_import(self, dataset, result, **kwargs)``
- * ``using_transactions`` param now in ``kwargs``
* ``dry_run`` param now in ``kwargs``

* - ``before_import_row(self, row, row_number=None, **kwargs)``
- ``before_import_row(self, row, **kwargs)``
- * ``row_number`` now in ``kwargs``

* - ``after_import_row(self, row, row_result, row_number=None, **kwargs)``
- ``after_import_row(self, row, row_result, **kwargs)``
- * ``row_number`` now in ``kwargs``

* - ``import_row(self, row, instance_loader, using_transactions=True, dry_run=False, **kwargs)``
- ``import_row(self, row, instance_loader, **kwargs)``
- * ``dry_run`` param now in ``kwargs``
* ``using_transactions`` param now in ``kwargs``

* - ``save_instance(self, instance, is_create, using_transactions=True, dry_run=False)``
- ``save_instance(self, instance, is_create, row, ***kwargs)``
- * ``dry_run`` param now in ``kwargs``
* ``using_transactions`` param now in ``kwargs``
* ``row`` added as mandatory arg

* - ``save_m2m(self, obj, data, using_transactions, dry_run)``
- ``save_m2m(self, instance, row, **kwargs)``
- * ``dry_run`` param now in ``kwargs``
* ``using_transactions`` param now in ``kwargs``
* ``row`` added as mandatory arg
* ``obj`` renamed to ``instance``
* ``data`` renamed to ``row``

* - ``before_save_instance(self, instance, using_transactions, dry_run)``
- ``before_save_instance(self, instance, row, **kwargs)``
- * ``dry_run`` param now in ``kwargs``
* ``using_transactions`` param now in ``kwargs``
* ``row`` added as mandatory arg

* - ``after_save_instance(self, instance, using_transactions, dry_run)``
- ``after_save_instance(self, instance, row, **kwargs)``
- * ``dry_run`` param now in ``kwargs``
* ``using_transactions`` param now in ``kwargs``
* ``row`` added as mandatory arg

* - ``delete_instance(self, instance, using_transactions=True, dry_run=False)``
- ``delete_instance(self, instance, row, **kwargs)``
- * ``dry_run`` param now in ``kwargs``
* ``using_transactions`` param now in ``kwargs``
* ``row`` added as mandatory arg

* - ``before_delete_instance(self, instance, dry_run)``
- ``before_delete_instance(self, instance, row, **kwargs)``
- * ``dry_run`` param now in ``kwargs``
* ``using_transactions`` param now in ``kwargs``
* ``row`` added as mandatory arg

* - ``after_delete_instance(self, instance, dry_run)``
- ``after_delete_instance(self, instance, row, **kwargs)``
- * ``dry_run`` param now in ``kwargs``
* ``using_transactions`` param now in ``kwargs``
* ``row`` added as mandatory arg

* - ``before_export(self, queryset, *args, **kwargs)``
- ``before_export(self, queryset, **kwargs)``
- * unused ``*args`` list removed

* - ``after_export(self, queryset, data, *args, **kwargs)``
- ``after_export(self, queryset, dataset, **kwargs)``
- * unused ``*args`` list removed
* ``data`` renamed to ``dataset``

* - ``filter_export(self, queryset, *args, **kwargs)``
- ``filter_export(self, queryset, **kwargs)``
- * unused ``*args`` list removed

* - ``export_field(self, field, obj)``
- ``export_field(self, field, instance)``
- * ``obj`` renamed to ``instance``

* - ``export(self, *args, queryset=None, **kwargs)``
- ``export(self, queryset=None, **kwargs)``
- * unused ``*args`` list removed

:class:`import_export.mixins.BaseImportMixin`
---------------------------------------------

Parameter changes
^^^^^^^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Previous
- New
- Summary

* - ``get_import_resource_kwargs(self, request, *args, **kwargs)``
- ``get_import_resource_kwargs(self, request, **kwargs)``
- * ``using_transactions`` param now in ``kwargs``
* ``dry_run`` param now in ``kwargs``
* unused ``*args`` list removed


:class:`import_export.mixins.BaseExportMixin`
---------------------------------------------

Parameter changes
^^^^^^^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Previous
- New
- Summary

* - ``get_export_resource_kwargs(self, request, *args, **kwargs)``
- ``get_export_resource_kwargs(self, request, **kwargs)``
- * unused ``*args`` list removed

* - ``get_export_resource_kwargs(self, request, *args, **kwargs)``
- ``get_export_resource_kwargs(self, request, **kwargs)``
- * unused ``*args`` list removed

* - ``get_data_for_export(self, request, *args, **kwargs)``
- ``get_data_for_export(self, request, queryset, **kwargs)``
- * unused ``*args`` list removed


:class:`import_export.fields.Field`
-----------------------------------

Parameter changes
^^^^^^^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Previous
- New
- Summary

* - ``clean(self, data, **kwargs)``
- ``clean(self, row, **kwargs)``
- * ``data`` renamed to ``row``

* - ``get_value(self, instance)``
- ``get_value(self, obj)``
- * ``obj`` renamed to ``instance``

* - ``save(self, obj, data, is_m2m=False, **kwargs)``
- ``save(self, instance, row, is_m2m=False, **kwargs)``
- * ``obj`` renamed to ``instance``
* ``data`` renamed to ``row``

* - ``export(self, obj)``
- ``export(self, instance)``
- * ``obj`` renamed to ``instance``
10 changes: 4 additions & 6 deletions import_export/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,10 @@ def process_dataset(
**kwargs,
):
res_kwargs = self.get_import_resource_kwargs(
request, *args, form=confirm_form, **kwargs
request, form=confirm_form, **kwargs
)
resource = self.choose_import_resource_class(confirm_form)(**res_kwargs)
imp_kwargs = self.get_import_data_kwargs(
request, *args, form=confirm_form, **kwargs
)
imp_kwargs = self.get_import_data_kwargs(request, form=confirm_form, **kwargs)

return resource.import_data(
dataset,
Expand Down Expand Up @@ -472,7 +470,7 @@ def import_action(self, request, *args, **kwargs):
if not import_form.errors:
# prepare kwargs for import data, if needed
res_kwargs = self.get_import_resource_kwargs(
request, *args, form=import_form, **kwargs
request, form=import_form, **kwargs
)
resource = self.choose_import_resource_class(import_form)(
**res_kwargs
Expand Down Expand Up @@ -500,7 +498,7 @@ def import_action(self, request, *args, **kwargs):
)
else:
res_kwargs = self.get_import_resource_kwargs(
request, *args, form=import_form, **kwargs
request, form=import_form, **kwargs
)
resource_classes = self.get_import_resource_classes()
resources = [
Expand Down

0 comments on commit 094d436

Please sign in to comment.