source: products/qPloneComments/tags/1.5/patch.py @ 1

Last change on this file since 1 was 1, checked in by myroslav, 18 years ago

Building directory structure

File size: 2.4 KB
Line 
1#from Products.CMFCore.CMFCorePermissions import ReplyToItem, View
2from Products.CMFDefault.DiscussionItem import DiscussionItemContainer, DiscussionItem
3from AccessControl import getSecurityManager, Unauthorized
4from DateTime import DateTime
5from Products.CMFCore.utils import getToolByName
6
7#from config import *
8from utils import *
9
10# Patching createReply method of
11# Products.CMFDefault.DiscussionItem.DiscussionItemContainer
12def createReply( self, title, text, Creator=None ):
13    """
14        Create a reply in the proper place
15    """
16    container = self._container
17
18    id = int(DateTime().timeTime())
19    while self._container.get( str(id), None ) is not None:
20        id = id + 1
21    id = str( id )
22
23    item = DiscussionItem( id, title=title, description=title )
24    item._edit( text_format='structured-text', text=text )
25
26    if Creator:
27        item.creator = Creator
28
29    pm = getToolByName(self, 'portal_membership')
30    value = 0
31    if pm.isAnonymousUser():
32        value = 1
33    if item.hasProperty('isAnon'):
34        item.manage_changeProperties({'id':'isAnon','value':value})
35    else:
36        item.manage_addProperty(id='isAnon', value=value, type='boolean')
37
38    item.__of__( self ).indexObject()
39
40    item.setReplyTo( self._getDiscussable() )
41
42    self._container[ id ] = item
43
44    # Control of performing moderation
45    ifModerate = getProp(self, "Turning_on/off_Moderation", marker=False)
46    if ifModerate:
47        from zLOG import LOG
48        LOG('qPloneComments',777,'createReply','ifModerate=%s \t that''s why Moderation was called' % str(ifModerate) )
49        roles = ['Manager', 'Owner', 'Reviewer']
50        item.manage_permission('View', roles, acquire=0)
51
52    return id
53
54
55def getReplies( self ):
56    """
57        Return a sequence of the DiscussionResponse objects which are
58        associated with this Discussable
59    """
60    objects = []
61    a = objects.append
62    validate = getSecurityManager().validate
63
64    result_ids = self._getReplyResults()
65    for id in result_ids:
66        object = self._container.get( id ).__of__( self ) 
67        try:
68            if validate(self, self, id, object):
69                a( object )
70        except Unauthorized:
71            pass
72
73    return objects
74
75DiscussionItemContainer.__dict__["createReply"] =  createReply
76DiscussionItemContainer.__dict__["getReplies"] =  getReplies
Note: See TracBrowser for help on using the repository browser.