Skip to content

Commit

Permalink
feat: django-import-export 4.0 support (3.x deprecated)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav committed May 21, 2024
1 parent 61c60f3 commit 14d8503
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/unfold/contrib/import_export/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from django import forms
from django.utils.translation import gettext_lazy as _
from import_export.admin import ExportActionModelAdmin as BaseExportActionModelAdmin

from unfold.admin import ActionForm
from unfold.widgets import SELECT_CLASSES


def export_action_form_factory(formats):
class _ExportActionForm(ActionForm):
file_format = forms.ChoiceField(
format = forms.ChoiceField(
label=" ",
choices=formats,
required=False,
Expand Down
14 changes: 7 additions & 7 deletions src/unfold/contrib/import_export/forms.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from import_export.forms import ExportForm as BaseExportForm
from import_export.forms import ImportForm as BaseImportForm
from import_export.forms import ImportExportFormBase as BaseImportExportFormBase

from unfold.widgets import SELECT_CLASSES, UnfoldAdminFileFieldWidget


class ImportForm(BaseImportForm):
class ImportForm(BaseImportExportFormBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["import_file"].widget = UnfoldAdminFileFieldWidget()
self.fields["input_format"].widget.attrs["class"] = " ".join(SELECT_CLASSES)
self.fields["resource"].widget = UnfoldAdminFileFieldWidget()
self.fields["format"].widget.attrs["class"] = " ".join(SELECT_CLASSES)


class ExportForm(BaseExportForm):
class ExportForm(BaseImportExportFormBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["file_format"].widget.attrs["class"] = " ".join(SELECT_CLASSES)
self.fields["format"].widget.attrs["class"] = " ".join(SELECT_CLASSES)
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{% csrf_token %}

<fieldset class="border border-gray-200 mb-8 rounded-md pt-3 px-3 shadow-sm dark:border-gray-800">
{% include "unfold/helpers/field.html" with field=form.file_format %}
{% include "unfold/helpers/field.html" with field=form.format %}
</fieldset>

<button type="submit" class="bg-primary-600 border border-transparent font-medium px-3 py-2 rounded-md text-sm text-white">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</p>

<fieldset class="border border-gray-200 mb-8 rounded-md pt-3 px-3 shadow-sm dark:border-gray-800">
{% include "unfold/helpers/field.html" with field=form.import_file %}
{% include "unfold/helpers/field.html" with field=form.resource %}

{% include "unfold/helpers/field.html" with field=form.input_format %}
{% include "unfold/helpers/field.html" with field=form.format %}
</fieldset>


Expand Down

0 comments on commit 14d8503

Please sign in to comment.