Mercurial > hg > commentator
changeset 2:689b9d928dc8
add date, reflect api change of lxmlmiddleware
author | k0s <k0scist@gmail.com> |
---|---|
date | Tue, 26 Jan 2010 23:00:51 -0500 |
parents | aebfbb10aefb |
children | d0d8524d9495 |
files | commentator/middleware.py commentator/model.py commentator/templates/comment.html setup.py |
diffstat | 4 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/commentator/middleware.py Sun Jan 24 17:40:54 2010 -0500 +++ b/commentator/middleware.py Tue Jan 26 23:00:51 2010 -0500 @@ -7,7 +7,8 @@ import re from handlers import PostComment -from model import CouchComments, PickleComments +#from model import CouchComments +from model import PickleComments from genshi.template import TemplateLoader from lxml import etree from lxmlmiddleware import LXMLMiddleware @@ -24,6 +25,7 @@ ### class level variables defaults = { 'auto_reload': 'False', 'database': 'commentator', + 'date_format': '%H:%M %m/%d/%Y', 'template_dirs': '', 'pattern': '.*', 'path': 'html', @@ -86,8 +88,8 @@ res = handler() return res(environ, start_response) - def manipulate(self, environ, tree): - url_match = re.match(self.url_pattern, environ['commentator.path_info']) + def manipulate(self, request, response, tree): + url_match = re.match(self.url_pattern, request.environ['commentator.path_info']) if not url_match: return tree @@ -110,6 +112,8 @@ data = {} data['comments'] = self.model.comments(uri) data['action'] = '%s/%s' % (uri, self.url) + data['date_format'] = self.date_format + data['request'] = request # render template template = self.loader.load(self.template)
--- a/commentator/model.py Sun Jan 24 17:40:54 2010 -0500 +++ b/commentator/model.py Tue Jan 26 23:00:51 2010 -0500 @@ -13,6 +13,7 @@ f.close() def comment(self, uri, **kw): + kw['date'] = datetime.now() f = file(self.database) comments = pickle.load(f) f.close()
--- a/commentator/templates/comment.html Sun Jan 24 17:40:54 2010 -0500 +++ b/commentator/templates/comment.html Tue Jan 26 23:00:51 2010 -0500 @@ -9,13 +9,20 @@ <div py:for="comment in comments" class="comment"> <a py:strip="not comment['link']" href="${comment['link']}"> ${comment['author']} - </a> + </a>${comment['date'].strftime(date_format)} <p>${comment['body']}</p> </div> + <form method="post" action="${action}"> + + <py:if test="bool(request.remote_user)"> + <input type="hidden" name="author" value="${request.remote_user}"/> + </py:if> <dl> + <py:if test="not request.remote_user"> <dt>Name:</dt><dd><input type="text" name="author"/></dd> + </py:if> <dt>URL:</dt><dd><input type="text" name="link"/></dd> <textarea name="body"></textarea> </dl>