source: trunk/Story.py @ 66

Revision 66, 2.8 KB checked in by tarmo, 14 years ago (diff)

Changed the svn:eol-style property to "native", since
people aren't using unix line feeds uniformally.

  • Property svn:eol-style set to native
Line 
1from Products.Archetypes.public import BaseSchema, Schema
2from Products.Archetypes.public import StringField, LinesField, TextField
3from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget, RichWidget
4from Products.Archetypes.public import BaseContent, registerType
5from Globals import InitializeClass
6from Products.CMFCore.utils import getToolByName
7from AccessControl import ClassSecurityInfo, Unauthorized
8from config import PROJECTNAME
9
10schema = BaseSchema + Schema((
11    TextField('description',
12        accessor="Description",
13        widget=TextAreaWidget(
14            label="Description",
15            label_msgid="label_description",
16            description="Description here",
17            description_msgid="desc_description",
18            i18n_domain="toolbox"),
19        ),
20    TextField('body',
21        accessor="getBody",
22        requid=1,
23        widget=TextAreaWidget(
24            label="Structured text",
25            label_msgid="label_structured_text",
26            description="Write your text here",
27            description_msgid="desc_structured_text",
28            i18n_domain="toolbox"),
29        ),
30))
31
32class Story(BaseContent):
33    schema = schema
34    actions= (
35    {
36    'id':'view',
37    'name':'view',
38    'action':'string:${object_url}/story_view',
39    'premission':('View',),
40    },
41    {
42    'id':'edit',
43    'name':'Edit',
44    'action':'string:${object_url}/story_edit',
45    'premission':('View',),
46    },
47    )
48    meta_type = "Story"
49    archetype_name = "Story" 
50    global_allow = 1
51   
52    def __init__(self, id):
53    self.id = id
54        self.links = []
55
56    def getAuthorName(self):
57    """ Getting authors name for author field's default value """
58        authorInfo = self.Creator()
59    authorObject = self.portal_membership.getMemberById(authorInfo)
60    authorName = getattr(authorObject, 'fullname')
61    if authorName != None:
62        return authorName
63        else:
64        return str(authorObject)
65   
66    def getLink(self):
67    """ Links out """
68    return self.links
69
70    def addLink(self, REQUEST):
71    """ Links add """
72    linkName = REQUEST.get('linkname')
73    linkSelf = REQUEST.get('linkself')
74    if (linkName != '' and linkSelf != ''):
75        link = {'name' : linkName, 'href' : linkSelf}
76        self.links.append(link)
77        self._p_changed = 1
78
79    def saveLinks(self, REQUEST):
80    """ Modify links """
81    newLinks = []
82    for nr in range(1, len(self.links)+1):
83        if (REQUEST.get('ischecked'+str(nr)) != None):
84            linkName = REQUEST.get('linkname'+str(nr))
85            linkSelf = REQUEST.get('linkself'+str(nr))
86        if (linkName != '' and linkSelf != ''):
87                link = {'name' : linkName, 'href' : linkSelf}
88                #self.links[nr-1] = link
89            newLinks.append(link)
90
91        else:
92                newLinks.append(self.links[nr-1])
93    self.links = newLinks       
94        self._p_changed = 1
95
96registerType(Story, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.