source: trunk/Module.py @ 47

Revision 47, 2.9 KB checked in by tarmo, 14 years ago (diff)

Converted all line feeds to LF and added the svn:eol-style
property to keep the line feeds in LF. When adding new text files,
run the command "svn propset svn:eol-style LF [FILE]" to set the
property.

  • 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 WYSIWYMWidget import WYSIWYMWidget, WYSIWYMTranslator
14
15schema = BaseSchema + LOMSchema + Schema((
16    TextField('body',
17        required=True,
18        primary=False,
19        languageIndependent=False,
20        accessor="getBody",
21        widget=WYSIWYMWidget(
22            label="Our body",
23            label_msgid="label_body",
24            description="Our body",
25            description_msgid="desc_body",
26            i18n_domain="toolbox",),
27        ),
28))
29
30class Module(BaseContent, WYSIWYMTranslator):
31    schema = schema
32    actions = (
33        {'id':'view',
34         'name':'view',
35         'action':'string:${object_url}/module_view',
36         'permission':('View',),
37        },
38    )
39    meta_type = "Module"
40    archetype_name = "Module" 
41    global_allow = 1
42
43    # Always access the __users list using this method.
44    def __getMyUsers(self):
45        try:
46            return self.__users
47        except AttributeError:
48            # Changes to PersistentList are stored automatically
49            self.__users=PersistentList()
50            return self.__users
51
52    #TODO: Need security settings
53    def useThis(self,REQUEST=None):
54        """Marks the current user as a user of this content."""
55        users=self.__getMyUsers()
56        user = getSecurityManager().getUser()
57        member = getToolboxMember(user.getId(),self)
58        if not user.getId() in users:
59            users.append(user.getId())
60        if not self.getId() in member.getTokens('used_content'):
61            member.addToken('used_content',self.getId())
62
63    def unuseThis(self):
64        """Undoes useThis."""
65        users=self.__getMyUsers()
66        user = getSecurityManager().getUser()
67        member = getToolboxMember(user.getId(),self)
68        if user.getId() in users:
69            users.remove(user.getId())
70        if self.getId() in member.getTokens('used_content'):
71            member.delToken('used_content',self.getId())
72
73    def countUsers(self):
74        """Returns count of users."""
75        users=self.__getMyUsers()
76        return len(users)
77
78    def isUsedByUser(self):
79        """Returns whether the current user is a user of this content."""
80        users=self.__getMyUsers()
81        user = getSecurityManager().getUser()
82        return user.getId() in users
83
84registerType(Module, PROJECTNAME)
Note: See TracBrowser for help on using the repository browser.