# -*- coding: utf-8 -*- # # File: TeleServices.py # # Copyright (c) 2007 by CommunesPlone # Generator: ArchGenXML Version 1.5.3 dev/svn # http://plone.org/products/archgenxml # # GNU General Public License (GPL) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # __author__ = """Gauthier BASTIEN , Stephan GEULETTE """ __docformat__ = 'plaintext' # Workflow Scripts for: workteleservices_workflow ##code-section workflow-script-header #fill in your manual code here from Products.CMFCore.utils import getToolByName from Products.CMFPlone.i18nl10n import utranslate from DateTime import DateTime ##/code-section workflow-script-header def afterClose(self, state_change, **kw): object = state_change['object'] if object.getFollowDemand(): #the user choosed to get some return on his demand, we send an email subject_param = "Suivi de votre '%s' : %s." % (utranslate(domain="plone", msgid=object.getPortalTypeName(), context=self, default=object.getPortalTypeName()).encode('utf-8'), unicode(object.Title(), 'utf-8')) template_param = "teleservices_sendto_template" wft = getToolByName(self, 'portal_workflow') state = wft.getInfoFor(object, 'review_state') send_to_address_param = object.getEmailAddress() comment_param = {'state' : utranslate(domain="plone", msgid=state, context=self, default=state)} send_to_address_param = object.getEmailAddress() object.sendAnEmail(object, template_param, subject_param, comment_param, send_to_address_param) def afterReject(self, state_change, **kw): object = state_change['object'] if object.getFollowDemand(): #the user choosed to get some return on his demand, we send an email subject_param = "Suivi de votre '%s' : %s." % (utranslate(domain="plone", msgid=object.getPortalTypeName(), context=self, default=object.getPortalTypeName()).encode('utf-8'), unicode(object.Title(), 'utf-8')) template_param = "teleservices_sendto_template" wft = getToolByName(self, 'portal_workflow') state = wft.getInfoFor(object, 'review_state') comment_param = {'state' : utranslate(domain="plone", msgid=state, context=self, default=state)} send_to_address_param = object.getEmailAddress() object.sendAnEmail(object, template_param, subject_param, comment_param, send_to_address_param) def afterCancel(self, state_change, **kw): pass def afterTreat(self, state_change, **kw): object = state_change['object'] if object.getFollowDemand(): #the user choosed to get some return on his demand, we send an email subject_param = "Suivi de votre '%s' : %s." % (utranslate(domain="plone", msgid=object.getPortalTypeName(), context=self, default=object.getPortalTypeName()).encode('utf-8'), unicode(object.Title(), 'utf-8')) template_param = "teleservices_sendto_template" wft = getToolByName(self, 'portal_workflow') state = wft.getInfoFor(object, 'review_state') comment_param = {'state' : utranslate(domain="plone", msgid=state, context=self, default=state)} send_to_address_param = object.getEmailAddress() object.sendAnEmail(object, template_param, subject_param, comment_param, send_to_address_param) def afterTransmit(self, state_change, **kw): object = state_change['object'] object.setTransmissionDate(DateTime()) if object.getFollowDemand(): #the user choosed to get some return on his demand, we send an email subject_param = "Suivi de votre '%s' : %s." % (utranslate(domain="plone", msgid=object.getPortalTypeName(), context=self, default=object.getPortalTypeName()).encode('utf-8'), unicode(object.Title(), 'utf-8')) template_param = "teleservices_sendto_template" wft = getToolByName(self, 'portal_workflow') state = wft.getInfoFor(object, 'review_state') comment_param = {'state' : utranslate(domain="plone", msgid=state, context=self, default=state)} send_to_address_param = object.getEmailAddress() object.sendAnEmail(object, template_param, subject_param, comment_param, send_to_address_param) #we check if we have to send an e-mail to the service to warn them that a new request is waiting #the name of the field in portal_teleservices is the portal_type + Emails but with first letter in lowercase field_name = object.getPortalTypeName() + "Emails" first_letter = field_name[0].lower() field_name = first_letter + field_name[1:] tstool = getToolByName(self, 'portal_teleservices') accessor = tstool.getField(field_name).getAccessor(tstool) if accessor(): translated_portal_type = utranslate(domain="plone", msgid=object.getPortalTypeName(), context=self, default=object.getPortalTypeName()).encode('utf-8') + " - " + object.Title() template_param = "teleservices_simple_sendto_template" subject_param = "Nouvelle '%s'." % translated_portal_type comment_param = "vous avez une nouvelle '%s' à gérer" % translated_portal_type #we transform our string of emails into a python list send_to_address_param = list(accessor().split(';')) #we send an email to the list of emails if this list is not empty self.sendAnEmail(object, template_param, subject_param, comment_param, send_to_address_param)