def getDefaultDispatchMessage(self): _ = getToolByName(self, "translation_service").translate rstText = _( msgid="mail_text_dispatched", default=u"""Dear user, this is a personal communication regarding the Form Online **${formonline_title}**. The request has been *approved*. Follow the link below to see the document: ${formonline_url} Regards """, domain="auslfe.formonline.pfgadapter", context=self, ) return rstHTML(rstText, input_encoding="utf-8", output_encoding="utf-8")
def getDefaultApprovalMessage(self): _ = getToolByName(self, "translation_service").translate rstText = _( msgid="mail_text_dispatch_required", default=u"""Dear user, this is a personal communication regarding the Form Online **${formonline_title}**, created on **${insertion_date}** by **${formonline_owner}**. The request has been approved and it's waiting for your confirmation. Follow the link below for perform your actions: ${formonline_url} Regards """, domain="auslfe.formonline.pfgadapter", context=self, ) return rstHTML(rstText, input_encoding="utf-8", output_encoding="utf-8")
def sendNotificationMail(formonline, worfklow_action, addresses): """ Send a notification email to the list of addresses """ portal_url = getToolByName(formonline, 'portal_url') portal = portal_url.getPortalObject() portal_membership = getToolByName(portal, 'portal_membership') portal_workflow = getToolByName(portal, 'portal_workflow') portal_catalog = getToolByName(portal, 'portal_catalog') plone_utils = getToolByName(portal, 'plone_utils') charset = plone_utils.getSiteEncoding() def su(value): return safe_unicode(value, encoding=charset) formonlineCreator = formonline.Creator() formonlineCreatorInfo = portal_membership.getMemberInfo(formonlineCreator) formonlineAuthor = formonlineCreator if formonlineCreatorInfo: formonlineAuthor = formonlineCreatorInfo['fullname'] or formonlineCreator insertion_date = formonline.toLocalizedTime(formonline.created()) if PLONE3: _ = getGlobalTranslationService().translate else: _ = i18ntranslate ann = IAnnotations(formonline) # See auslfe.formonline.tokenaccess if ann.get('share-tokens') and worfklow_action == 'submit': path = '/'.join(formonline.getPhysicalPath()).replace('/%s/' % portal.getId(), '') formonline_url = '%s/@@consume-powertoken-first?path=%s&token=%s' % ( portal_url(), path, ann['share-tokens']['view'] ) logger.debug(formonline_url) else: formonline_url = su(formonline.absolute_url()) comment = portal_workflow.getInfoFor(formonline, 'comments') if not comment: try: comment = _(msgid='comment_retract', default=u'No comments', domain="auslfe.formonline.content", context=formonline) except TypeError: # On Plone 4 comment = _(msgid='comment_retract', default=u'No comments', domain="auslfe.formonline.content", context=formonline.REQUEST) lines = comment.splitlines() comment = "" for l in lines: comment+="\t%s\n" % l mapping = dict(formonline_title = su(formonline.title_or_id()), insertion_date = su(insertion_date), formonline_owner = su(formonlineAuthor), formonline_url = formonline_url, comment = comment, ) formOnlineAdapter_UID = ann.get('formOnlineAdapter','') formOnlineAdapter = formOnlineAdapter_UID and portal_catalog.unrestrictedSearchResults(UID=formOnlineAdapter_UID) or [] # get subject and text of email from the fields of FormOnlineAdapter if formOnlineAdapter: form_online_adapter = formOnlineAdapter[0]._unrestrictedGetObject() if worfklow_action == 'submit': subject = form_online_adapter.getFormOnlineSubmitSubject() text = form_online_adapter.getFormOnlineSubmitMessage() elif worfklow_action == 'approval': subject = form_online_adapter.getFormOnlineApprovalSubject() text = form_online_adapter.getFormOnlineApprovalMessage() elif worfklow_action == 'dispatch': subject = form_online_adapter.getFormOnlineDispatchSubject() text = form_online_adapter.getFormOnlineDispatchMessage() elif worfklow_action == 'retract_approval' or worfklow_action == 'retract_dispatch': subject = form_online_adapter.getFormOnlineRetractSubject() text = form_online_adapter.getFormOnlineRetractMessage() text = text.decode("utf-8") for variable in mapping: text = text.replace("${%s}" % variable, mapping[variable]) else: # Let's keep ol hardcoded messages, so FormOnline contents created before this version will still works if worfklow_action == 'submit': subject = _(msgid='subject_pending_approval', default=u'[Form Online] - Form Online in pending state approval', domain="auslfe.formonline.content", context=formonline) text = _(msgid='mail_text_approval_required', default=u"""Dear user, this is a personal communication regarding the Form Online **${formonline_title}**, created on **${insertion_date}** by **${formonline_owner}**. It is waiting for your approval. Follow the link below for perform your actions: ${formonline_url} Regards """, domain="auslfe.formonline.content", context=formonline, mapping=mapping) elif worfklow_action == 'approval': subject = _(msgid='subject_pending_dispatch', default=u'[Form Online] - Form Online in pending state dispatch', domain="auslfe.formonline.content", context=formonline) text = _(msgid='mail_text_dispatch_required', default=u"""Dear user, this is a personal communication regarding the Form Online **${formonline_title}**, created on **${insertion_date}** by **${formonline_owner}**. The request has been approved and it's waiting for your confirmation. Follow the link below for perform your actions: ${formonline_url} Regards """, domain="auslfe.formonline.content", context=formonline, mapping=mapping) elif worfklow_action == 'dispatch': subject = _(msgid='subject_dispatched', default=u'[Form Online] - Form Online approved', domain="auslfe.formonline.content", context=formonline) text = _(msgid='mail_text_dispatched', default=u"""Dear user, this is a personal communication regarding the Form Online **${formonline_title}**. The request has been *approved*. Follow the link below to see the document: ${formonline_url} Regards """, domain="auslfe.formonline.content", context=formonline, mapping=mapping) elif worfklow_action == 'retract_approval' or worfklow_action == 'retract_dispatch': subject = _(msgid='subject_rejected', default=u'[Form Online] - Form Online rejected', domain="auslfe.formonline.content", context=formonline) text = _(msgid='mail_text_rejected', default=u"""Dear user, this is a personal communication regarding the Form Online **${formonline_title}**. The request has been *rejected*. The overseer provided the following comment:: ${comment} Follow the link below to see the document: ${formonline_url} Regards """, domain="auslfe.formonline.content", context=formonline, mapping=mapping) # converte il testo in HTML perchè sendEmail si aspetta che arrivi un messaggio HTML, # come nel caso default in cui l'annotazione del formOnlineAdapter è presente sul Form text = rstHTML(text,input_encoding='utf-8',output_encoding='utf-8').decode("utf-8") sendEmail(formonline, addresses, subject, text)