Hello,
I have a simple messageboard using SQLalchemy and URL-Dispatching.
The __init__.py holds a line:
config.add_route('home', '/', view='bp2.message.start',
view_renderer='templates/start.pt')
The important part of message.py is:
def start(request):
session = DBSession
messages = session.query(Message).order_by(desc(Message.datetime))[-10:]
return {'messages':messages}
The important part of the template is:
<span tal:repeat="m messages">
<div id="message">
<div id="subject" tal:content="m.subject">Subject</div>
<div id="text" tal:content="m.text">Text</div>
<div id="datetime" tal:content="m.datetime.strftime('%d.%m.%Y %H:%M:
%S')">Datetime</div>
<div id="userid" tal:content="m.userid">UserID</div>
</div>
</span>
This works, but I'd like to put out the date string not only in the format
shown above. I want to use strings like "yesterday", "a week ago" etc.
How can I do that ?
I've tried to use a python function in the template:
<div id="mdatetime"
tal:content="python:bp2/message/dateformat(m.datetime)">Datetime</div>
I extended the message.py by the function dateformat:
def dateformat(str):
result = 'yesterday' # dummy, here's more code
return result
The error I get looks like this:
RuntimeError: Caught exception rendering template.
- Expression: ``bp2/message/dateformat(m.datetime)``
- Filename: /home/mm/pyramid/bp2/bp2/templates/start.pt
- Arguments: renderer_name: templates/start.pt
template: <PageTemplateFile - at 0xae012ac>
xincludes: <XIncludes - at 0xae01eec>
macros: <Macros - at 0xae0e9cc>
request: <Request - at 0xadfefac>
messages: <list - at 0xae01a8c>
renderer_info: {...} (2)
context: <instance None at 0xadfefcc>
view: <function start at 0xadf9b8c>
NameError: bp2
----------------------------------------
What is the best practise ? In pylons there were helpers..
Thanks for your help
Matthias
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.