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

Goodup #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion fluent_contents/admin/contentitems.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.contrib.contenttypes.admin import BaseGenericInlineFormSet, GenericInlineModelAdmin

from nested_inline.admin import NestedStackedInline, NestedModelAdmin

from fluent_contents import appsettings, extensions
from fluent_contents.forms import ContentItemForm
from fluent_contents.models import Placeholder, get_parent_language_code
Expand Down Expand Up @@ -80,7 +82,7 @@ def type_name(self):
return self.model.__name__


class BaseContentItemInline(GenericInlineModelAdmin):
class BaseContentItemInline(NestedStackedInline, GenericInlineModelAdmin):
"""
The ``InlineModelAdmin`` class used for all content items.
"""
Expand All @@ -95,6 +97,7 @@ class BaseContentItemInline(GenericInlineModelAdmin):
ordering = ("sort_order",)
template = "admin/fluent_contents/contentitem/inline_container.html"
is_fluent_editor_inline = True # Allow admin templates to filter the inlines
inlines = []

# overwritten by subtype
name = None
Expand Down Expand Up @@ -162,6 +165,7 @@ def get_content_item_inlines(plugins=None, base=BaseContentItemInline):
"raw_id_fields",
"filter_vertical",
"filter_horizontal",
"inlines",
"radio_fields",
"prepopulated_fields",
"formfield_overrides",
Expand Down
5 changes: 4 additions & 1 deletion fluent_contents/admin/placeholderfield.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from functools import partial

from nested_inline.admin import NestedModelAdmin

from django.forms import Media

from fluent_contents import extensions
Expand All @@ -21,8 +23,9 @@ def media(self):
media = super().media
return Media(js=[f for f in media._js if not f.endswith("cp_tabs.js")], css=media._css)

inlines = []

class PlaceholderFieldAdmin(PlaceholderEditorAdmin):
class PlaceholderFieldAdmin(PlaceholderEditorAdmin, NestedModelAdmin):
"""
The base functionality for :class:`~django.contrib.admin.ModelAdmin` dialogs to display placeholder fields.

Expand Down
3 changes: 3 additions & 0 deletions fluent_contents/extensions/pluginbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class AnnouncementBlockPlugin(ContentPlugin):
#: The template to render the frontend HTML output.
render_template = None

#: The nested inlines for the admin view.
inlines = []

#: By default, rendered output is cached, and updated on admin changes.
cache_output = True

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% load i18n %}
{% load i18n static %}
{% with recursive_formset=inline_admin_formset stacked_template='admin/edit_inline/stacked-nested.html' tabular_template='admin/edit_inline/tabular-nested.html'%}

<div id="{{ inline_admin_formset.formset.prefix }}-group" class="inline-group inline-contentitem-group inline-{{ inline_admin_formset.formset.type_name }}-group" data-inline-model="{{ inline_admin_formset.formset.type_name }}">
{{ inline_admin_formset.formset.management_form }}
{{ inline_admin_formset.formset.non_form_errors }}
Expand All @@ -7,9 +9,10 @@
{% include inline_admin_formset.opts.cp_admin_init_template %}
{% endif %}


{# looping in `inline_admin_formset.formset.forms` excludes empty form #}
{# looping in `inline_admin_formset` includes the empty placeholder as last item #}
{% for inline_admin_form in inline_admin_formset %}
{% for inline_admin_form in recursive_formset %}
<div class="inline-related inline-{{ inline_admin_form.model_admin.type_name }}{% if forloop.last %} empty-form last-related{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
<h2 class="cp-formset-item-title cp-clearfix">
<span class="title">{{ inline_admin_formset.opts.name }}</span>
Expand All @@ -35,8 +38,23 @@ <h2 class="cp-formset-item-title cp-clearfix">
{% with inline_admin_form.form as form %}
{% include inline_admin_formset.opts.cp_admin_form_template %}
{% endwith %}
{% if inline_admin_form.form.nested_formsets %}
{% for inline_admin_formset in inline_admin_form.form.nested_formsets %}
{% if inline_admin_formset.opts.template == stacked_template %}
{% include stacked_template with prev_prefix=recursive_formset.formset.prefix loopCounter=forloop.parentloop.counter0 %}
{% else %}
{% include tabular_template with prev_prefix=recursive_formset.formset.prefix loopCounter=forloop.parentloop.counter0 %}
{% endif %}
<div class="nested-inline-bottom-border"></div>
{% endfor %}
{% endif %}

{% endblock %}
</div>
</div>
{% endfor %}
</div>


{% endwith %}

</div>
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def find_version(*parts):
"django-polymorphic>=2.1.2",
"django-tag-parser>=3.2",
"django-template-analyzer>=1.6.2",
"future>=0.12.2",
'django-nested-inline>=0.3.7',
"html5lib >= 1.1",
],
requires=["Django (>=2.2)"],
Expand Down