Pages

0 views
Skip to first unread message

Eric Moritz

unread,
Feb 26, 2009, 1:41:42 PM2/26/09
to Penny Press developers
Another idea is to get rid of the idea of sections and use customized
flat pages with the combination of template tags

For instance:

class Page:
slug
title
categories = ManyToManyField(Category)
template_name = TextField(blank=True) # Inherits template from
parent if no parent template is found, an error is raised
parent = ForeignKey('self', null=True)

def all_categories(self):
# Use mptt to get a list of categories by child page
pass


So the /news/ page uses the pages/news.html template and has no
parent.

We create a template tag: {% get_content news.stories by
page.all_categories as story_list order_by pub_date %} If we have the
request in the context we can bake in the pagination.

Now if we have a /news/local/ page that is a child of the /news/ it
automatically uses the /news/ template unless otherwise given. If
categories are assigned to /news/local/, then /news/ inherits those
categories when page.all_categories
is called.

Now we can then use this to define video pages:

/videos/sports/ uses the pages/videos.html template and {%
get_content media.videos by page.all_categories as video_list order_by
pub_date %}
/video-galleries/sports/ uses the pages/video-galleries.html template
{% get_content galleries.videos by page.all_categories as video_list
order_by pub_date %}
/photos/sports/ uses the pages/photos.html template {% get_content
media.photos by page.all_categories as photo_list order_by pub_date


For the home page we can have a template tag called {% get_page_group
%} for the individual elements. Or we could have a page groups model
that groups pages together for
displaying in this way.

class PageGroup:
slug
title

class PageGroupItem:
page_group = ForeignKey(PageGroup) # edit inline
page = ForeignKey(Page)

class PageGroupItemLimits:
page_group_item = ForeignKey(PageGroupItem)
content_type = ForeignKey(ContentType)
limit = IntegerField


{% get_page_group slug="homepage-news" as news_page_list %}
{% for page in page_list %}
<div id="homepage-{{page.slug|slug_to_id}}"> <!-- becomes #homepage-
news-local -->
{% get_content news.stories by page_list.0.all_categories as
local_story_list %}
<h2>{{ page.title }}</h2>
{% for story in local_story_list %}
<div class="headline"><a href="{{ story.get_absolute_url }}">
{{ story.title }}</a></div>
<div class="tease">{{ story.short_description }}</div>
<div class="related">
<ul>
{% if story.has_related_by_inlines %}
{% if story.has_related_by_inlines %}
<ul>
{% for related in story.get_related_by_inlines|slice:5 %} <!--
This is a mixed list of content -->
<li><a href="{{related.get_absolute_url }}">{{ related.title }}
</a></li>
{% endfor %}
</ul>
{% endif %}
{% else %}
{% if story.has_related_by_categories %}
<ul>
{% for related in story.get_related_by_tags|slice:5 %} <!--
This is a mixed list of content -->
<li><a href="{{ related.get_absolute_url }}">
{{ related.title }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
{% endfor %}
Reply all
Reply to author
Forward
0 new messages