source: products/qPloneComments/branches/plone-2.1/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.3 KB
Line 
1from Products.CMFDefault.DiscussionItem import DiscussionItemContainer, DiscussionItem
2from AccessControl import getSecurityManager, Unauthorized
3from DateTime import DateTime
4from Products.CMFCore.utils import getToolByName
5
6from utils import *
7
8# Patching createReply method of
9# Products.CMFDefault.DiscussionItem.DiscussionItemContainer
10def createReply( self, title, text, Creator=None ):
11    """
12        Create a reply in the proper place
13    """
14    container = self._container
15
16    id = int(DateTime().timeTime())
17    while self._container.get( str(id), None ) is not None:
18        id = id + 1
19    id = str( id )
20
21    item = DiscussionItem( id, title=title, description=title )
22    item._edit( text_format='structured-text', text=text )
23
24    if Creator:
25        item.creator = Creator
26
27    pm = getToolByName(self, 'portal_membership')
28    value = 0
29    if pm.isAnonymousUser():
30        value = 1
31    if item.hasProperty('isAnon'):
32        item.manage_changeProperties({'id':'isAnon','value':value})
33    else:
34        item.manage_addProperty(id='isAnon', value=value, type='boolean')
35
36    item.review_state="private"
37
38    item.setReplyTo( self._getDiscussable() )
39    self._container[ id ] = item
40
41    # Control of performing moderation
42    ifModerate = getProp(self, "enable_moderation", marker=False)
43    if ifModerate:
44        roles = ['DiscussionManager']
45        item.manage_permission('Delete objects', roles, acquire=1)
46        item.manage_permission('View', roles, acquire=0)
47    else:
48        item.review_state = "published"
49        item._p_changed = 1
50
51    item.__of__( self ).indexObject()       
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    return objects
73
74
75DiscussionItemContainer.createReply = createReply
76DiscussionItemContainer.getReplies = getReplies
Note: See TracBrowser for help on using the repository browser.