From 4c2f00452697031f3c8500f5c95705f17b86b776 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 12 Jul 2008 16:28:05 +0000 Subject: Use a djangoesque layout and naming scheme. --- repoze/bfg/sampleapp/views.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 repoze/bfg/sampleapp/views.py (limited to 'repoze/bfg/sampleapp/views.py') diff --git a/repoze/bfg/sampleapp/views.py b/repoze/bfg/sampleapp/views.py new file mode 100644 index 000000000..3d61802bb --- /dev/null +++ b/repoze/bfg/sampleapp/views.py @@ -0,0 +1,48 @@ +import time + +from webob.exc import HTTPFound + +from repoze.bfg.template import TemplateView +from repoze.bfg.sampleapp.models import BlogEntry + +def datestring(dt): + return dt.strftime('%Y-%m-%dT%H:%M:%S') + +class BlogDefaultView(TemplateView): + def getInfo(self): + entrydata = [] + for name, entry in self.context.items(): + entrydata.append( + { + 'name':name, + 'title':entry.title, + 'author':entry.author, + 'created':datestring(entry.created), + } + ) + return {'name':self.context.__name__, 'entries':entrydata} + +class BlogEntryDefaultView(TemplateView): + def getInfo(self): + return { + 'name':self.context.__name__, + 'title':self.context.title, + 'body':self.context.body, + 'author':self.context.author, + 'created':datestring(self.context.created), + } + +class BlogEntryAddView(object): + def __init__(self, context, request): + self.context = context + self.request = request + + def __call__(self): + author = self.request.params['author'] + body = self.request.params['body'] + title = self.request.params['title'] + name = str(time.time()) + new_entry = BlogEntry(name, title, body, author) + self.context[name] = new_entry + return HTTPFound(location='/') + -- cgit v1.2.3