~divmod-dev/divmod.org/NULLIFY-versus-disallowNone-2736

« back to all changes in this revision

Viewing changes to Hyperbola/hyperbola/hyperbola_view.py

  • Committer: glyph
  • Date: 2006-01-11 17:00:20 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:4021

Author: glyph
Reviewer: moe

Fixes #382

This merge provides basic sharing functionality, such as the ability to give a
user a publicly-viewable web page (at /by/username, for the cool kids, or
/users, if you're a fuddy-duddy).

It also adds (working) support for a simple ClickChronicle public page at
/by/username/clicks, which exposes the "my clicks" page without the "actions"
column, and also (not working) Hyperbola at /by/username/blog which should some
day soon grow into a blog.  Patches accepted :).


Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from zope.interface import implements
 
3
 
 
4
from nevow import athena
 
5
 
 
6
from xmantissa import ixmantissa, webtheme
 
7
 
 
8
from xmantissa import tdbview, sharing, liveform
 
9
 
 
10
from hyperbola.hyperblurb import Blurb, FLAVOR
 
11
 
 
12
class HyperbolaView(athena.LiveFragment):
 
13
    # This is a Fragment of a Page
 
14
    implements(ixmantissa.INavigableFragment)
 
15
 
 
16
    # This View will use the hyperbola-start.html template
 
17
    fragmentName = 'hyperbola-start'
 
18
 
 
19
    live = 'athena'
 
20
    iface = {}
 
21
 
 
22
    def head(self):
 
23
        # Add tags in the page <head>
 
24
        pass
 
25
 
 
26
 
 
27
    def render_blogs(self, ctx, data):
 
28
        view = tdbview.TabularDataView(
 
29
            self.original.getTDM(),
 
30
            [tdbview.ColumnViewBase('title', displayName='Title')])
 
31
        view.page = self.page
 
32
        view.docFactory = webtheme.getLoader(view.fragmentName)
 
33
        return ctx.tag[view]
 
34
 
 
35
 
 
36
    def render_addBlog(self, ctx, data):
 
37
        return BlogAddingFragment(self.page, self.original)
 
38
 
 
39
 
 
40
 
 
41
class BlogAddingFragment(liveform.LiveForm):
 
42
    #fragmentName = 'hyperbola-add-blog'
 
43
    fragmentName = None
 
44
    jsClass = u'Hyperbola.AddBlog'
 
45
 
 
46
    def __init__(self, page, hyperbola):
 
47
        super(BlogAddingFragment, self).__init__(self.addBlog,
 
48
                [liveform.Parameter(
 
49
                    'title',
 
50
                    liveform.TEXT_INPUT,
 
51
                    unicode,
 
52
                    "A title for your blog",
 
53
                    "A Blog"),
 
54
                 liveform.Parameter(
 
55
                    'description',
 
56
                    liveform.TEXT_INPUT,
 
57
                    unicode,
 
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)
 
63
 
 
64
    def addBlog(self, title, description):
 
65
        store = self.hyperbola.store
 
66
 
 
67
        blog = self.hyperbola.topPost(title, description, FLAVOR.BLOG)
 
68
 
 
69
        authorsRole = sharing.getPrimaryRole(store, title + u' blog', True)
 
70
        sharing.getSelfRole(store).becomeMemberOf(authorsRole)
 
71
 
 
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'))
 
74
 
 
75
 
 
76
class BlurbViewer(athena.LiveFragment):
 
77
    implements(ixmantissa.INavigableFragment)
 
78
    fragmentName = 'hyperbola-view-blurb'
 
79
    jsClass = u'Hyperbola.ViewBlurb'
 
80
 
 
81
    def __init__(self, frag):
 
82
        super(athena.LiveFragment, self).__init__(frag)
 
83
 
 
84
    def customizeFor(self, username):
 
85
        print 'blurb viewer customized for', username
 
86
        self.customizedFor = username
 
87
        return self
 
88
 
 
89
    def head(self):
 
90
        pass
 
91
 
 
92
from twisted.python.components import registerAdapter
 
93
registerAdapter(BlurbViewer, Blurb, ixmantissa.INavigableFragment)