Changeset 5183 for WAeUP_SRP/trunk


Ignore:
Timestamp:
5 May 2010, 05:52:36 (15 years ago)
Author:
Henrik Bettermann
Message:

implement changeWorkflofState from Gilles Lenfant

http://glenfant.wordpress.com/2010/04/02/changing-workflow-state-quickly-on-cmfplone-content/

1st step: bypass doActionFor in StudentImport? and VerdictImport?

Location:
WAeUP_SRP/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/WAeUPImport.py

    r5063 r5183  
    11271127            current_level = mapping.get('current_level','')
    11281128            transition = mapping.get('reg_transition',None)
     1129            change_reg_state = mapping.get('change_reg_state',None)  # for brute force method
    11291130            # the validate_courses import transition is not really useful because it does not execute validate_courses.py
    11301131            if transition and transition not in ('admit','return','graduate','pay_school_fee','validate_courses'):
     
    11811182                            pass
    11821183            if transition:
     1184                #import pdb;pdb.set_trace()
    11831185                try:
    11841186                    self.portal_workflow.doActionFor(student_obj,transition)
    11851187                except:
    11861188                    msg = "reg_transition not allowed"
     1189            elif change_reg_state:
     1190                msg = self.waeup_tool.changeStudentState(student_obj, change_reg_state)
     1191             
    11871192            if password:
    11881193                self.waeup_tool.editPassword(student_id,password)
     
    14411446            level_review_state = wftool.getInfoFor(level_obj,'review_state',None)
    14421447            if level_review_state != "closed":
    1443                 wftool.doActionFor(level_obj,'close')
     1448                #wftool.doActionFor(level_obj,'close')
     1449                self.waeup_tool.changeWorkflowState(level_obj, 'closed')
    14441450                # msg = 'student %s: level %s is not closed' % (student_id,
    14451451                #                                                      current_level)
     
    14481454            level_obj.getContent().edit(mapping = d)
    14491455            if student_review_state != "returning":
    1450                 wftool.doActionFor(student_obj,'return')
     1456                #wftool.doActionFor(student_obj,'return')
     1457                self.waeup_tool.changeStudentState(student_obj, 'returning')
    14511458            # try:
    14521459            #     wftool.doActionFor(level_obj,'close')
  • WAeUP_SRP/trunk/WAeUPTool.py

    r5168 r5183  
    19291929
    19301930
     1931    security.declareProtected(ModifyPortalContent,"changeWorkflowState")
     1932    def changeWorkflowState(self, content, state_id, acquire_permissions=False,
     1933                            portal_workflow=None, **kw):
     1934        """Change the workflow state of an object
     1935        @param content: Content obj which state will be changed
     1936        @param state_id: name of the state to put on content
     1937        @param acquire_permissions: True->All permissions unchecked and on riles and
     1938                                    acquired
     1939                                    False->Applies new state security map
     1940        @param portal_workflow: Provide workflow tool (optimisation) if known
     1941        @param kw: change the values of same name of the state mapping
     1942        @return: None
     1943        """
     1944   
     1945        if portal_workflow is None:
     1946            portal_workflow = getToolByName(content, 'portal_workflow')
     1947   
     1948        # Might raise IndexError if no workflow is associated to this type
     1949
     1950        wf_def = portal_workflow.getWorkflowsFor(content)[0]
     1951        wf_id= wf_def.getId()
     1952   
     1953        wf_state = {
     1954            'action': None,
     1955            'actor': None,
     1956            'comments': "Setting state to %s" % state_id,
     1957            'review_state': state_id,
     1958            'time': DateTime.DateTime(),
     1959            }
     1960   
     1961        # Updating wf_state from keyword args
     1962        for k in kw.keys():
     1963            # Remove unknown items
     1964            if not wf_state.has_key(k):
     1965                del kw[k]
     1966        if kw.has_key('review_state'):
     1967            del kw['review_state']
     1968        wf_state.update(kw)
     1969   
     1970        portal_workflow.setStatusOf(wf_id, content, wf_state)
     1971   
     1972        if acquire_permissions:
     1973            # Acquire all permissions
     1974            for permission in content.possible_permissions():
     1975                content.manage_permission(permission, acquire=1)
     1976        else:
     1977            # Setting new state permissions
     1978            wf_def.updateRoleMappingsFor(content)
     1979   
     1980        # Map changes to the catalogs
     1981        content.reindexObject(idxs=['allowedRolesAndUsers', 'review_state'])
     1982        return
     1983       
     1984       
     1985       
     1986    security.declareProtected(ModifyPortalContent,"changeStudentState")
     1987    def changeStudentState(self, content, state_id, acquire_permissions=False,
     1988                            portal_workflow=None, **kw):
     1989        """Change the student state of an object
     1990       
     1991        ChangeWorkflowState + indexing students_catalog and check for registration state
     1992
     1993        """
     1994   
     1995        if portal_workflow is None:
     1996            portal_workflow = getToolByName(content, 'portal_workflow')
     1997   
     1998        # Might raise IndexError if no workflow is associated to this type
     1999
     2000        wf_def = portal_workflow.getWorkflowsFor(content)[0]
     2001        wf_id= wf_def.getId()
     2002        wf = portal_workflow.getWorkflowById(wf_id)
     2003
     2004        if not wf.states.get(state_id):
     2005            return 'reg state does not exist'
     2006       
     2007        wf_state = {
     2008            'action': None,
     2009            'actor': None,
     2010            'comments': "Setting state to %s" % state_id,
     2011            'review_state': state_id,
     2012            'time': DateTime.DateTime(),
     2013            }
     2014   
     2015        # Updating wf_state from keyword args
     2016        for k in kw.keys():
     2017            # Remove unknown items
     2018            if not wf_state.has_key(k):
     2019                del kw[k]
     2020        if kw.has_key('review_state'):
     2021            del kw['review_state']
     2022        wf_state.update(kw)
     2023       
     2024        portal_workflow.setStatusOf(wf_id, content, wf_state)
     2025   
     2026        if acquire_permissions:
     2027            # Acquire all permissions
     2028            for permission in content.possible_permissions():
     2029                content.manage_permission(permission, acquire=1)
     2030        else:
     2031            # Setting new state permissions
     2032            wf_def.updateRoleMappingsFor(content)
     2033   
     2034        # Map changes to the catalogs
     2035        content.reindexObject(idxs=['allowedRolesAndUsers', 'review_state'])
     2036        data = {}
     2037        #import pdb;pdb.set_trace()
     2038        student_id = content.getId()
     2039        res = self.students_catalog(id=student_id)
     2040        data['id'] = student_id
     2041        data['review_state'] = state_id
     2042        self.students_catalog.modifyRecord(**data)       
     2043       
     2044        return       
     2045
     2046
    19312047InitializeClass(WAeUPTool)
  • WAeUP_SRP/trunk/profiles/default/layouts/import_student.xml

    r5031 r5183  
    3131  <property name="is_required">True</property>
    3232 </widget>
     33 
     34 <widget name="change_reg_state" meta_type="String Widget">
     35  <property name="fields">
     36   <element value="change_reg_state"/>
     37  </property>
     38  <property name="is_required">False</property>
     39 </widget>
     40 
     41 
    3342 <widget name="email" meta_type="Email Widget">
    3443  <property name="title">Email</property>
  • WAeUP_SRP/trunk/profiles/default/schemas/import_student.xml

    r4558 r5183  
    55 <field name="import_mode" meta_type="CPS String Field"/>
    66 <field name="reg_transition" meta_type="CPS String Field"/>
     7 <field name="change_reg_state" meta_type="CPS String Field"/>
    78 <field name="firstname" meta_type="CPS String Field"/>
    89 <field name="middlename" meta_type="CPS String Field"/>
Note: See TracChangeset for help on using the changeset viewer.