Skip to content

Commit

Permalink
Do not needlessly override the widget if it's set explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Dec 16, 2024
1 parent b3c3a15 commit 1569241
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions django_prose_editor/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def formfield(self, **kwargs):
return super().formfield(**defaults)


def _is(widget, widget_class):
return (
issubclass(widget, widget_class)
if isinstance(widget, type)
else isinstance(widget, widget_class)
)


class ProseEditorFormField(forms.CharField):
widget = ProseEditorWidget

Expand All @@ -67,15 +75,9 @@ def __init__(self, *args, **kwargs):
# We don't know if widget is set, and if it is, we do not know if it is
# a class or an instance of the widget. The following if statement
# should take all possibilities into account.
if widget and (
(
isinstance(widget, type)
and issubclass(widget, widgets.AdminTextareaWidget)
)
or isinstance(widget, widgets.AdminTextareaWidget)
):
if widget and _is(widget, widgets.AdminTextareaWidget):
kwargs["widget"] = AdminProseEditorWidget
else:
elif not widget or not _is(widget, ProseEditorWidget):
kwargs["widget"] = ProseEditorWidget

super().__init__(*args, **kwargs)
Expand Down

0 comments on commit 1569241

Please sign in to comment.