Skip to content

Commit 07c9bb9

Browse files
committed
Merge pull request #106 from dongweiming/jinja2
categories/detail.html use jinja2
2 parents f807c18 + 915b7e0 commit 07c9bb9

File tree

5 files changed

+38
-30
lines changed

5 files changed

+38
-30
lines changed

firefly/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ def get_locale():
9797
def before_request():
9898
g.locale = get_locale()
9999

100+
@app.context_processor
101+
def inject_builtin():
102+
return {
103+
'hasattr': hasattr,
104+
'len': len
105+
}
106+
100107

101108
def plug_to_db(db):
102109
from firefly.models.utils import dict_filter
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{% extends "base.html" %}
2+
3+
{% block outlet %}
4+
<h1>{{category}}</h1>
5+
{% for post in posts %}
6+
<h2>
7+
<a href="{{post.url()}}">{{post.title}}</a>
8+
{% if post.body %}
9+
{% if post.post_type == 'Quote' %}
10+
<blockquote>{{post.body}}</blockquote>
11+
<p>{{post.author}}</p>
12+
{% else %}
13+
<p>{{post.body}}</p>
14+
{% endif %}
15+
{% endif %}
16+
{% if hasattr(post, 'embed_code') and post.embed_code %}
17+
{{post.embed_code}}
18+
{% endif %}
19+
{% if hasattr(post, 'image_url') and post.image_url %}
20+
<p>
21+
<img alt="" src="{{post.image_url}}"/>
22+
</p>
23+
{% endif %}
24+
<p>{{post.created_at.strftime('%H:%M %Y-%m-%d')}}</p>
25+
{% set total = len(post.comments) %}
26+
{{total}} comment
27+
</h2>
28+
{% endfor %}
29+
{% endblock %}

firefly/templates/categories/list.html

Lines changed: 0 additions & 28 deletions
This file was deleted.

firefly/views/category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get(self, slug):
1717
posts = Post.objects.filter(
1818
category=category
1919
).order_by("-recent_activity_time")
20-
return render_template('categories/list.html',
20+
return render_template('categories/detail.html',
2121
category=category.name,
2222
posts=posts)
2323

firefly/views/post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DetailView(MethodView):
3939
def get(self, id):
4040
post = Post.objects.get_or_404(id=id)
4141
Post.objects(id=id).update_one(inc__views=1)
42-
return render_template('posts/detail.html', post=post, hasattr=hasattr,
42+
return render_template('posts/detail.html', post=post,
4343
Markdown=Markdown, gen_author=gen_author,
4444
gen_author_name=gen_author_name,
4545
short_timesince=short_timesince)

0 commit comments

Comments
 (0)