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

[WIP] Advanced options for kotti_blog #5

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4713d5c
Add a basic sidebar and implement filtering by tag
nightmarebadger Dec 20, 2013
f1ea4d4
Make the blog title link to an unfiltered blog
nightmarebadger Dec 20, 2013
c24e1fb
Whoops, turned request and context around (thought
nightmarebadger Dec 20, 2013
3bcff2e
Added all dates from posts to the sidebar - they show the
nightmarebadger Dec 20, 2013
059aee9
Only show tags/dates from posts you can actually see
nightmarebadger Dec 20, 2013
3e9db68
Make sure we can switch pages while filtered
nightmarebadger Dec 20, 2013
ef9cdb4
Adding more metadata (date/time, tags with links to filters),
nightmarebadger Dec 20, 2013
89e970e
Added metadata and similar styling to blog view too
nightmarebadger Dec 20, 2013
bad297c
Adding proper HTML to sidebar
nightmarebadger Dec 20, 2013
f87c2c9
Marking translations
nightmarebadger Dec 20, 2013
4fa3dd6
Move getting tags/archives to methods in Blog class. Tried to
nightmarebadger Dec 22, 2013
8b552d6
Add a categories view which either lists categories or shows
nightmarebadger Dec 22, 2013
1b786ad
Reworked pagination so it works via URL's like
nightmarebadger Dec 22, 2013
6e9ccea
Make sure to use the new categories URL's everywhere
nightmarebadger Dec 22, 2013
d7c9293
Implemented archives in the same way as categories (will fix
nightmarebadger Dec 22, 2013
fa4f486
New archives URL in sidebar
nightmarebadger Dec 22, 2013
7e8adfd
Fix archives and categories "list" view
nightmarebadger Dec 22, 2013
24bb50a
Use archives template on archives listing, fixes to the
nightmarebadger Dec 22, 2013
1b7de69
Use correct url's in archives listing
nightmarebadger Dec 22, 2013
61e6230
Show no. of posts for category/archive, add basic settings
nightmarebadger Dec 22, 2013
bea99f8
Instead of querying, use Kotti's .children attribute. Not sure
nightmarebadger Dec 26, 2013
1eafd0b
Put all filtering in one function so we only need to iterate
nightmarebadger Dec 26, 2013
943d7a2
Cleaning up imports
nightmarebadger Dec 26, 2013
15e3b4d
Fixes to archives and categories view templates
nightmarebadger Dec 26, 2013
c245e3a
Minor cleaning
nightmarebadger Dec 26, 2013
d31a764
If you choose 0 in the "how many categories/archives are
nightmarebadger Dec 27, 2013
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
50 changes: 50 additions & 0 deletions kotti_blog/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,55 @@ class KottiBlogSettingsSchema(colander.MappingSchema):
}


class UseSidebarCategories(colander.SchemaNode):
name = 'use_sidebar_categories'
title = _(u'Show categories in sidebar')
description = _(u'Show categories sorted by number of posts on which you '
u'can filter.')
missing = True
default = True


class SidebarCategoriesNumber(colander.SchemaNode):
name = 'sidebar_categories_number'
title = _(u'The number of categories shown')
description = _(u'Choose how many categories are shown in the sidebar. ' +
u'Set to 0 to show all categories.')
default = 5


class UseSidebarArchives(colander.SchemaNode):
name = 'use_sidebar_archives'
title = _(u'Show archives in sidebar')
description = _(u'Show categories sorted by date on which you can filter.')
missing = True
default = True


class SidebarArchivesNumber(colander.SchemaNode):
name = 'sidebar_archives_number'
title = _(u'The number of archives shown')
description = _(u'Choose how many archives are shown in the sidebar. ' +
u'Set to 0 to show all archives.')
default = 5


class KottiBlogSidebarSettingsSchema(colander.MappingSchema):
use_sidebar_categories = UseSidebarCategories(colander.Boolean())
sidebar_categories_number = SidebarCategoriesNumber(colander.Integer())
use_sidebar_archives = UseSidebarArchives(colander.Boolean())
sidebar_archives_number = SidebarArchivesNumber(colander.Integer())


KottiBlogSidebarSettings = {
'name': 'kotti_blog_sidebar_settings',
'title': _(u'Blog sidebar settings'),
'description': _(u"Settings for kotti_blog sidebar"),
'success_message': _(u"Successfully saved blog sidebar settings."),
'schema_factory': KottiBlogSidebarSettingsSchema,
}


def populate_settings():
add_settings(KottiBlogSettings)
add_settings(KottiBlogSidebarSettings)
33 changes: 33 additions & 0 deletions kotti_blog/resources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from datetime import date
from dateutil.tz import tzutc
from sqlalchemy import Column
from sqlalchemy import ForeignKey
Expand Down Expand Up @@ -33,6 +34,38 @@ class Blog(Document):
addable_to=[u'Document'],
)

def get_children_with_permission(self, request):
return self.children_with_permission(request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why children_with_permission is reimplemented? Should be used directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I'd need to use some extras here but it turned out I didn't - will fix this :)


def get_unique_tags(self, request):
children = self.get_children_with_permission(request)

unique_tags_dict = {}
for child in children:
for tag in child.tags:
try:
unique_tags_dict[tag] += 1
except KeyError:
unique_tags_dict[tag] = 1

return sorted(
unique_tags_dict.items(),
key=lambda x: x[1],
reverse=True
)

def get_archives(self, request):
children = self.get_children_with_permission(request)

dates_dict = {}
for child in children:
try:
dates_dict[date(child.date.year, child.date.month, 1)] += 1
except KeyError:
dates_dict[date(child.date.year, child.date.month, 1)] = 1

return sorted(dates_dict.items(), reverse=True)


class BlogEntry(Document):
id = Column(Integer, ForeignKey('documents.id'), primary_key=True)
Expand Down
12 changes: 11 additions & 1 deletion kotti_blog/static/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
.blog-view .blogentry {
margin-top: 2em;
}
.blogentry-view h1,
.blog-view .blogentry h2 {
border-top: 1px solid black;
margin-top: 0.75em;
padding-top: 0.5em;
}
.blogentry-view h1 {
margin-top: 0.5em;
}
.blog-view .description,
.blogentry-view .description {
font-style: italic;
}
.blog-metadata {
margin-bottom: 20px;
border-bottom: 1px solid #EEE;
}
27 changes: 27 additions & 0 deletions kotti_blog/templates/blog-archives.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en"
i18n:domain="kotti_blog"
xmlns:tal="http://xml.zope.org/namespaces/tal"
metal:use-macro="api.macro('kotti:templates/view/master.pt')">

<article metal:fill-slot="content" class="blog-archives content">

<h1><a href="${api.url(context)}">${context.title}</a> <tal:block i18n:translate="">archives</tal:block></h1>
<p class="description">
${context.description}
</p>
<p class="body">
${structure: context.body}
</p>

<div tal:condition="items" class="archives">
<ul tal:repeat="archive items" class="blogentry">
<li>
<a href="${api.url(context)}archives/${archive[0].year}_${archive[0].month}">${api.format_date(archive[0], 'MMMM yyyy')}</a> <span class="badge">${archive[1]}</span>
</li>
</ul>
</div>

</article>
</html>
27 changes: 27 additions & 0 deletions kotti_blog/templates/blog-categories.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en"
i18n:domain="kotti_blog"
xmlns:tal="http://xml.zope.org/namespaces/tal"
metal:use-macro="api.macro('kotti:templates/view/master.pt')">

<article metal:fill-slot="content" class="blog-categories content">

<h1><a href="${api.url(context)}">${context.title}</a> <tal:block i18n:translate="">categories</tal:block></h1>
<p class="description">
${context.description}
</p>
<p class="body">
${structure: context.body}
</p>

<div tal:condition="items" class="categories">
<ul tal:repeat="tag items" class="blogentry">
<li>
<a href="${api.url(context)}categories/{tag[0]}">${tag[0]}</a> <span class="badge">${tag[1]}</span>
</li>
</ul>
</div>

</article>
</html>
22 changes: 22 additions & 0 deletions kotti_blog/templates/blog-sidebar.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="blog-sidebar">
<div class="categories" tal:condition="use_categories">
<h5><tal:block i18n:translate="">Categories</tal:block>:</h5>

<ul>
<li tal:repeat="tag unique_tags">
<a href="${blog_url}categories/${tag[0]}">${tag[0]}</a> <span class="badge">${tag[1]}</span>
</li>
</ul>
</div>

<div class="archive" tal:condition="use_archives">
<h5><tal:block i18n:translate="">Archives</tal:block>:</h5>

<ul>
<li tal:repeat="archive archives">
<a href="${blog_url}archives/${archive[0].year}_${archive[0].month}">${api.format_date(archive[0], 'MMMM yyyy')}</a> <span class="badge">${archive[1]}</span>
</li>
</ul>
</div>
</div>

11 changes: 9 additions & 2 deletions kotti_blog/templates/blog-view.pt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<article metal:fill-slot="content" class="blog-view content">

<h1>${api.context.title}</h1>
<h1><a href="${api.url(api.context)}">${api.context.title}</a></h1>
<p class="description">
${api.context.description}
</p>
Expand All @@ -17,12 +17,19 @@

<div tal:condition="items" class="blogentries">
<div tal:repeat="item items" class="blogentry" data-uri="${api.url(item)}">
<span class="date" tal:content="api.format_date(item.date)" />
<h2>
<a href="${api.url(item)}" title="${item.description}" tal:omit-tag="not: link_headline">
${item.title}
</a>
</h2>
<div class="blog-metadata">
<span class="date" tal:content="api.format_datetime(item.date, 'MMM dd, yyyy \'at\' HH:mm')" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format_datetime should be called without a specific formatting because the date attribute is locale aware. Is the output api.format_datetime(item.date) not precise enough? With the extra formatting it will not change in other languages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly I just didn't like the default format and wanted to get rid of the seconds - didn't really think about locale awareness, which is probably more important then how it looks to me :P

I'll see if I can keep the locale awareness while still getting rid of the seconds (I think they are unnecessary data in this case) and if not I guess we can keep the seconds too.

| <tal:block i18n:translate="">categories</tal:block>:
<span class="categories">
<tal:block tal:repeat="tag item.tags">
<a href="${api.url(context)}categories/${tag}">${tag}</a><tal:block tal:condition="not: repeat.tag.end">,</tal:block>
</tal:block></span>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The categories should only be shown if there are tags for the blog entry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, will add a check here

<p>${structure: item.body}</p>
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion kotti_blog/templates/blogentry-view.pt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
<article metal:fill-slot="content" class="blogentry-view content blogentries">

<div class="blogentry" data-uri="${api.url(context)}">
<span class="date" tal:content="api.format_date(context.date)" />
<h1>${api.context.title}</h1>
<div class="blog-metadata">
<span class="date" tal:content="api.format_datetime(context.date, 'MMM dd, yyyy \'at\' HH:mm')" />
| <tal:block i18n:translate="">categories</tal:block>:
<span class="categories">
<tal:block tal:repeat="tag context.tags">
<a href="${api.url(context.parent)}categories/${tag}">${tag}</a><tal:block tal:condition="not: repeat.tag.end">,</tal:block>
</tal:block></span>
</div>
<p class="description">
${api.context.description}
</p>
Expand Down
12 changes: 6 additions & 6 deletions kotti_blog/templates/macros.pt
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@
tal:condition="batch.multiple_pages">
<ul>
<li class="previous" tal:condition="batch.has_previous">
<a href="" tal:attributes="href string:${url}?page=${batch.previouspage}" i18n:translate="">
<a href="" tal:attributes="href string:${url}${url_parameters}${batch.previouspage}" i18n:translate="">
Previous <span i18n:name="number" tal:omit-tag="" tal:content="batch.pagesize">n</span> items
</a>
</li>
<li tal:condition="batch.show_link_to_first">
<a href="" tal:attributes="href string:${url}?page=1">1</a>
<a href="" tal:attributes="href string:${url}${url_parameters}1">1</a>
<span tal:condition="batch.second_page_not_in_navlist" tal:omit-tag="">...</span>
</li>
<li tal:repeat="page batch.previous_pages">
<a href="" tal:content="page" tal:attributes="href string:${url}?page=${page}"/>
<a href="" tal:content="page" tal:attributes="href string:${url}${url_parameters}${page}"/>
</li>
<li class="active" tal:condition="batch.navlist">
<a href="#" tal:content="batch.pagenumber">Current page number</a>
</li>
<li tal:repeat="page batch.next_pages">
<a href="" tal:content="page"
tal:attributes="href string:${url}?page=${page}"/>
tal:attributes="href string:${url}${url_parameters}${page}"/>
</li>
<li tal:condition="batch.show_link_to_last">
<span tal:condition="batch.before_last_page_not_in_navlist" tal:omit-tag="">...</span>
<a href=""
tal:attributes="href string:${url}?page=${batch.lastpage}"
tal:attributes="href string:${url}${url_parameters}${batch.lastpage}"
tal:content="batch.lastpage">last page</a>
</li>
<li class="next"
tal:condition="batch.has_next">
<a href="" tal:attributes="href string:${url}?page=${batch.nextpage}" i18n:translate="">
<a href="" tal:attributes="href string:${url}${url_parameters}${batch.nextpage}" i18n:translate="">
Next <span i18n:name="number" tal:omit-tag="" tal:content="batch.next_item_count">n</span> items
</a>
</li>
Expand Down
Loading