Back to index

plone3  3.1.7
Public Member Functions
Marshall.namespaces.cmfns.WorkflowAttribute Class Reference
Inheritance diagram for Marshall.namespaces.cmfns.WorkflowAttribute:
Inheritance graph
[legend]
Collaboration diagram for Marshall.namespaces.cmfns.WorkflowAttribute:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def getAttributeNames
def get
def deserialize
def serialize
def serializeWorkflow
def processXml

Detailed Description

serializes workflow state into the form below

it will try to deal as best as possible with arbitrary
python values, if it can't deal it will error out.

<workflow_history>
  <workflow id="">
   <!-- in chronological order -->
   <history>
     <wf_var id="" type="" value="" />
     <wf_var id="" type="" value="" />
   </history>
  </workflow>
</workflow_history>

Definition at line 189 of file cmfns.py.


Member Function Documentation

def Marshall.namespaces.cmfns.WorkflowAttribute.deserialize (   self,
  instance,
  ns_data 
)

Definition at line 213 of file cmfns.py.

00213 
00214     def deserialize(self, instance, ns_data):
00215         wf_records = ns_data.get(self.name, {})
00216         wf_tool = getToolByName(instance, 'portal_workflow')
00217 
00218         for wf_id in wf_records:
00219             #history = list( instance.workflow_history.setdefault( wf_id, () ) )
00220             history=[]
00221             for record in wf_records[ wf_id ]:
00222                 history.append( record )
00223             instance.workflow_history[ wf_id ] = tuple( history )

Here is the call graph for this function:

def Marshall.namespaces.cmfns.WorkflowAttribute.get (   self,
  instance 
)

Definition at line 210 of file cmfns.py.

00210 
00211     def get(self, instance):
00212         return getattr(instance, 'workflow_history', None)

Here is the caller graph for this function:

Definition at line 207 of file cmfns.py.

00207 
00208     def getAttributeNames(self):
00209         return ("workflow", "var", "history", 'workflow_history')
        
def Marshall.namespaces.cmfns.WorkflowAttribute.processXml (   self,
  context,
  node 
)

Definition at line 282 of file cmfns.py.

00282 
00283     def processXml(self, context, node):
00284 
00285         tag,namespace=utils.fixtag(node.tag,context.ns_map)
00286         data = context.getDataFor(self.namespace.xmlns)
00287         nsprefix=node.tag[:node.tag.find('}')+1]
00288 
00289         #iworkflow
00290         wf_node=node.find(nsprefix+'workflow')
00291         wf_id = wf_node.attrib.get(nsprefix+'id') or wf_node.attrib.get('id') #be tolerant with namespace sloppyness;)
00292         assert wf_id
00293             
00294             
00295         wf_data = data.setdefault(self.name, {})
00296         wf_data.setdefault( wf_id, [] )
00297         wf_pstate = data.setdefault('_wf_pstate', wf_id)
00298             
00299         #history
00300         hist_nodes=wf_node.findall(nsprefix+'history')
00301         wf_pstate = data['_wf_pstate']
00302         for hist_node in hist_nodes:
00303             record = {}
00304             data[self.name][wf_pstate].append( record )
00305     
00306             #var
00307             var_nodes=hist_node.findall(nsprefix+'var')
00308             vid = vtype = value = None
00309             
00310             for var_node in var_nodes:
00311                 vid=var_node.attrib.get(nsprefix+'id') or var_node.attrib.get('id')
00312                 vtype=var_node.attrib.get(nsprefix+'type',None) or var_node.attrib.get('type')
00313                 value=var_node.attrib.get(nsprefix+'value',None) or var_node.attrib.get('value') or ''
00314                 
00315                 assert vid and vtype and not value is None
00316     
00317                 value = demarshall_value( value, vtype )
00318                 wf_pstate = data['_wf_pstate']            
00319                 data[self.name][wf_pstate][-1][vid]=value
00320 
00321         return True
00322     

Here is the call graph for this function:

def Marshall.namespaces.cmfns.WorkflowAttribute.serialize (   self,
  dom,
  parent_node,
  instance 
)

Definition at line 224 of file cmfns.py.

00224 
00225     def serialize(self, dom, parent_node, instance):
00226         history = self.get( instance )
00227 
00228         if history is None:
00229             return
00230         
00231         elname = "%s:workflow_history"%(self.namespace.prefix)
00232         node = dom.createElementNS( self.namespace.xmlns, elname )
00233         keys = history.keys()
00234         for wf_id in keys:
00235             wf_node = self.serializeWorkflow( dom, wf_id, history )
00236             node.appendChild( wf_node )
00237         parent_node.appendChild( node )
00238         

def Marshall.namespaces.cmfns.WorkflowAttribute.serializeWorkflow (   self,
  dom,
  wf_id,
  wf_hist 
)

Definition at line 239 of file cmfns.py.

00239 
00240     def serializeWorkflow(self, dom, wf_id, wf_hist):
00241 
00242         prefix = self.namespace.prefix
00243         xmlns  = self.namespace.xmlns
00244         
00245         elname = "%s:workflow"%prefix
00246         node = dom.createElementNS(xmlns, elname)
00247 
00248         wfid_attr = dom.createAttribute( "id" )
00249         wfid_attr.value = wf_id
00250         
00251         node.setAttributeNode( wfid_attr )
00252         
00253         for history in wf_hist[wf_id]:
00254             elname = "%s:%s"%(prefix, "history")
00255             history_node = dom.createElementNS(xmlns, elname)
00256             items = history.items()
00257             items.sort(lambda a,b: cmp(a[0],b[0]))
00258             
00259             for k,v in items:
00260                 elname = "%s:%s"%(prefix, "var" )
00261                 var_node = dom.createElementNS(xmlns, elname)
00262                 # Attributes normally do not have a namespace
00263                 value_attr = dom.createAttribute("value")
00264                 type_attr = dom.createAttribute("type")
00265                 id_attr = dom.createAttribute("id")
00266 
00267                 value, vtype = marshall_value( v )
00268 
00269                 id_attr.value = str(k)
00270                 type_attr.value = vtype
00271                 value_attr.value = value
00272 
00273                 var_node.setAttributeNode(id_attr)
00274                 var_node.setAttributeNode(type_attr)
00275                 var_node.setAttributeNode(value_attr)
00276                 
00277                 history_node.appendChild( var_node )
00278                 
00279             node.appendChild( history_node )
00280 
00281         return node
                

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: