Skip to content

Commit

Permalink
Bump django-import-export to 4.3.4 (#13414)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos authored Feb 3, 2025
1 parent 983fc03 commit e26219d
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 183 deletions.
59 changes: 27 additions & 32 deletions stubs/django-import-export/import_export/admin.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from _typeshed import Incomplete
from collections.abc import Callable
from collections.abc import Callable, Sequence
from logging import Logger
from typing import Any, TypeVar
from typing import Any, Literal, TypeVar
from typing_extensions import TypeAlias, deprecated

from django.contrib import admin
from django.contrib.admin.helpers import ActionForm
from django.core.files import File
from django.db.models import Model, QuerySet
from django.forms import Form, Media
from django.forms import Form
from django.http.request import HttpRequest
from django.http.response import HttpResponse
from django.template.response import TemplateResponse
Expand Down Expand Up @@ -38,33 +38,21 @@ class ImportMixin(BaseImportMixin[_ModelT], ImportExportMixinBase):
import_form_class: type[Form] = ...
confirm_form_class: type[Form] = ...
from_encoding: str
import_error_display: Sequence[Literal["message", "row", "traceback"]]
skip_admin_log: bool | None
tmp_storage_class: str | type[BaseStorage]
def get_skip_admin_log(self) -> bool: ...
def get_tmp_storage_class(self) -> type[BaseStorage]: ...
def get_tmp_storage_class_kwargs(self) -> dict[str, Any]: ...
def has_import_permission(self, request: HttpRequest) -> bool: ...
def get_urls(self) -> list[URLPattern]: ...
def process_import(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ...
def process_dataset(
self,
dataset: Dataset,
confirm_form: Form,
request: HttpRequest,
*args: Any,
rollback_on_validation_errors: bool = False,
**kwargs: Any,
) -> Result: ...
def process_import(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: ...
def process_dataset(self, dataset: Dataset, form: Form, request: HttpRequest, **kwargs: Any) -> Result: ...
def process_result(self, result: Result, request: HttpRequest) -> HttpResponse: ...
def generate_log_entries(self, result: Result, request: HttpRequest) -> None: ...
def add_success_message(self, result: Result, request: HttpRequest) -> None: ...
def get_import_context_data(self, **kwargs: Any) -> dict[str, Any]: ...
def get_context_data(self, **kwargs: Any) -> dict[str, Any]: ...
@deprecated("Use get_import_form_class instead")
def get_import_form(self) -> type[Form]: ...
@deprecated("Use get_confirm_form_class instead")
def get_confirm_import_form(self) -> type[Form]: ...
@deprecated("Use get_import_form_kwargs or get_confirm_form_kwargs")
def get_form_kwargs(self, form: Form, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
def create_import_form(self, request: HttpRequest) -> Form: ...
def get_import_form_class(self, request: HttpRequest) -> type[Form]: ...
def get_import_form_kwargs(self, request: HttpRequest) -> dict[str, Any]: ...
Expand All @@ -73,42 +61,49 @@ class ImportMixin(BaseImportMixin[_ModelT], ImportExportMixinBase):
def get_confirm_form_class(self, request: HttpRequest) -> type[Form]: ...
def get_confirm_form_kwargs(self, request: HttpRequest, import_form: Form | None = None) -> dict[str, Any]: ...
def get_confirm_form_initial(self, request: HttpRequest, import_form: Form | None) -> dict[str, Any]: ...
def get_import_data_kwargs(self, request: HttpRequest, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
def get_import_data_kwargs(self, **kwargs: Any) -> dict[str, Any]: ...
def write_to_tmp_storage(self, import_file: File[bytes], input_format: Format) -> BaseStorage: ...
def add_data_read_fail_error_to_form(self, form: Form, e: Exception) -> None: ...
def import_action(self, request: HttpRequest, *args: Any, **kwargs: Any) -> TemplateResponse: ...
def import_action(self, request: HttpRequest, **kwargs: Any) -> TemplateResponse: ...
def changelist_view(self, request: HttpRequest, extra_context: dict[str, Any] | None = None) -> HttpResponse: ...

class ExportMixin(BaseExportMixin[_ModelT], ImportExportMixinBase):
import_export_change_list_template: str | None
import_export_change_list_template: str
export_template_name: str
to_encoding: str | None
export_form_class: type[Form] = ...
def get_urls(self) -> list[URLPattern]: ...
def has_export_permission(self, request: HttpRequest) -> bool: ...
def get_export_queryset(self, request: HttpRequest) -> QuerySet[_ModelT]: ...
def get_export_data(self, file_format: Format, queryset: QuerySet[_ModelT], *args: Any, **kwargs: Any) -> str | bytes: ...
def get_export_data(
self, file_format: Format, request: HttpRequest, queryset: QuerySet[_ModelT], **kwargs: Any
) -> str | bytes: ...
def get_export_context_data(self, **kwargs: Any) -> dict[str, Any]: ...
def get_context_data(self, **kwargs: Any) -> dict[str, Any]: ...
@deprecated("Use get_export_form_class or use the export_form_class attribute")
def get_export_form(self) -> Form: ...
def get_export_form_class(self) -> type[Form]: ...
def export_action(self, request: HttpRequest, *args: Any, **kwargs: Any) -> TemplateResponse: ...
def export_action(self, request: HttpRequest) -> TemplateResponse: ...
@deprecated(
"The 'get_valid_export_item_pks()' method is deprecated and will be removed in a future release. "
"Overwrite 'get_queryset()' or 'get_export_queryset()' instead."
)
def get_valid_export_item_pks(self, request: HttpRequest) -> list[str]: ...
def changelist_view(self, request: HttpRequest, extra_context: dict[str, Any] | None = None) -> HttpResponse: ...
def get_export_filename(self, request: HttpRequest, queryset: QuerySet[_ModelT], file_format: Format) -> str: ... # type: ignore[override]
def init_request_context_data(self, request: HttpRequest, form: Form) -> dict[str, Any]: ...

class ImportExportMixin(ImportMixin[_ModelT], ExportMixin[_ModelT]):
import_export_change_list_template: str

class ImportExportMixin(ImportMixin[_ModelT], ExportMixin[_ModelT]): ...
class ImportExportModelAdmin(ImportExportMixin[_ModelT], admin.ModelAdmin[_ModelT]): ... # type: ignore[misc]

class ExportActionMixin(ExportMixin[_ModelT]):
change_form_template: str
show_change_form_export: bool
action_form: type[ActionForm]
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
def change_view(
self, request: HttpRequest, object_id: str, form_url: str = "", extra_context: dict[str, Any] | None = None
) -> HttpResponse: ...
def response_change(self, request: HttpRequest, obj: _ModelT) -> HttpResponse: ...
def export_admin_action(self, request: HttpRequest, queryset: QuerySet[_ModelT]) -> HttpResponse: ...
def get_actions(self, request: HttpRequest) -> dict[str, tuple[Callable[..., str], str, str] | None]: ...
@property
def media(self) -> Media: ...

class ExportActionModelAdmin(ExportActionMixin[_ModelT], admin.ModelAdmin[_ModelT]): ... # type: ignore[misc]
class ImportExportActionModelAdmin(ImportMixin[_ModelT], ExportActionModelAdmin[_ModelT]): ... # type: ignore[misc]
12 changes: 12 additions & 0 deletions stubs/django-import-export/import_export/command_utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from _typeshed import StrPath
from typing import Any

from .formats.base_formats import Format
from .resources import ModelResource

def get_resource_class(model_or_resource_class: str) -> ModelResource[Any]: ...

MIME_TYPE_FORMAT_MAPPING: dict[str, type[Format]]

def get_format_class(format_name: str, file_name: StrPath, encoding: str | None = None) -> Format: ...
def get_default_format_names() -> str: ...
11 changes: 11 additions & 0 deletions stubs/django-import-export/import_export/declarative.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import _typeshed
from logging import Logger
from typing import Any

logger: Logger

class DeclarativeMetaclass(type):
def __new__(cls: type[_typeshed.Self], name: str, bases: tuple[type[Any], ...], attrs: dict[str, Any]) -> _typeshed.Self: ...

class ModelDeclarativeMetaclass(DeclarativeMetaclass):
def __new__(cls: type[_typeshed.Self], name: str, bases: tuple[type[Any], ...], attrs: dict[str, Any]) -> _typeshed.Self: ...
9 changes: 9 additions & 0 deletions stubs/django-import-export/import_export/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
from typing import Any

class ImportExportError(Exception): ...
class FieldError(ImportExportError): ...
class WidgetError(ImportExportError): ...

class ImportError(ImportExportError):
error: Exception
number: int | None
row: dict[str, Any] | None
def __init__(self, error: Exception, number: int | None = None, row: dict[str, Any] | None = None) -> None: ...
8 changes: 4 additions & 4 deletions stubs/django-import-export/import_export/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Field:
dehydrate_method: str | None = None,
m2m_add: bool = False,
) -> None: ...
def clean(self, data: Mapping[str, Any], **kwargs: Any) -> Any: ...
def get_value(self, obj: Model) -> Any: ...
def save(self, obj: Model, data: Mapping[str, Any], is_m2m: bool = False, **kwargs: Any) -> None: ...
def export(self, obj: Model) -> str: ...
def clean(self, row: Mapping[str, Any], **kwargs: Any) -> Any: ...
def get_value(self, instance: Model) -> Any: ...
def save(self, instance: Model, row: Mapping[str, Any], is_m2m: bool = False, **kwargs: Any) -> None: ...
def export(self, instance: Model, **kwargs: Any) -> str: ...
def get_dehydrate_method(self, field_name: str | None = None) -> str: ...
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from _typeshed import Incomplete, ReadableBuffer
from logging import Logger
from typing import IO, Any, ClassVar
from typing_extensions import Self, TypeAlias

Dataset: TypeAlias = Incomplete # tablib.Dataset

logger: Logger

class Format:
def get_title(self) -> type[Self]: ...
def create_dataset(self, in_stream: str | bytes | IO[Any]) -> Dataset: ...
Expand Down Expand Up @@ -43,8 +46,7 @@ class TSV(TextFormat):
class ODS(TextFormat):
def export_data(self, dataset: Dataset, **kwargs: Any) -> bytes: ...

class HTML(TextFormat):
def export_data(self, dataset: Dataset, **kwargs: Any) -> str: ...
class HTML(TextFormat): ...

class XLS(TablibFormat):
def export_data(self, dataset: Dataset, **kwargs: Any) -> bytes: ...
Expand All @@ -55,3 +57,4 @@ class XLSX(TablibFormat):
def create_dataset(self, in_stream: ReadableBuffer) -> Dataset: ... # type: ignore[override]

DEFAULT_FORMATS: list[type[Format]]
BINARY_FORMATS: list[type[Format]]
25 changes: 16 additions & 9 deletions stubs/django-import-export/import_export/forms.pyi
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
from collections.abc import Iterable, Sequence
from typing import Any

from django import forms
from django.contrib.admin.helpers import ActionForm

from .formats.base_formats import Format
from .resources import Resource
from .resources import ModelResource, Resource

class ImportExportFormBase(forms.Form):
resource: forms.ChoiceField
def __init__(self, *args: Any, resources: list[type[Resource[Any]]] | None = None, **kwargs: Any) -> None: ...
format: forms.ChoiceField
def __init__(
self, formats: list[type[Format]], resources: list[type[Resource[Any]]] | None = None, **kwargs: Any
) -> None: ...

class ImportForm(ImportExportFormBase):
import_file: forms.FileField
input_format: forms.ChoiceField
def __init__(self, import_formats: list[Format], *args: Any, **kwargs: Any) -> None: ...
field_order: Sequence[str]
@property
def media(self) -> forms.Media: ...

class ConfirmImportForm(forms.Form):
import_file_name: forms.CharField
original_file_name: forms.CharField
input_format: forms.CharField
resource: forms.CharField
def clean_import_file_name(self) -> str: ...

class ExportForm(ImportExportFormBase):
file_format: forms.ChoiceField
def __init__(self, formats: list[Format], *args: Any, **kwargs: Any) -> None: ...
export_items: forms.MultipleChoiceField

def export_action_form_factory(formats: list[tuple[str, str]]) -> type[ActionForm]: ...
class SelectableFieldsExportForm(ExportForm):
resources: Iterable[ModelResource[Any]]
is_selectable_fields_form: bool
resource_fields: dict[str, list[str]]
@staticmethod
def create_boolean_field_name(resource: ModelResource[Any], field_name: str) -> str: ...
def get_selected_resource(self) -> ModelResource[Any]: ...
def get_selected_resource_export_fields(self) -> list[str]: ...
35 changes: 17 additions & 18 deletions stubs/django-import-export/import_export/mixins.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from _typeshed import Incomplete, SupportsGetItem
from logging import Logger
from typing import Any, Generic, TypeVar
from typing_extensions import TypeAlias
from typing_extensions import TypeAlias, deprecated

from django.db.models import Model, QuerySet
from django.forms import BaseForm, Form
Expand All @@ -19,7 +19,6 @@ logger: Logger
_ModelT = TypeVar("_ModelT", bound=Model)

class BaseImportExportMixin(Generic[_ModelT]):
resource_class: type[Resource[_ModelT]]
resource_classes: SupportsGetItem[int, type[Resource[_ModelT]]]
@property
def formats(self) -> list[type[Format]]: ...
Expand All @@ -28,39 +27,39 @@ class BaseImportExportMixin(Generic[_ModelT]):
@property
def import_formats(self) -> list[type[Format]]: ...
def check_resource_classes(self, resource_classes: SupportsGetItem[int, type[Resource[_ModelT]]]) -> None: ...
def get_resource_classes(self) -> list[type[Resource[_ModelT]]]: ...
def get_resource_classes(self, request: HttpRequest) -> list[type[Resource[_ModelT]]]: ...
def get_resource_kwargs(self, request: HttpRequest, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
def get_resource_index(self, form: Form) -> int: ...

class BaseImportMixin(BaseImportExportMixin[_ModelT]):
def get_import_resource_classes(self) -> list[type[Resource[_ModelT]]]: ...
skip_import_confirm: bool
def get_import_resource_classes(self, request: HttpRequest) -> list[type[Resource[_ModelT]]]: ...
def get_import_formats(self) -> list[Format]: ...
def get_import_resource_kwargs(self, request: HttpRequest, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
def choose_import_resource_class(self, form: Form) -> type[Resource[_ModelT]]: ...
def get_import_resource_kwargs(self, request: HttpRequest, **kwargs: Any) -> dict[str, Any]: ...
def choose_import_resource_class(self, form: Form, request: HttpRequest) -> type[Resource[_ModelT]]: ...
def is_skip_import_confirm_enabled(self) -> bool: ...

class BaseExportMixin(BaseImportExportMixin[_ModelT]):
model: Model
escape_exported_data: bool
escape_html: bool
escape_formulae: bool
@property
def should_escape_html(self) -> bool: ...
@property
def should_escape_formulae(self) -> bool: ...
skip_export_form: bool
skip_export_form_from_action: bool
def get_export_formats(self) -> list[Format]: ...
def get_export_resource_classes(self) -> list[Resource[_ModelT]]: ...
def choose_export_resource_class(self, form: Form) -> Resource[_ModelT]: ...
def get_export_resource_kwargs(self, request: HttpRequest, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
def get_data_for_export(self, request: HttpRequest, queryset: QuerySet[_ModelT], *args: Any, **kwargs: Any) -> Dataset: ...
def get_export_resource_classes(self, request: HttpRequest) -> list[Resource[_ModelT]]: ...
def choose_export_resource_class(self, form: Form, request: HttpRequest) -> Resource[_ModelT]: ...
def get_export_resource_kwargs(self, request: HttpRequest, **kwargs: Any) -> dict[str, Any]: ...
def get_data_for_export(self, request: HttpRequest, queryset: QuerySet[_ModelT], **kwargs: Any) -> Dataset: ...
def get_export_filename(self, file_format: Format) -> str: ...
def is_skip_export_form_enabled(self) -> bool: ...
def is_skip_export_form_from_action_enabled(self) -> bool: ...

class ExportViewMixin(BaseExportMixin[_ModelT]):
form_class: type[BaseForm] = ...
def get_export_data(self, file_format: Format, queryset: QuerySet[_ModelT], *args: Any, **kwargs: Any) -> str | bytes: ...
def get_export_data(self, file_format: Format, queryset: QuerySet[_ModelT], **kwargs: Any) -> str | bytes: ...
def get_context_data(self, **kwargs: Any) -> dict[str, Any]: ...
def get_form_kwargs(self) -> dict[str, Any]: ...

_FormT = TypeVar("_FormT", bound=BaseForm)

@deprecated("ExportViewFormMixin is deprecated and will be removed in a future release.")
class ExportViewFormMixin(ExportViewMixin[_ModelT], FormView[_FormT]): # type: ignore[misc]
def form_valid(self, form: _FormT) -> HttpResponse: ...
32 changes: 32 additions & 0 deletions stubs/django-import-export/import_export/options.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from collections.abc import Sequence
from typing import Any, Generic, TypeVar

from django.db.models import Model

from .instance_loaders import BaseInstanceLoader

_ModelT = TypeVar("_ModelT", bound=Model)

class ResourceOptions(Generic[_ModelT]):
model: _ModelT | str
fields: Sequence[str] | None
exclude: Sequence[str] | None
instance_loader_class: type[BaseInstanceLoader] | None
import_id_fields: Sequence[str]
export_order: Sequence[str] | None
import_order: Sequence[str] | None
widgets: dict[str, Any] | None
use_transactions: bool | None
skip_unchanged: bool
report_skipped: bool
clean_model_instances: bool
chunk_size: int | None
skip_diff: bool
skip_html_diff: bool
use_bulk: bool
batch_size: int
force_init_instance: bool
using_db: str | None
store_row_values: bool
store_instance: bool
use_natural_foreign_keys: bool
Loading

0 comments on commit e26219d

Please sign in to comment.