diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-07-12 16:28:05 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-07-12 16:28:05 +0000 |
| commit | 4c2f00452697031f3c8500f5c95705f17b86b776 (patch) | |
| tree | 604c4664e684154947ad8d374159a86ac97c3cfa /repoze/bfg/sampleapp/views.py | |
| parent | effbaa2f68cc3fcf4a29aa0c275648c2a52e9455 (diff) | |
| download | pyramid-4c2f00452697031f3c8500f5c95705f17b86b776.tar.gz pyramid-4c2f00452697031f3c8500f5c95705f17b86b776.tar.bz2 pyramid-4c2f00452697031f3c8500f5c95705f17b86b776.zip | |
Use a djangoesque layout and naming scheme.
Diffstat (limited to 'repoze/bfg/sampleapp/views.py')
| -rw-r--r-- | repoze/bfg/sampleapp/views.py | 48 |
1 files changed, 48 insertions, 0 deletions
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='/') + |
