Application content, make entry_detail override ``main``

49 views
Skip to first unread message

Skylar Saveland

unread,
Jun 8, 2010, 2:32:55 AM6/8/10
to Django FeinCMS
Using:

Page.create_content_type(ApplicationContent, APPLICATIONS=(
('content.news_urls', 'News Articles'),
))

I add 'News Article' content at say '/news/' in ``main``.

The other content in ``main`` that I put at '/news/' shows up in the
children/detail pages.

I would like to add my urls at /news/ in the main region with some
other stuff. I don't want to see this "other stuff" when I go to the
article detail. There is no way to *override a region moving forward
from:

{% load applicationcontent_tags %}

{% fragment request "title" %}{{ object.title }}{% endfragment %}

{% block content %}{% endblock %}
<div class="entry">
<h2>{{ object.title }}</h2>
<span class="date">{{ object.published_date|date:"d.m.Y" }}</span>

{{ object.content|safe }}
</div>

?

Matthias Kestenholz

unread,
Jun 8, 2010, 2:41:23 AM6/8/10
to django-...@googlegroups.com
On Tue, Jun 8, 2010 at 8:32 AM, Skylar Saveland
<skylar....@gmail.com> wrote:
> Using:
>
> Page.create_content_type(ApplicationContent, APPLICATIONS=(
>        ('content.news_urls', 'News Articles'),
>    ))
>
> I add 'News Article' content at say '/news/' in ``main``.
>
> The other content in ``main`` that I put at '/news/' shows up in the
> children/detail pages.
>
> I would like to add my urls at /news/ in the main region with some
> other stuff. I don't want to see this "other stuff" when I go to the
> article detail.  There is no way to *override a region moving forward
> from:
> [...]


There is a way to do this, although it may seem convoluted at first sight

Add the following code to the place where you create the ApplicationContent:


def get_admin_fields(form, *args, **kwargs):
return {
'exclusive_subpages': forms.BooleanField(
label=capfirst(_('exclusive subpages')),
required=False,
initial=form.instance.parameters.get('exclusive_subpages', False),
help_text=_('Exclude everything other than the
application\'s content when rendering subpages.'),
),
}


Page.create_content_type(ApplicationContent, APPLICATIONS=(
('content.news_urls', 'News Articles', {'admin_fields': get_admin_fields}),
)


Once you add the news articles to a page and reload the editor (save
and continue editing), you'll see an additional checkbox, "exclusive
subpages". Check this and save.

Next, add 'feincms.context_processors.appcontent_parameters' to your
TEMPLATE_CONTEXT_PROCESSORS. This will ensure that the templates know
the value of exclusive_subpages.

As the final step, replace your feincms_render_region call in your
base template with the following snippet:

{% block content %}
{% if exclusive_subpages and in_appcontent_subpage %}
{% feincms_render_region_appcontent feincms_page "main" request %}
{% else %}
{% feincms_render_region feincms_page "main" request %}
{% endif %}
{% endblock %}

Note that the value of in_appcontent_subpage is always determined by
feincms.views.applicationcontent.handler (resp. build_page_response)

This special use case could be made more simple of course. On the
other hand, it serves as a nice example how to customize application
contents from the administration interface.

Matthias


--
Matthias Kestenholz - Dipl. Umwelt-Natw. ETH - Konzept & Programmierung
FEINHEIT GmbH - Molkenstrasse 21 - CH-8004 Zürich
FeinCMS Django CMS building toolkit: http://www.feinheit.ch/labs/feincms/

Skylar Saveland

unread,
Jun 8, 2010, 4:30:40 AM6/8/10
to Django FeinCMS
Thanks Mattias, that does work.

On Jun 8, 2:41 am, Matthias Kestenholz <matthias.kestenh...@gmail.com>
wrote:

Martin J. Laubach

unread,
Jun 8, 2010, 9:23:44 AM6/8/10
to Django FeinCMS
I'm not sure I understood the original problem -- is that basically
the same (but having it configurable on a per-page basis) as adding an
@standalone to your app's view or does it do something completely
different?

mjl

Matthias Kestenholz

unread,
Jun 8, 2010, 9:53:49 AM6/8/10
to django-...@googlegroups.com

This is about hiding content elements which are added before or after
an applicationcontent.

Your page might look like this:

1. RichTextContent: Blabla introduction blurb
2. ApplicationContent: News module
3. RichTextContent: Some additional information


However, on subpages you might want to hide the RichTextContents in
position 1 and 3. The snippets posted allow you to do this -- instead
of concatenating the output of all content blocks together, you only
get the content of the embedded detail view.


Matthias

Hedde van der Heide

unread,
Sep 13, 2013, 9:40:41 AM9/13/13
to django-...@googlegroups.com
Has the "appcontent_parameters" context processor been deprecated, if so, is there an alternative to this without writing your own solution?

Op dinsdag 8 juni 2010 15:53:49 UTC+2 schreef Matthias Kestenholz:

Matthias Kestenholz

unread,
Sep 19, 2013, 10:59:10 AM9/19/13
to FeinCMS
Hi,


On Fri, Sep 13, 2013 at 3:40 PM, Hedde van der Heide <h.vand...@intellimedia.nl> wrote:
Has the "appcontent_parameters" context processor been deprecated, if so, is there an alternative to this without writing your own solution?
It's not necessary anymore. The values from application content are always available in the context (by means of request._feincms_extra_context which is always added to the rendering context by all FeinCMS views).


HTH.
Matthias

Reply all
Reply to author
Forward
0 new messages