Merge blog_index and blog_category views

This commit is contained in:
str4d
2013-02-03 02:58:55 +00:00
parent 55af9d11b3
commit 1be4ea4943
3 changed files with 13 additions and 16 deletions

View File

@ -10,22 +10,16 @@ from i2p2www.helpers import Pagination, get_for_page
# Blog views
@cache.memoize(600)
def blog_index(page):
all_posts = get_blog_posts()
def blog_index(page, category=None):
all_posts = get_blog_posts(category=category)
posts = get_for_page(all_posts, page, BLOG_POSTS_PER_PAGE)
if not posts and page != 1:
abort(404)
pagination = Pagination(page, BLOG_POSTS_PER_PAGE, len(all_posts))
return render_template('blog/index.html', pagination=pagination, posts=posts)
@cache.memoize(600)
def blog_category(category, page):
category_posts = get_blog_posts(category=category)
posts = get_for_page(category_posts, page, BLOG_POSTS_PER_PAGE)
if not posts and page != 1:
abort(404)
pagination = Pagination(page, BLOG_POSTS_PER_PAGE, len(category_posts))
if category:
return render_template('blog/category.html', pagination=pagination, posts=posts, category=category)
else:
return render_template('blog/index.html', pagination=pagination, posts=posts)
@cache.memoize(600)
def blog_post(slug):

View File

@ -1,6 +1,9 @@
{%- macro change_lang(lang) -%}
{%- if request.endpoint == 'site_show' -%}{{ url_for('site_show', lang=lang, page=page) }}
{%- elif request.endpoint == 'blog_category' -%}{{ url_for('blog_category', lang=lang, category=category) }}
{%- elif request.endpoint == 'blog_index' -%}
{%- if category -%}{{ url_for('blog_index', lang=lang, category=category) }}
{%- else -%}{{ url_for('blog_index', lang=lang) }}
{%- endif -%}
{%- elif request.endpoint == 'blog_post' -%}{{ url_for('blog_post', lang=lang, slug=slug) }}
{%- elif request.endpoint == 'meetings_show' -%}{{ url_for('meetings_show', lang=lang, id=id) }}
{%- elif request.endpoint == 'downloads_select' -%}{{ url_for('downloads_select', lang=lang, file=file) }}
@ -35,7 +38,7 @@
{%- macro render_categories(categories) -%}
{%- if categories and categories|length %}
{%- for category in categories %}<a href="{{ get_url('blog_category', category=category) }}">{{ category }}</a>{% if not loop.last %}, {% endif %}{% endfor %}
{%- for category in categories %}<a href="{{ get_url('blog_index', category=category) }}">{{ category }}</a>{% if not loop.last %}, {% endif %}{% endfor %}
{%- else %}{{ _('None') }}
{%- endif %}
{%- endmacro %}

View File

@ -40,8 +40,8 @@ url('/<lang:lang>/<path:page>', 'views.site_show')
url('/<lang:lang>/blog/', 'blog.views.blog_index', defaults={'page': 1})
url('/<lang:lang>/blog/page/<int:page>', 'blog.views.blog_index')
url('/<lang:lang>/blog/category/<string:category>', 'blog.views.blog_category', defaults={'page': 1})
url('/<lang:lang>/blog/category/<string:category>/page/<int:page>', 'blog.views.blog_category')
url('/<lang:lang>/blog/category/<string:category>', 'blog.views.blog_index', defaults={'page': 1})
url('/<lang:lang>/blog/category/<string:category>/page/<int:page>', 'blog.views.blog_index')
url('/<lang:lang>/blog/post/<path:slug>', 'blog.views.blog_post')
url('/<lang:lang>/feed/blog/rss', 'blog.views.blog_rss')
url('/<lang:lang>/feed/blog/atom', 'blog.views.blog_atom')