Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: django-import-export 4.0 support (3.x deprecated) #398

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/unfold/contrib/import_export/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def export_action_form_factory(formats):
class _ExportActionForm(ActionForm):
file_format = forms.ChoiceField(
format = forms.ChoiceField(
label=" ",
choices=formats,
required=False,
Expand Down
13 changes: 6 additions & 7 deletions src/unfold/contrib/import_export/forms.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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