Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit fc820c0

Browse files
committed
Relocate PublishableFluentContentsAdmin into publishing app, re #22
- move `PublishableFluentContentsAdmin` class from `articles` models to the central publishing app location that makes more sense - relocate `FluentLayoutsMixin` admin mixin from `icekit.admin` module to the new `admin_mixins` module to avoid circular import problems - fix imports and document references to models and mixin to refer to new location.
1 parent 9e25aff commit fc820c0

File tree

7 files changed

+54
-47
lines changed

7 files changed

+54
-47
lines changed

docs/howto/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ with two mixin classes:
8181

8282
# admin.py
8383

84-
from icekit.admin import FluentLayoutsMixin
84+
from icekit.admin_mixins import FluentLayoutsMixin
8585

8686
class MyModelAdmin(FluentLayoutsMixin, MyModelAdminBase):
8787
...

docs/topics/publishing.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ To make a `FluentContentsPage` model publishable:
4141
* subclass your model from `icekit.publishing.models.PublishableFluentContentsPage`
4242
* subclass your model's admin from `FluentContentsPageAdmin` and `icekit.publishing.admin.PublishingAdmin`
4343

44+
To make a fluent contents model (see [ContentsPlugins]) publishable:
45+
46+
* subclass your model from `icekit.publishing.models.PublishableFluentContents`
47+
* subclass your model's admin from `icekit.publishing.admin.PublishableFluentContentsAdmin`
48+
4449
#### Note: Validating slug uniqueness
4550

4651
In publishable models, both the draft and published slugs will be identical,
@@ -225,3 +230,5 @@ rendering related content for the public and for site admins:
225230
There has been an issue discovered where `ManyToMany` fields referring both
226231
ways on models have the many to many data cloned for published and
227232
unpublished objects. This is currently being worked on.
233+
234+
[ContentsPlugins]: ../howto/plugins.md

icekit/admin.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
from django.contrib.contenttypes.models import ContentType
1111
from django.http import JsonResponse
1212
from django.utils.translation import ugettext_lazy as _
13-
from fluent_contents.admin import PlaceholderEditorAdmin
14-
from fluent_contents.analyzer import get_template_placeholder_data
15-
from fluent_contents.models import PlaceholderData
1613
from polymorphic.admin import PolymorphicParentModelAdmin
1714

1815
from icekit import models
@@ -44,37 +41,6 @@ def queryset(self, request, queryset):
4441
# MIXINS ######################################################################
4542

4643

47-
class FluentLayoutsMixin(PlaceholderEditorAdmin):
48-
"""
49-
Mixin class for models that have a ``layout`` field and fluent content.
50-
"""
51-
52-
change_form_template = 'icekit/admin/fluent_layouts_change_form.html'
53-
54-
class Media:
55-
js = ('icekit/admin/js/fluent_layouts.js', )
56-
57-
def formfield_for_foreignkey(self, db_field, *args, **kwargs):
58-
"""
59-
Update queryset for ``layout`` field.
60-
"""
61-
formfield = super(FluentLayoutsMixin, self).formfield_for_foreignkey(
62-
db_field, *args, **kwargs)
63-
if db_field.name == 'layout':
64-
formfield.queryset = formfield.queryset.for_model(self.model)
65-
return formfield
66-
67-
def get_placeholder_data(self, request, obj):
68-
"""
69-
Get placeholder data from layout.
70-
"""
71-
if not obj or not obj.layout:
72-
data = [PlaceholderData(slot='main', role='m', title='Main')]
73-
else:
74-
data = obj.layout.get_placeholder_data()
75-
return data
76-
77-
7844
class ChildModelPluginPolymorphicParentModelAdmin(PolymorphicParentModelAdmin):
7945
"""
8046
Get child models and choice labels from registered plugins.

icekit/admin_mixins.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from fluent_contents.admin import PlaceholderEditorAdmin
2+
from fluent_contents.models import PlaceholderData
3+
4+
5+
class FluentLayoutsMixin(PlaceholderEditorAdmin):
6+
"""
7+
Mixin class for models that have a ``layout`` field and fluent content.
8+
"""
9+
10+
change_form_template = 'icekit/admin/fluent_layouts_change_form.html'
11+
12+
class Media:
13+
js = ('icekit/admin/js/fluent_layouts.js', )
14+
15+
def formfield_for_foreignkey(self, db_field, *args, **kwargs):
16+
"""
17+
Update queryset for ``layout`` field.
18+
"""
19+
formfield = super(FluentLayoutsMixin, self).formfield_for_foreignkey(
20+
db_field, *args, **kwargs)
21+
if db_field.name == 'layout':
22+
formfield.queryset = formfield.queryset.for_model(self.model)
23+
return formfield
24+
25+
def get_placeholder_data(self, request, obj):
26+
"""
27+
Get placeholder data from layout.
28+
"""
29+
if not obj or not obj.layout:
30+
data = [PlaceholderData(slot='main', role='m', title='Main')]
31+
else:
32+
data = obj.layout.get_placeholder_data()
33+
return data

icekit/articles/admin.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
from django.contrib import admin
22

3-
from icekit.admin import FluentLayoutsMixin
4-
from icekit.publishing.admin import PublishingAdmin
5-
6-
7-
class PublishableFluentContentsAdmin(PublishingAdmin, FluentLayoutsMixin):
8-
"""
9-
Add publishing features for non-Page rich content models
10-
"""
11-
pass
3+
from icekit.publishing.admin import PublishableFluentContentsAdmin
124

135

146
class TitleSlugAdmin(admin.ModelAdmin):

icekit/page_types/layout_page/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from fluent_pages.integration.fluent_contents.admin import FluentContentsPageAdmin
22

3-
from icekit.admin import FluentLayoutsMixin
3+
from icekit.admin_mixins import FluentLayoutsMixin
44
from icekit.publishing.admin import PublishingAdmin
55

66

icekit/publishing/admin.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
from django.template import loader, Context
1717

1818
from fluent_pages.models.db import UrlNode
19-
from fluent_pages.adminui.pageadmin import DefaultPageChildAdmin, \
20-
_select_template_name
19+
from fluent_pages.adminui.pageadmin import _select_template_name
2120
from fluent_pages.adminui.urlnodeparentadmin import UrlNodeParentAdmin
21+
22+
from icekit.admin_mixins import FluentLayoutsMixin
23+
2224
from .models import PublishingModel
2325

2426

@@ -636,3 +638,10 @@ class ICEKitFluentPagesParentAdminMixin(
636638
):
637639
""" Add publishing features for FluentPage parent admin (listing) pages """
638640
list_filter = (PublishingStatusFilter, PublishingPublishedFilter)
641+
642+
643+
class PublishableFluentContentsAdmin(PublishingAdmin, FluentLayoutsMixin):
644+
"""
645+
Add publishing admin features for models with Fluent Contents features
646+
"""
647+
pass

0 commit comments

Comments
 (0)