2
from zope.interface import implements
4
from nevow import athena
6
from xmantissa import ixmantissa, webtheme
8
from xmantissa import tdbview, sharing, liveform
10
from hyperbola.hyperblurb import Blurb, FLAVOR
12
class HyperbolaView(athena.LiveFragment):
13
# This is a Fragment of a Page
14
implements(ixmantissa.INavigableFragment)
16
# This View will use the hyperbola-start.html template
17
fragmentName = 'hyperbola-start'
23
# Add tags in the page <head>
27
def render_blogs(self, ctx, data):
28
view = tdbview.TabularDataView(
29
self.original.getTDM(),
30
[tdbview.ColumnViewBase('title', displayName='Title')])
32
view.docFactory = webtheme.getLoader(view.fragmentName)
36
def render_addBlog(self, ctx, data):
37
return BlogAddingFragment(self.page, self.original)
41
class BlogAddingFragment(liveform.LiveForm):
42
#fragmentName = 'hyperbola-add-blog'
44
jsClass = u'Hyperbola.AddBlog'
46
def __init__(self, page, hyperbola):
47
super(BlogAddingFragment, self).__init__(self.addBlog,
52
"A title for your blog",
58
"A description of your blog",
59
"A Blog that I write") ])
60
self.setFragmentParent(page)
61
self.hyperbola = hyperbola
62
# ideally, self.docFactory = webtheme.getLoader(self.fragmentName)
64
def addBlog(self, title, description):
65
store = self.hyperbola.store
67
blog = self.hyperbola.topPost(title, description, FLAVOR.BLOG)
69
authorsRole = sharing.getPrimaryRole(store, title + u' blog', True)
70
sharing.getSelfRole(store).becomeMemberOf(authorsRole)
72
sharing.shareItem(blog, authorsRole, shareID=u'blog')
73
sharing.shareItem(blog, sharing.getEveryoneRole(store), shareID=u'blog', attributeNames=(u'title', u'body', u'dateLastEdited', u'author'))
76
class BlurbViewer(athena.LiveFragment):
77
implements(ixmantissa.INavigableFragment)
78
fragmentName = 'hyperbola-view-blurb'
79
jsClass = u'Hyperbola.ViewBlurb'
81
def __init__(self, frag):
82
super(athena.LiveFragment, self).__init__(frag)
84
def customizeFor(self, username):
85
print 'blurb viewer customized for', username
86
self.customizedFor = username
92
from twisted.python.components import registerAdapter
93
registerAdapter(BlurbViewer, Blurb, ixmantissa.INavigableFragment)