From a8a9510c629e7a2b64e848321e8cde64c26bbf95 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 22 Jan 2010 13:07:27 +0200 Subject: [PATCH] Added a "tags" view. --- .bzrignore | 1 + scribeengine/config/routing.py | 2 + scribeengine/controllers/blog.py | 11 +++++- scribeengine/public/scripts/ScribeEngine.js | 2 +- scribeengine/public/styles/style.css | 43 ++++++++++++++++++--- scribeengine/templates/blog/index.mako | 2 +- scribeengine/templates/blog/tag.mako | 22 +++++++++++ scribeengine/templates/blog/view.mako | 7 +++- 8 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 scribeengine/templates/blog/tag.mako diff --git a/.bzrignore b/.bzrignore index 669ccfe..dc00706 100644 --- a/.bzrignore +++ b/.bzrignore @@ -4,3 +4,4 @@ ScribeEngine.e4p scribeengine.sqlite posts.sql *.egg-info +ScrivbeEngine.e4p diff --git a/scribeengine/config/routing.py b/scribeengine/config/routing.py index 6a91213..9c3aaa0 100644 --- a/scribeengine/config/routing.py +++ b/scribeengine/config/routing.py @@ -48,6 +48,8 @@ def make_map(): map.connect('/archive/{year}/{month}/{day}', controller='blog', action='archive') map.connect('/archive/{year}/{month}/{day}/{url}', controller='blog', action='view') + map.connect('/tag/{id}', controller='blog', action='tag') + map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') diff --git a/scribeengine/controllers/blog.py b/scribeengine/controllers/blog.py index ef2b09d..3f87f02 100644 --- a/scribeengine/controllers/blog.py +++ b/scribeengine/controllers/blog.py @@ -25,7 +25,7 @@ from datetime import datetime from scribeengine.lib.base import * from scribeengine.lib import utils -from scribeengine.model import Post, Comment +from scribeengine.model import Post, Comment, Tag from scribeengine.model.meta import Session log = logging.getLogger(__name__) @@ -71,6 +71,15 @@ class BlogController(BaseController): c.page_title = c.post.title return render(u'/blog/view.mako') + def tag(self, id=None): + if not id: + h.redirect_to('/') + c.tag = Session.query(Tag).filter_by(url=id).first() + if not c.tag: + h.redirect_to('/') + c.page_title = u'Blog posts with tag: %s' % c.tag.name + return render('/blog/tag.mako') + @authenticate() def comment_POST(self, id): if not id: diff --git a/scribeengine/public/scripts/ScribeEngine.js b/scribeengine/public/scripts/ScribeEngine.js index 7dfdbca..4aa3397 100644 --- a/scribeengine/public/scripts/ScribeEngine.js +++ b/scribeengine/public/scripts/ScribeEngine.js @@ -125,7 +125,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", { }, tagEditor: function (selector) { - $(selector).tagEditor({confirmRemoval: true, completeOnBlur: true, initialParse: true}); + $(selector).tagEditor({completeOnBlur: true, initialParse: true}); } }); diff --git a/scribeengine/public/styles/style.css b/scribeengine/public/styles/style.css index ac130f9..08ad597 100644 --- a/scribeengine/public/styles/style.css +++ b/scribeengine/public/styles/style.css @@ -16,9 +16,6 @@ body { color: #999999; } -h1, h2, h3 { -} - h1 { font-size: 3em; } @@ -29,7 +26,7 @@ h2 { } h3 { - font-size: 1em; + font-size: 1.5em; } p, ul, ol, pre { @@ -141,6 +138,11 @@ hr { width: 605px; } +.title { + border-bottom: 1px solid #454545; + margin-bottom: 1em; +} + .post { margin-bottom: 40px; } @@ -198,7 +200,7 @@ hr { #comments, #respond { - font-size: 1.5em; + /*font-size: 1.5em;*/ margin-top: 1.8em; } @@ -224,6 +226,36 @@ hr { margin-top: 0; } +/* Tags */ + +.tags { + margin-top: 1.8em; +} + +.tags p { + font-weight: bold; +} + +.tags ul { + margin: 4px 0 4px 10px; + padding: 0; +} + +.tags ul li { + background-color: #454545; + cursor: pointer; + display: inline; + list-style-type: none; + margin: 0; + padding: 2px 6px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; +} + +.tags ul li a { + text-decoration: none; +} + /* Sidebar */ #sidebar { @@ -430,6 +462,7 @@ fieldset { .tagEditor li:hover { background-color: #eee; + color: #000; } /* Miscellaneous Styles */ diff --git a/scribeengine/templates/blog/index.mako b/scribeengine/templates/blog/index.mako index b7f0ea7..cb560ae 100644 --- a/scribeengine/templates/blog/index.mako +++ b/scribeengine/templates/blog/index.mako @@ -1,5 +1,5 @@ <%inherit file="/base.mako"/> - <%include file="/flash.mako"/> + <%include file="/flash.mako"/> % for post in c.posts:

${post.title}

diff --git a/scribeengine/templates/blog/tag.mako b/scribeengine/templates/blog/tag.mako new file mode 100644 index 0000000..6fd917a --- /dev/null +++ b/scribeengine/templates/blog/tag.mako @@ -0,0 +1,22 @@ +<%inherit file="/base.mako"/> + <%include file="/flash.mako"/> +

Blog posts with tag: ${c.tag.name}

+% for post in c.tag.posts: +
+

${post.title}

+
+ ${h.literal(h.teaser(post.body, h.url_for_post(post)))} +
+

+ + Read more +% if len(post.comments) == 0: + No comments +% elif len(post.comments) == 1: + 1 comment +% else: + ${len(post.comments)} comments +% endif +

+
+% endfor diff --git a/scribeengine/templates/blog/view.mako b/scribeengine/templates/blog/view.mako index a9a01f8..b88ef62 100644 --- a/scribeengine/templates/blog/view.mako +++ b/scribeengine/templates/blog/view.mako @@ -6,11 +6,16 @@
${h.literal(c.post.body)}
+% if c.post.tags:
+

Filed under:

+
+% endif % if len(c.post.comments) == 0:

No Responses

% elif len(c.post.comments) == 1: