source: trunk/Module.py @ 54

Revision 54, 2.9 KB checked in by laszlo, 14 years ago (diff)

Created the Activity content type. We changed WYSIWYM also (closes #150 spent 2h).

  • Property svn:eol-style set to LF
Line 
1from Products.Archetypes.public import BaseSchema, Schema, MetadataSchema
2from Products.Archetypes.public import StringField, LinesField, TextField
3from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget
4from Products.Archetypes.public import BaseContent, registerType
5from Globals import InitializeClass
6from Products.CMFCore.utils import getToolByName
7from AccessControl import ClassSecurityInfo, Unauthorized, getSecurityManager
8from config import PROJECTNAME
9from LOMSchema import LOMSchema
10from Products.Archetypes.ExtensibleMetadata import ExtensibleMetadata
11from ZODB.PersistentList import PersistentList
12from ToolboxMember import getToolboxMember
13from WYSIWYM import WYSIWYMField, WYSIWYMWidget
14
15schema = BaseSchema + LOMSchema + Schema((
16    WYSIWYMField('body',
17        required=True,
18        primary=False,
19        languageIndependent=False,
20        widget=WYSIWYMWidget(
21            label="Body",
22            label_msgid="label_body",
23            description="Module body",
24            description_msgid="desc_body",
25            i18n_domain="toolbox",),
26        ),
27))
28
29class Module(BaseContent):
30    schema = schema
31    actions = (
32        {'id':'view',
33         'name':'view',
34         'action':'string:${object_url}/module_view',
35         'permission':('View',),
36        },
37    )
38    meta_type = "Module"
39    archetype_name = "Module" 
40    global_allow = 1
41
42    # Always access the __users list using this method.
43    def __getMyUsers(self):
44        try:
45            return self.__users
46        except AttributeError:
47            # Changes to PersistentList are stored automatically
48            self.__users=PersistentList()
49            return self.__users
50
51    #TODO: Need security settings
52    def useThis(self,REQUEST=None):
53        """Marks the current user as a user of this content."""
54        users=self.__getMyUsers()
55        user = getSecurityManager().getUser()
56        member = getToolboxMember(user.getId(),self)
57        if not user.getId() in users:
58            users.append(user.getId())
59        if not self.getId() in member.getTokens('used_content'):
60            member.addToken('used_content',self.getId())
61
62    def unuseThis(self):
63        """Undoes useThis."""
64        users=self.__getMyUsers()
65        user = getSecurityManager().getUser()
66        member = getToolboxMember(user.getId(),self)
67        if user.getId() in users:
68            users.remove(user.getId())
69        if self.getId() in member.getTokens('used_content'):
70            member.delToken('used_content',self.getId())
71
72    def countUsers(self):
73        """Returns count of users."""
74        users=self.__getMyUsers()
75        return len(users)
76
77    def isUsedByUser(self):
78        """Returns whether the current user is a user of this content."""
79        users=self.__getMyUsers()
80        user = getSecurityManager().getUser()
81        return user.getId() in users
82
83registerType(Module, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.