source: products/qPloneComments/tags/2.0/patch.py @ 1591

Last change on this file since 1591 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        if hasattr(item, 'addCreator'):
26            item.addCreator(Creator)
27        else:
28            item.creator = Creator
29
30    pm = getToolByName(self, 'portal_membership')
31    value = 0
32    if pm.isAnonymousUser():
33        value = 1
34    if item.hasProperty('isAnon'):
35        item.manage_changeProperties({'id':'isAnon','value':value})
36    else:
37        item.manage_addProperty(id='isAnon', value=value, type='boolean')
38
39    item.review_state="private"
40
41    item.setReplyTo( self._getDiscussable() )
42    self._container[ id ] = item
43
44    # Control of performing moderation
45    ifModerate = getProp(self, "enable_moderation", marker=False)
46    if ifModerate:
47        roles = ['DiscussionManager']
48        item.manage_permission('Delete objects', roles, acquire=1)
49        item.manage_permission('View', roles, acquire=0)
50    else:
51        item.review_state = "published"
52
53    item.__of__( self ).indexObject()       
54    return id
55
56
57def getReplies( self ):
58    """
59        Return a sequence of the DiscussionResponse objects which are
60        associated with this Discussable
61    """
62    objects = []
63    a = objects.append
64    validate = getSecurityManager().validate
65
66    result_ids = self._getReplyResults()
67    for id in result_ids:
68        object = self._container.get( id ).__of__( self ) 
69        try:
70            if validate(self, self, id, object):
71                a( object )
72        except Unauthorized:
73            pass
74    return objects
75
76
77DiscussionItemContainer.createReply = createReply
78DiscussionItemContainer.getReplies = getReplies
Note: See TracBrowser for help on using the repository browser.