experimenter/typings/import_export/admin.pyi (76 lines of code) (raw):
"""
This type stub file was generated by pyright.
"""
from django.contrib import admin
from django.utils.decorators import method_decorator
from django.views.decorators.http import require_POST
from .mixins import BaseExportMixin, BaseImportMixin
class ImportExportMixinBase:
def get_model_info(self): ...
class ImportMixin(BaseImportMixin, ImportExportMixinBase):
"""
Import mixin.
This is intended to be mixed with django.contrib.admin.ModelAdmin
https://docs.djangoproject.com/en/dev/ref/contrib/admin/
"""
change_list_template = ...
import_template_name = ...
from_encoding = ...
skip_admin_log = ...
tmp_storage_class = ...
def get_skip_admin_log(self): ...
def get_tmp_storage_class(self): ...
def has_import_permission(self, request): # -> Literal[True]:
"""
Returns whether a request has import permission.
"""
...
def get_urls(self): ...
@method_decorator(require_POST)
def process_import(self, request, *args, **kwargs): # -> HttpResponseRedirect | None:
"""
Perform the actual import action (after the user has confirmed the import)
"""
...
def process_dataset(self, dataset, confirm_form, request, *args, **kwargs): ...
def process_result(self, result, request): ...
def generate_log_entries(self, result, request): ...
def add_success_message(self, result, request): ...
def get_import_context_data(self, **kwargs): ...
def get_context_data(self, **kwargs): ...
def get_import_form(self): # -> Type[ImportForm]:
"""
Get the form type used to read the import format and file.
"""
...
def get_confirm_import_form(self): # -> Type[ConfirmImportForm]:
"""
Get the form type (class) used to confirm the import.
"""
...
def get_form_kwargs(self, form, *args, **kwargs): # -> dict[str, Unknown]:
"""
Prepare/returns kwargs for the import form.
To distinguish between import and confirm import forms,
the following approach may be used:
if isinstance(form, ImportForm):
# your code here for the import form kwargs
# e.g. update.kwargs({...})
elif isinstance(form, ConfirmImportForm):
# your code here for the confirm import form kwargs
# e.g. update.kwargs({...})
...
"""
...
def get_import_data_kwargs(self, request, *args, **kwargs): # -> dict[str, Unknown]:
"""
Prepare kwargs for import_data.
"""
...
def write_to_tmp_storage(self, import_file, input_format): ...
def import_action(
self, request, *args, **kwargs
): # -> HttpResponse | TemplateResponse:
"""
Perform a dry_run of the import to make sure the import will not
result in errors. If there where no error, save the user
uploaded file to a local temp file that will be used by
'process_import' for the actual import.
"""
...
def changelist_view(self, request, extra_context=...): ...
class ExportMixin(BaseExportMixin, ImportExportMixinBase):
"""
Export mixin.
This is intended to be mixed with django.contrib.admin.ModelAdmin
https://docs.djangoproject.com/en/dev/ref/contrib/admin/
"""
change_list_template = ...
export_template_name = ...
to_encoding = ...
def get_urls(self): ...
def has_export_permission(self, request): # -> Literal[True]:
"""
Returns whether a request has export permission.
"""
...
def get_export_queryset(self, request):
"""
Returns export queryset.
Default implementation respects applied search and filters.
"""
...
def get_export_data(self, file_format, queryset, *args, **kwargs):
"""
Returns file_format representation for given queryset.
"""
...
def get_export_context_data(self, **kwargs): ...
def get_context_data(self, **kwargs): ...
def get_export_form(self): # -> Type[ExportForm]:
"""
Get the form type used to read the export format.
"""
...
def export_action(self, request, *args, **kwargs): ...
def changelist_view(self, request, extra_context=...): ...
def get_export_filename(self, request, queryset, file_format): ...
class ImportExportMixin(ImportMixin, ExportMixin):
"""
Import and export mixin.
"""
change_list_template = ...
class ImportExportModelAdmin(ImportExportMixin, admin.ModelAdmin):
"""
Subclass of ModelAdmin with import/export functionality.
"""
...
class ExportActionMixin(ExportMixin):
"""
Mixin with export functionality implemented as an admin action.
"""
change_list_template = ...
def __init__(self, *args, **kwargs) -> None:
"""
Adds a custom action form initialized with the available export
formats.
"""
...
def export_admin_action(self, request, queryset): # -> HttpResponse | None:
"""
Exports the selected rows using file_format.
"""
...
def get_actions(self, request):
"""
Adds the export action to the list of available actions.
"""
...
@property
def media(self): ...
class ExportActionModelAdmin(ExportActionMixin, admin.ModelAdmin):
"""
Subclass of ModelAdmin with export functionality implemented as an
admin action.
"""
...
class ImportExportActionModelAdmin(ImportMixin, ExportActionModelAdmin):
"""
Subclass of ExportActionModelAdmin with import/export functionality.
Export functionality is implemented as an admin action.
"""
...