Ejemplo n.º 1
0
def _MDDManageActions_Paste( theInteractionCtxt):

    if not theInteractionCtxt:
        return None

    aContextualElement = theInteractionCtxt.fGP( 'theBrowsedElement', None)
    if aContextualElement == None:
        return None

    aModelDDvlPloneTool = theInteractionCtxt.fGP( 'theModelDDvlPloneTool', None)
    if not aModelDDvlPloneTool:
        return None

    someAdditionalParms = theInteractionCtxt.fGP( 'theAdditionalParms', None)

    aBeginTime  = fMillisecondsNow()

    aPasteReport = aModelDDvlPloneTool.fObjectPaste( 
        theTimeProfilingResults     =None,
        theContainerObject          =aContextualElement, 
        theAdditionalParams         =someAdditionalParms,
    )

    anEndTime  = fMillisecondsNow()

    anActionResult= {
        'action':       'Paste',
        'begin_time':   aBeginTime,
        'end_time':     anEndTime,
        'report':       aPasteReport,
    }
        
    theInteractionCtxt.pAppendActionResult( anActionResult)

    return None
Ejemplo n.º 2
0
def _MDDManageActions_MoveElementosPlone( theRdCtxt):


    if not theInteractionCtxt:
        return None

    aContextualElement = theInteractionCtxt.fGP( 'theBrowsedElement', None)
    if aContextualElement == None:
        return None

    aModelDDvlPloneTool = theInteractionCtxt.fGP( 'theModelDDvlPloneTool', None)
    if not aModelDDvlPloneTool:
        return None

    someAdditionalParms = theInteractionCtxt.fGP( 'theAdditionalParms', None)

    aRequest        = theInteractionCtxt.fGP( 'theRequest', None)    

    aTraversalName  = aRequest.get( 'theTraversalName', None)
    if not aTraversalName:
        return None

    aMovedObjectUID = aRequest.get( 'theMovedObjectUID', None)
    if not aMovedObjectUID:
        return None

    aMoveDirection  = aRequest.get( 'theMoveDirection', None)        
    if not aMoveDirection:
        return None



    aBeginTime  = fMillisecondsNow()

    aMoveReferenceResult = aModelDDvlPloneTool.fMoveSubObjectPlone( 
        theTimeProfilingResults     =None,
        theContainerElement         =aContextualElement,  
        theTraversalName            =aTraversalName, 
        theMovedObjectUID           =aMovedObjectUID, 
        theMoveDirection            =aMoveDirection, 
        theAdditionalParams         =someAdditionalParms,
    )

    anEndTime  = fMillisecondsNow()

    anActionResult= {
        'action':       'MovePlone',
        'begin_time':   aBeginTime,
        'end_time':     anEndTime,
        'report':       aMoveResult,
    }
    theInteractionCtxt.pAppendActionResult( anActionResult)
        
    return None
Ejemplo n.º 3
0
def _MDDManageActions_GroupActions( theInteractionCtxt):

    if not theInteractionCtxt:
        return None

    aContextualElement = theInteractionCtxt.fGP( 'theBrowsedElement', None)
    if aContextualElement == None:
        return None

    aModelDDvlPloneTool = theInteractionCtxt.fGP( 'theModelDDvlPloneTool', None)
    if not aModelDDvlPloneTool:
        return None

    someAdditionalParms = theInteractionCtxt.fGP( 'theAdditionalParms', None)
    
    aRequest            = theInteractionCtxt.fGP( 'theRequest', None)    

    aRequestForm = aRequest.get( 'form', None)
    if not aRequestForm:
        return None

    aGroupAction = aRequestForm.get( 'theGroupAction', None)
    if not aGroupAction:
        return None

    aReferenceFieldName = aRequestForm.get( 'theReferenceFieldName', None) 
    someGroupUIDs       = aRequestForm.get( 'theUIDs', []) 

    if not someGroupUIDs:
        return None
    
    aBeginTime  = fMillisecondsNow()

    aGroupActionReport   = aModelDDvlPloneTool.fGroupAction( 
        theTimeProfilingResults     =None,
        theContainerObject          =aContextualElement, 
        theGroupAction              =aGroupAction,
        theGroupUIDs                =someGroupUIDs,
        theReferenceFieldName       =aReferenceFieldName,
        theAdditionalParams         =someAdditionalParms,
    )

    anEndTime  = fMillisecondsNow()

    anActionResult= {
        'action':       aGroupAction,
        'begin_time':   aBeginTime,
        'end_time':     anEndTime,
        'report':       aGroupActionReport,
    }
    theInteractionCtxt.pAppendActionResult( anActionResult)
        

    return None
Ejemplo n.º 4
0
def MDDManageActions(  theInteractionCtxt=None):
    """Main service for handling the actions requested by users for manipulation of the objects network, or the clipboard.

    Entry point invoked from a the MDDInteractionTabular external method.

    Must be registered as an External method as:
        Id            MDDManageActions
        Title         MDDManageActions
        Module name   MDDManageActions
        Function name MDDManageActions

    """

    
    if not theInteractionCtxt:
        return None
    

    # #################################################################
    """Get basic parameters from received interaction context.

    """
    aModelDDvlPloneTool = theInteractionCtxt.fGP( 'theModelDDvlPloneTool', None)
    aBrowsedElement     = theInteractionCtxt.fGP( 'theBrowsedElement', None) 
    aRequest            = theInteractionCtxt.fGP( 'theRequest', None)    
    anOutput            = theInteractionCtxt.fGP( 'output', None)    
    aPasteRequested     = theInteractionCtxt.fGP( 'thePasteRequested', False) 


       
    # #################################################################
    """Record time now

    """

    theInteractionCtxt.pSP( 'theActionsBeginTime', fMillisecondsNow())


    # #################################################################
    """Manage paste into the current element

    """
    if aPasteRequested:
        _MDDManageActions_Paste( theInteractionCtxt)




    # #################################################################
    """Manage actions on an element's aggregation or relationship

    """
    aRequestForm = aRequest.get( 'form', None)
    if aRequestForm:
        aGroupAction = aRequestForm.get( 'theGroupAction', None)
        if aGroupAction:
            aReferenceFieldName = aRequestForm.get( 'theReferenceFieldName', None) 
            someGroupUIDs       = aRequestForm.get( 'theUIDs', []) 

            _MDDManageActions_GroupActions( theInteractionCtxt, aGroupAction, aReferenceFieldName, someGroupUIDs)



    # #################################################################
    """Manage clear clipboard

    """
    aClearClipboard = aRequest.get( 'theClearClipboard', None)
    if aClearClipboard:
        _MDDManageActions_ClearClipboard( theInteractionCtxt)


    # #################################################################
    """Manage reorder contained (MDD aware) elements

    """
    aTraversalName  = aRequest.get( 'theTraversalName', None)
    aMovedElementID = aRequest.get( 'theMovedElementID', None)
    aMoveDirection  = aRequest.get( 'theMoveDirection', None)        
    if aTraversalName and aMovedElementID and aMoveDirection:
        _MDDManageActions_MoveElementos( theInteractionCtxt, aTraversalName, aMovedElementID, aMoveDirection)


    # #################################################################
    """Manage reorder referenced elements

    """
    aMovedReferenceUID = aRequest.get( 'theMovedReferenceUID', None)
    if aTraversalName and aMovedReferenceUID and aMoveDirection:
        _MDDManageActions_MoveReferencias( theInteractionCtxt, aTraversalName, aMovedReferenceUID, aMoveDirection)




    # #################################################################
    """Manage reorder contained Plone elements

    """
    aMovedObjectUID = aRequest.get( 'theMovedObjectUID', None)
    if aTraversalName and aMovedObjectUID and aMoveDirection:
        _MDDManageActions_MoveElementosPlone( theInteractionCtxt, aTraversalName, aMovedObjectUID, aMoveDirection)


    # #################################################################
    """Record time now

    """
    theInteractionCtxt.pSP( 'theActionsEndTime', fMillisecondsNow())

    return None
def MDDInteractionTabular(theInteractionParms=None, theViewParms=None):
    """Main service for handling the request-reply interaction  on tabular views, allowing actions for manipulation of the clipboard and the objects network.

    Entry point invoked from a template.

    PUBLIC METHOD for Tabular renderings with handling of Actions allowing manipulation of elements by authoried users.
    Must be registered as an External method as:
        Id            MDDInteractionTabular
        Title         MDDInteractionTabular
        Module name   MDDInteractionTabular
        Function name MDDInteractionTabular

    """

    if not theInteractionParms:
        return u''

    # #################################################################
    """Create interaction context.Initialize with received basic parameters. Initialize output streaming. 

    """
    aModelDDvlPloneTool = theInteractionParms.get('theModelDDvlPloneTool',
                                                  None)
    aBrowsedElement = theInteractionParms.get('theBrowsedElement', None)
    aRequest = theInteractionParms.get('theRequest', None)
    aPasteRequested = theInteractionParms.get('thePasteRequested', False)

    anOutput = StringIO(u'')

    aInteractionCtxt = fNewInteractionContext(
        aBrowsedElement, {
            'theInteractionParms':
            theInteractionParms,
            'theViewParms':
            theViewParms,
            'theModelDDvlPloneTool':
            aModelDDvlPloneTool,
            'theBrowsedElement':
            theInteractionParms.get('theBrowsedElement', None),
            'theRequest':
            aRequest,
            'thePasteRequested':
            aPasteRequested,
            'theBeginTime':
            None,
            'theEndTime':
            None,
            'output':
            anOutput,
            'pO':
            lambda theString: anOutput.write(theString),
            'pOL':
            lambda theString: anOutput.write('%s\n' % theString),
            'pOS':
            lambda theString: anOutput.write('%s\n' % '\n'.join(
                [unaLine.strip() for unaLine in theString.splitlines()])),
        })

    # #################################################################
    """Retrieve localizations for internationalized strings.

    """

    _MDDInit_UITranslations_Tabular(aInteractionCtxt)

    # #################################################################
    """Make sure essential parameters are supplied, or return an error page.

    """
    if not theInteractionParms:
        _MDDRender_EmptyPageContents(aInteractionCtxt,
                                     cResultCondition_MissingParameter + '-',
                                     'theInteractionParms', None)
        anHTMLToReturn = anOutput.getvalue()
        return anHTMLToReturn

    if not aModelDDvlPloneTool:
        _MDDRender_EmptyPageContents(aInteractionCtxt,
                                     cResultCondition_MissingParameter + '-',
                                     'theModelDDvlPloneTool', None)
        anHTMLToReturn = anOutput.getvalue()
        return anHTMLToReturn

    if aBrowsedElement == None:
        _MDDRender_EmptyPageContents(aInteractionCtxt,
                                     cResultCondition_MissingParameter + '-',
                                     'theBrowsedElement', None)
        anHTMLToReturn = anOutput.getvalue()
        return anHTMLToReturn

    if not aRequest:
        _MDDRender_EmptyPageContents(
            aInteractionCtxt,
            aModelDDvlPloneTool.fTranslateI18N(
                aBrowsedElement, 'ModelDDvlPlone',
                cResultCondition_MissingParameter,
                cResultCondition_MissingParameter + '-'), 'theRequest', None)
        anHTMLToReturn = anOutput.getvalue()
        return anHTMLToReturn

    # #################################################################
    """Begin Process.

    """
    aInteractionCtxt.pSP('theBeginTime', fMillisecondsNow())

    # #################################################################
    """Flush cache entries, if so requested.

    """

    aFlushCacheCode = aRequest.get(cRqstParmName_FlushCacheCode, None)
    aFlushDiskCache = aRequest.get(cRqstParmName_FlushDiskCache, None)
    if aFlushCacheCode:
        aModelDDvlPloneTool.fFlushCachedTemplateForElement(
            aBrowsedElement, aFlushCacheCode, 'Tabular_NoHeaderNoFooter',
            aFlushDiskCache)

    # #################################################################
    """Try to get and execute the external method to Manage Actions.

    """
    anActionsResult = None

    aBeginTime = fMillisecondsNow()
    try:
        unManageActionsExternalMethod = aq_get(aBrowsedElement,
                                               cMDDExtMethod_MDDManageActions,
                                               None, 1)
    except:
        None
    if unManageActionsExternalMethod and isinstance(
            unManageActionsExternalMethod, ExternalMethod):

        anActionsResult = unManageActionsExternalMethod(aInteractionCtxt)
        if anActionsResult:
            aInteractionCtxt.pSP('actions_result', anActionsResult)

            anEndTime = fMillisecondsNow()
            theInteractionCtxt.pAppendRetrievalResult({
                'subject':
                'ACTIONS',
                'begin_time':
                aBeginTime,
                'end_time':
                anEndTime,
                'result':
                anActionsResult,
            })

    # #################################################################
    """Retrieve Clipboard content,.

    """
    aBeginTime = fMillisecondsNow()

    aClipboardResult = aModelDDvlPloneTool.fClipboardResult(
        theTimeProfilingResults=None,
        theContextualElement=aBrowsedElement,
        theAdditionalParams=None,
    )
    if aClipboardResult:
        aInteractionCtxt.pSP('clipboard_result', aClipboardResult)

        anEndTime = fMillisecondsNow()

        aInteractionCtxt.pAppendRetrievalResult({
            'subject': 'CLIPBOARD',
            'begin_time': aBeginTime,
            'end_time': anEndTime,
            'result': aClipboardResult,
        })

    # #################################################################
    """If element not writeable, present a note.

    """

    _MDDRender_NotAllowWrite(aInteractionCtxt, aBrowsedElement)

    # #################################################################
    """Invoke External Method to Present Clipboard content, if any.

    """
    if aClipboardResult and aClipboardResult.get('num_elements', 0):
        #if unPortalRoot:
        unPresentationClipboardExternalMethod = None
        try:
            unPresentationClipboardExternalMethod = aq_get(
                aBrowsedElement, cMDDExtMethod_MDDPresentationClipboard, None,
                1)
        except:
            None
        if unPresentationClipboardExternalMethod and isinstance(
                unPresentationClipboardExternalMethod, ExternalMethod):
            unPresentationClipboardExternalMethod(aInteractionCtxt)

    # #################################################################
    """Invoke External Method to Present Action results, if any.

    """
    if anActionsResult:
        unPresentationActionResultsExternalMethod = None
        try:
            unPresentationActionResultsExternalMethod = aq_get(
                aBrowsedElement, cMDDExtMethod_MDDPresentationActionsResults,
                None, 1)
        except:
            None
        if unPresentationActionResultsExternalMethod and isinstance(
                unPresentationActionResultsExternalMethod, ExternalMethod):
            unPresentationActionResultsExternalMethod(aInteractionCtxt)

    # #################################################################
    """Present Page body: render on supplied output stream, by-passing cache and forcing to render, or trying first to obtain the rendered HTML from cache.

    """
    aPresentationOutput = StringIO(u'')

    aPresentationCtxt = aInteractionCtxt.fNewCtxt({
        'output':
        aPresentationOutput,
        'pO':
        lambda theString: aPresentationOutput.write(theString),
        'pOL':
        lambda theString: aPresentationOutput.write('%s\n' % theString),
        'pOS':
        lambda theString: aPresentationOutput.write('%s\n' % '\n'.join(
            [unaLine.strip() for unaLine in theString.splitlines()])),
    })

    unPresentationTabularExternalMethod = None
    try:
        unPresentationTabularExternalMethod = aq_get(
            aBrowsedElement, cMDDExtMethod_MDDPresentationTabular, None, 1)
    except:
        None

    if unPresentationTabularExternalMethod and isinstance(
            unPresentationTabularExternalMethod, ExternalMethod):

        aNoCache = aRequest.get(cRqstParmName_NoCache, None)
        aNoCacheCode = aRequest.get(cRqstParmName_NoCacheCode, None)
        aNoCacheAllowed = aModelDDvlPloneTool.fNoCacheIdAllowsRender(
            aBrowsedElement, aNoCacheCode, 'Tabular_NoHeaderNoFooter')

        aPresentedString = ''
        if aNoCacheAllowed:
            aPresentedString = unPresentationTabularExternalMethod(
                theInteractionCtxt=aPresentationCtxt,
                theViewParms=theViewParms)
        else:
            aPresentedString = aModelDDvlPloneTool.fRenderCallableOrCachedForElement(
                aBrowsedElement, 'Tabular_NoHeaderNoFooter',
                lambda otherInteractionCtxt, otherViewParms:
                unPresentationTabularExternalMethod(
                    theInteractionCtxt=otherInteractionCtxt,
                    theViewParms=otherViewParms), aPresentationCtxt,
                theViewParms)

        if aPresentedString:
            anOutput.write(aPresentedString)

    # #################################################################
    """Present Page footer: sub-componentes (invoked templates) may delegate on cache, for example to present the Credits.

    """
    aHTMLPresentationFooter = aModelDDvlPloneTool.fRenderTemplate(
        aBrowsedElement, '%sFooter_view')
    if aHTMLPresentationFooter:
        anOutput.write(aHTMLPresentationFooter)

    aInteractionCtxt.pSP('theEndTime', fMillisecondsNow())

    anHTMLToReturn = anOutput.getvalue()
    return anHTMLToReturn