ERP5EGov_Extensions.py 4.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
from zLOG import LOG

def sendCrendentialsByEMail(self, login, password, user_email):
  activity_tool = self.getPortalObject().portal_activities
  from Products.MailHost.MailHost import MailHostError
  from Products.CMFActivity.ActivityTool import Message
  import socket
  portal = activity_tool.getPortalObject()

  mail_text="""From: %s
To: %s
Subject: %s

Thanks for registrering to SAFI, now you can connect in on www.safi.sn with the followin credentials :

Login: %s
Password: %s
18
""" % ('fabien@nexedi.com', user_email, 'your credential for www.safi.sn',
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
     login, password)

  try:
    activity_tool.MailHost.send( mail_text )
  except (socket.error, MailHostError), message:
    LOG('ActivityTool.notifyUser', 0, 'Mail containing failure information failed to be sent: %s.' % (message))

def getPoralTypeListForWorkflow(self, workflow):
  '''
    return a list of portal_types that use workflow
  '''
  pw = self.portal_workflow
  cbt = pw._chains_by_type
  ti = pw._listTypeInfo()

  portal_type_list = []
  for t in ti:
    id = t.getId()
    if cbt is not None and cbt.has_key(id) and workflow in cbt[id]:
      portal_type_list.append(id)

  return portal_type_list

42
def getPortalTypeWorklistDictForWorkflow(self, workflow_list):
43 44 45 46
  """
    return a dict containing portal_type and all informations about work_list
    of workflow :

47
    {'Subscription Form': {'signed': {'category': 'global',
48 49 50 51 52 53 54
                                         'count': 1,
                                         'description': 'Subscription Forms to archive',
                                         'formated_name': 'Subscription Forms to archive (%(count)s)',
                                         'formated_url': 'Base_viewSearchResultList?validation_state=signed&local_roles=Assignor&reset=1&portal_type=Subscription Form
',
                                         'id': 'subscription_forms_to_archive',
                                         'roles': ('Assignor',),
55
                                         'validation_state': 'signed'}
56 57
                          },
              .....
58

59 60 61
    }
  """
  portal_type_worklist_dict = {}
62
  portal_workflow = self.getPortalObject().portal_workflow
63

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  if not isinstance(workflow_list, list):
    workflow = [workflow_list]

  for workflow in workflow_list:

    portal_type_list = self.getPoralTypeListForWorkflow(self, 
        workflow=workflow)
    workflow = getattr(portal_workflow, workflow, None)

    if workflow is not None:
      worklist_dict = workflow.worklists._mapping
      for portal_type in portal_type_list:
        for worklist_id, worklist in worklist_dict.items():
          state = None
          if worklist.var_matches.has_key('validation_state'):
            state=worklist.var_matches['validation_state']
          local_role_list=worklist.guard.roles
          if state is None:
            continue
83 84
          else:
            state=state[0]
85 86 87 88 89 90 91 92 93 94 95

          result = self.getPortalObject().portal_catalog(\
                                          portal_type=portal_type,
                                          local_roles=local_role_list,
                                          validation_state=state)
          if not len(result):
            continue

          if not portal_type_worklist_dict.has_key(portal_type):
            portal_type_worklist_dict[portal_type] = {}

96 97
          portal_type_worklist_dict[portal_type][state] = {}
          result_dict = portal_type_worklist_dict[portal_type][state]
98 99 100 101 102 103 104
          result_dict['id']=worklist_id
          result_dict['count']=len(result)
          result_dict['description']=worklist.description
          result_dict['validation_state']=state
          result_dict['formated_name']=worklist.actbox_name
          result_dict['formated_url']=worklist.actbox_url
          result_dict['formated_url']='Base_viewSearchResultList?validation_state=%s&local_roles=%s&reset=1&portal_type=%s'\
105
            % (state, local_role_list[0], portal_type)
106 107
          result_dict['category']=worklist.actbox_category
          result_dict.update(worklist.guard.__dict__)
108 109
  return portal_type_worklist_dict