-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: import_export actions form styling (#279)
- Loading branch information
1 parent
a2700bf
commit e35c5f5
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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( | ||
label=" ", | ||
choices=formats, | ||
required=False, | ||
widget=forms.Select( | ||
{"class": " ".join([*SELECT_CLASSES, "ml-3", "!w-auto", "lg:!w-40"])} | ||
), | ||
) | ||
|
||
_ExportActionForm.__name__ = "ExportActionForm" | ||
|
||
return _ExportActionForm | ||
|
||
|
||
class ExportActionModelAdmin(BaseExportActionModelAdmin): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
choices = [] | ||
formats = self.get_export_formats() | ||
if formats: | ||
for i, f in enumerate(formats): | ||
choices.append((str(i), f().get_title())) | ||
|
||
if len(formats) > 1: | ||
choices.insert(0, ("", _("Select format"))) | ||
|
||
self.action_form = export_action_form_factory(choices) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters