Back to index

plone3  3.1.7
Functions
update_discussion Namespace Reference

Functions

def update_discussion

Function Documentation

 1. Install (if it isn't there already) a type information
    object for DiscussionItems, so that they can get actions,
    etc.  Erase the "(default)" workflow bound to it, to prevent
    showing the "Retract" options, etc.

 2. Update all DiscussionItems to use the new marking for
    'in_reply_to':

      - Items which are replies to the containing content object
        have None as their 'in_reply_to';

      - Items which are replies to sibling items have the sibling's
        ID as their 'in_reply_to'.

    The representation we are converting from was:

      - Items which are replies to the containing content object
        have the portal-relative pathstring of the content object
        as their 'in_reply_to';

      - Items which are replies to sibling items have the absolute
        path of the sibling as their 'in_reply_to'.

Definition at line 4 of file update_discussion.py.

00004 
00005 def update_discussion(self):
00006     """
00007      1. Install (if it isn't there already) a type information
00008         object for DiscussionItems, so that they can get actions,
00009         etc.  Erase the "(default)" workflow bound to it, to prevent
00010         showing the "Retract" options, etc.
00011 
00012      2. Update all DiscussionItems to use the new marking for
00013         'in_reply_to':
00014 
00015           - Items which are replies to the containing content object
00016             have None as their 'in_reply_to';
00017 
00018           - Items which are replies to sibling items have the sibling's
00019             ID as their 'in_reply_to'.
00020 
00021         The representation we are converting from was:
00022 
00023           - Items which are replies to the containing content object
00024             have the portal-relative pathstring of the content object
00025             as their 'in_reply_to';
00026 
00027           - Items which are replies to sibling items have the absolute
00028             path of the sibling as their 'in_reply_to'.
00029     """
00030 
00031     log = []
00032     a = log.append
00033     types_tool = self.portal_types
00034     if not getattr( types_tool, 'Discussion Item', None ):
00035 
00036         fti = FactoryTypeInformation(
00037                                 **DiscussionItem.factory_type_information[0] )
00038         types_tool._setObject( 'Discussion Item', fti )
00039         a( 'Added type object for DiscussionItem' )
00040 
00041         workflow_tool = self.portal_workflow
00042         workflow_tool.setChainForPortalTypes( ( 'Discussion Item', ), () )
00043         a( 'Erased workflow for DiscussionItem' )
00044 
00045     items = self.portal_catalog.searchResults( meta_type='Discussion Item' )
00046     a( 'DiscussionItems updated:' )
00047 
00048     for item in items:
00049 
00050         object = item.getObject()
00051         talkback = object.aq_parent
00052         path = item.getPath()
00053         in_reply_to = object.in_reply_to
00054 
00055         if in_reply_to is None: # we've been here already
00056             continue
00057 
00058         irt_elements = in_reply_to.split('/')
00059 
00060         if len( irt_elements ) == 1:
00061             if talkback._container.get( irt_elements[0] ):
00062                 # we've been here already
00063                 continue
00064 
00065         if irt_elements[0] == '': # absolute, so we are IRT a sibling
00066             sibling_id = irt_elements[ -1 ]
00067             if talkback._container.get( sibling_id, None ):
00068                 in_reply_to = sibling_id
00069             else:
00070                 in_reply_to = None
00071         else:
00072             in_reply_to = None
00073 
00074         object.in_reply_to = in_reply_to
00075         assert object.inReplyTo() # sanity check
00076         object.reindexObject()
00077 
00078         a( path )
00079 
00080     return '\n'.join(log)
00081