1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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='/')
|