Skip to content

Commit

Permalink
Add a class decorator for automatically assigning colors to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Jun 26, 2024
1 parent 2ba84b5 commit d666b07
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions content_editor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ def create(cls, model, **kwargs):
)


def auto_icon_colors(content_editor):
hue = 330
for inline in content_editor.inlines:
if issubclass(inline, ContentEditorInline) and not inline.color:
inline.color = f"oklch(0.5 0.2 {hue})"
hue -= 20
return content_editor


class ContentEditor(ModelAdmin):
"""
The ``ContentEditor`` is a drop-in replacement for ``ModelAdmin`` with the
Expand All @@ -139,6 +148,7 @@ def _content_editor_context(self, request, context):

plugins = []
adding_not_allowed = ["_adding_not_allowed"]

for iaf in context.get("inline_admin_formsets", []):
if not isinstance(iaf.opts, ContentEditorInline):
continue
Expand Down

0 comments on commit d666b07

Please sign in to comment.