Admin¶
- class import_export_extensions.admin.model_admins.export_job_admin.ExportJobAdmin(model, admin_site)¶
Admin class for debugging ExportJob.
- cancel_jobs(request: WSGIRequest, queryset: QuerySet)¶
Admin action for cancelling data export.
- export_job_progress_view(request: WSGIRequest, job_id: int, **kwargs)¶
View to return ExportJob status as JSON.
If current status is exporting, view also returns job state and percent of completed work.
- Return:
Response: dictionary with status (optionally, state and percent).
- form¶
alias of
ExportJobAdminForm
- get_urls()¶
Add url to get current export job progress in JSON representation.
/admin/import_export_extensions/exportjob/<job_id>/progress/
- class import_export_extensions.admin.model_admins.import_job_admin.ImportJobAdmin(model, admin_site)¶
Admin class for debugging ImportJob.
- cancel_jobs(request: WSGIRequest, queryset: QuerySet)¶
Admin action for cancelling data import.
- confirm_jobs(request: WSGIRequest, queryset: QuerySet)¶
Admin action for confirming data import.
- form¶
alias of
ImportJobAdminForm
- get_queryset(request: WSGIRequest)¶
Override get_queryset.
Do not get result from db because it can be rather big and is not used in admin.
- get_urls()¶
Add url to get current import job progress in JSON representation.
/admin/import_export_extensions/importjob/<job_id>/progress/
- import_job_progress_view(request: WSGIRequest, job_id: int, **kwargs) JsonResponse¶
View to return
ImportJobstatus as JSON.If current status is parsing/importing, view also returns job state and percent of completed work.
- Return:
Response: dictionary with status (optionally, state and percent).
- class import_export_extensions.admin.model_admins.mixins.BaseImportExportJobAdminMixin¶
Mixin provides common methods for ImportJob and ExportJob admins.
- get_from_content_type(obj: BaseJob) ContentType | None¶
Shortcut to get object from content_type.
- has_add_permission(request: WSGIRequest, *args, **kwargs) bool¶
Import/Export Jobs should not be created using this interface.
- has_delete_permission(request: WSGIRequest, *args, **kwargs) bool¶
Import/Export Jobs should not be deleted using this interface.
Instead, admins must cancel jobs.
- class import_export_extensions.admin.forms.export_job_admin_form.ExportJobAdminForm(instance: ExportJob, *args, **kwargs)¶
Admin form for ExportJob model.
Adds custom export_progressbar field that displays current export progress using AJAX requests to specified endpoint. Fields widget is defined in __init__ method.
- property media¶
Return all media required to render the widgets on this form.
- class import_export_extensions.admin.forms.import_job_admin_form.ImportJobAdminForm(instance: ImportJob, *args, **kwargs)¶
Admin form for
ImportJobmodel.Adds custom import_progressbar field that displays current import progress using AJAX requests to specified endpoint. Fields widget is defined in __init__ method.
- property media¶
Return all media required to render the widgets on this form.
- class import_export_extensions.admin.forms.import_admin_form.ForceImportForm(formats, resources, **kwargs)¶
Import form with force_import option.
- property media¶
Return all media required to render the widgets on this form.
- class import_export_extensions.admin.mixins.types.ModelInfo(meta: Options)¶
Contain base info about imported model.
- property app_label¶
App label of model.
- property app_model_name: str¶
Return url name.
- property name: str¶
Get name of model.
- class import_export_extensions.admin.mixins.export_mixin.CeleryExportAdminMixin(*args, **kwargs)¶
Admin mixin for celery export.
- Admin export work-flow is:
GET celery_export_action() - display form with format type input
- POST celery_export_action() - create ExportJob and starts data export
This view redirects to next view:
- GET celery_export_job_status_view() - display ExportJob status (with
progress bar). When data exporting is done, redirect to next view:
- GET celery_export_job_results_view() - display export results. If no
errors - success message and link to the file with exported data. If errors - traceback and error message.
- celery_export_action(request, *args, **kwargs)¶
Show and handle export.
GET: show export form with format_type input POST: create ExportJob instance and redirect to it’s status
- changelist_view(request: WSGIRequest, context: dict[str, Any] | None = None)¶
Add the check for permission to changelist template context.
- create_export_job(request: WSGIRequest, resource_class: type[CeleryResource | CeleryModelResource], resource_kwargs: dict[str, Any], file_format: type[Format]) ExportJob¶
Create and return instance of export job with chosen format.
- export_form_class¶
alias of
SelectableFieldsExportForm
- export_job_results_view(request: WSGIRequest, job_id: int, *args, **kwargs) HttpResponse¶
Display export results.
- GET-request:
show message
if no errors - show file link
if errors - show traceback and error
- export_job_status_view(request: WSGIRequest, job_id: int, **kwargs) HttpResponse¶
View to track export job status.
Displays current export job status and progress (using JS + another view).
If job result is ready - redirects to another page to see results.
- get_export_context_data(**kwargs)¶
Get context data for export.
- get_export_form_class()¶
Get the form class used to read the export format.
- get_resource_kwargs(request, *args, **kwargs)¶
Return filter kwargs for resource queryset.
- get_urls()¶
Return list of urls.
- /<model/celery-export/:
ExportForm (‘export_action’ method)
- /<model>/celery-export/<ID>/:
status of ExportJob and progress bar (‘export_job_status_view’)
- /<model>/celery-export/<ID>/results/:
table with export results (errors)
- has_export_permission(request)¶
Returns whether a request has export permission.
- class import_export_extensions.admin.mixins.import_export_mixin.CeleryImportExportMixin(*args, **kwargs)¶
Import and export mixin.
- class import_export_extensions.admin.mixins.import_mixin.CeleryImportAdminMixin(*args, **kwargs)¶
Admin mixin for celery import.
Admin import work-flow is:
GET
celery_import_action()- display form with import file input- POST
celery_import_action()- save file and create ImportJob. This view redirects to next view:
- GET
celery_import_job_status_view()- display ImportJob status (with progress bar and critical errors occurred). When data parsing is done, redirect to next view:
- GET
celery_import_job_results_view()- display rows that will be imported and data parse errors. If no errors - next step. If errors - display same form as in
import_action()- POST
celery_import_job_results_view()- start data importing and redirect back to GET
celery_import_job_status_view()with progress bar and import totals.
- celery_import_action(request: WSGIRequest, *args, **kwargs)¶
Show and handle ImportForm.
- GET:
show import form with data_file input form
- POST:
create ImportJob instance and redirect to it’s status
- celery_import_job_results_view(request: WSGIRequest, job_id: int, *args, **kwargs) HttpResponse¶
Display table with import results and import confirm form.
- GET-request:
show row results
if data valid - show import confirmation form
if data invalid - show ImportForm for uploading other file
- POST-request:
start data importing if data is correct
- celery_import_job_status_view(request: WSGIRequest, job_id: int, **kwargs) HttpResponse¶
View to track import job status.
Displays current import job status and progress (using JS + another view).
If job result is ready - redirects to another page to see results.
Also generates admin log entries if the job has IMPORTED status.
- changelist_view(request: WSGIRequest, context: dict[str, Any] | None = None)¶
Add the check for permission to changelist template context.
- confirm_form_class¶
alias of
ConfirmImportForm
- create_confirm_form(request, import_form=None)¶
Added in version 3.0.
Return a form instance to use for the ‘confirm’ import step. This method can be extended to make dynamic form updates to the form after it has been instantiated. You might also look to override the following:
- create_import_form(request)¶
Added in version 3.0.
Return a form instance to use for the ‘initial’ import step. This method can be extended to make dynamic form updates to the form after it has been instantiated. You might also look to override the following:
- create_import_job(request: WSGIRequest, form: Form, resource: CeleryResource | CeleryModelResource)¶
Create and return instance of import job.
- get_confirm_form_class(request)¶
Added in version 3.0.
Return the form class to use for the ‘confirm’ import step. If you only have a single custom form class, you can set the
confirm_form_classattribute to change this for your subclass.
- get_confirm_form_initial(request, import_form)¶
Added in version 3.0.
Return a dictionary of initial field values to be provided to the ‘confirm’ form.
- get_confirm_form_kwargs(request, import_form=None)¶
Added in version 3.0.
Return a dictionary of values with which to initialize the ‘confirm’ form (including the initial values returned by
get_confirm_form_initial()).
- get_import_context_data(**kwargs)¶
Get context data for import.
- get_import_form_class(request)¶
Added in version 3.0.
Return the form class to use for the ‘import’ step. If you only have a single custom form class, you can set the
import_form_classattribute to change this for your subclass.
- get_import_form_initial(request)¶
Added in version 3.0.
Return a dictionary of initial field values to be provided to the ‘import’ form.
- get_import_form_kwargs(request)¶
Added in version 3.0.
Return a dictionary of values with which to initialize the ‘import’ form (including the initial values returned by
get_import_form_initial()).
- get_urls()¶
Return list of urls.
- /<model>/<celery-import>/:
ImportForm (‘celery_import_action’ method)
- /<model>/<celery-import>/<ID>/:
status of ImportJob and progress bar (‘celery_import_job_status_view’)
- /<model>/<celery-import>/<ID>/results/:
table with import results (errors) and import confirmation (‘celery_import_job_results_view’)
- has_import_permission(request)¶
Returns whether a request has import permission.
- import_form_class¶
alias of
ForceImportForm
- POST
- class import_export_extensions.admin.widgets.ProgressBarWidget(*args, **kwargs)¶
Widget for progress bar field.
Value for progress_bar element is changed using JS code.
- class Media¶
Class with custom assets for widget.
- render(*args, **kwargs) str¶
Render HTML5 progress element.
Additionally, method provides hidden import_job_url and export_job_url value that is used in js/admin/progress_bar.js to send GET requests.