def render_forgot_secret(self, subscription): """ Custom render_forgot method. If there is a registered template with id "forgot_newsletter_subscription" use it. If there isn't, use the default template. """ vars = self._vars(subscription) subscription_vars = self._subscription_vars(subscription) portal = getSite() if 'forgot_secret_subject' not in vars: vars['forgot_secret_subject'] = translate( _(u"Change your subscriptions with ${site_title}", mapping={'site_title': vars['channel_title']}), target_language=self.language) forgot_template = portal.restrictedTraverse('forgot_newsletter_subscription', self.forgot_template) html = forgot_template(**vars) html = utils.compactify(html) html = string.Template(html).safe_substitute(subscription_vars) message = create_html_mail( vars['forgot_secret_subject'], html, from_addr=vars['from_addr'], to_addr=subscription_vars[template_var('to_addr')], headers=vars.get('more_headers'), encoding=self.encoding) # status=None prevents message from ending up in any queue return Message( message, subscription, status=None)
def render_forgot_secret(self, subscription): vars = self._vars(subscription) subscription_vars = self._subscription_vars(subscription) if 'forgot_secret_subject' not in vars: # XXX Since this is not working #vars['forgot_secret_subject'] = zope.i18n.translate( # _(u"Change your subscriptions with ${site_title}", # mapping={'site_title': vars['site_title']}), # target_language=self.language) vars['forgot_secret_subject'] = self.portal_url.translate( _(u"Change your subscriptions with ${site_title}", mapping={'site_title': vars['site_title']})) html = self.forgot_template(**vars) html = utils.compactify(html) html = string.Template(html).safe_substitute(subscription_vars) message = collective.singing.mail.create_html_mail( vars['forgot_secret_subject'], html, from_addr=vars['from_addr'], to_addr=subscription_vars[template_var('to_addr')], headers=vars.get('more_headers'), encoding=self.encoding) # status=None prevents message from ending up in any queue return collective.singing.message.Message(message, subscription, status=None)
def render_confirmation(self, subscription): """ Custom render_confirmation method. If there is a registered template with id "confirm_newsletter_subscription" use it. If there isn't, use the default template. """ vars = self._vars(subscription) subscription_vars = self._subscription_vars(subscription) if 'confirmation_subject' not in vars: vars['confirmation_subject'] = translate( _(u"Confirm your subscription with ${channel-title}", mapping={'channel-title': subscription.channel.title}), target_language=self.language) to_addr = subscription_vars[template_var('to_addr')] vars['to_addr'] = to_addr portal = getSite() confirm_template = portal.restrictedTraverse('confirm_newsletter_subscription', self.confirm_template) html = confirm_template(**vars) html = utils.compactify(html) html = string.Template(html).safe_substitute(subscription_vars) message = create_html_mail( vars['confirmation_subject'], html, from_addr=vars['from_addr'], to_addr=to_addr, headers=vars.get('more_headers'), encoding=self.encoding) # status=None prevents message from ending up in any queue return Message( message, subscription, status=None)
def render_forgot_secret(self, subscription): vars = self._vars(subscription) subscription_vars = self._subscription_vars(subscription) if 'forgot_secret_subject' not in vars: # XXX Since this is not working #vars['forgot_secret_subject'] = zope.i18n.translate( # _(u"Change your subscriptions with ${site_title}", # mapping={'site_title': vars['site_title']}), # target_language=self.language) vars['forgot_secret_subject'] = self.portal_url.translate( _(u"Change your subscriptions with ${site_title}", mapping={'site_title': vars['site_title']})) html = self.forgot_template(**vars) html = utils.compactify(html) html = string.Template(html).safe_substitute(subscription_vars) message = collective.singing.mail.create_html_mail( vars['forgot_secret_subject'], html, from_addr=vars['from_addr'], to_addr=subscription_vars[template_var('to_addr')], headers=vars.get('more_headers'), encoding=self.encoding) # status=None prevents message from ending up in any queue return collective.singing.message.Message( message, subscription, status=None)
def render_confirmation(self, subscription): vars = self._vars(subscription) subscription_vars = self._subscription_vars(subscription) if 'confirmation_subject' not in vars: vars['confirmation_subject'] = zope.i18n.translate( _(u"Confirm your subscription with ${channel-title}", mapping={'channel-title': subscription.channel.title}), target_language=self.language) html = self.confirm_template(**vars) html = utils.compactify(html) html = string.Template(html).safe_substitute(subscription_vars) message = collective.singing.mail.create_html_mail( vars['confirmation_subject'], html, from_addr=vars['from_addr'], to_addr=subscription_vars[template_var('to_addr')], headers=vars.get('more_headers'), encoding=self.encoding) # status=None prevents message from ending up in any queue return collective.singing.message.Message( message, subscription, status=None)
def render_confirmation(self, subscription): vars = self._vars(subscription) subscription_vars = self._subscription_vars(subscription) if 'confirmation_subject' not in vars: vars['confirmation_subject'] = zope.i18n.translate( _(u"Confirm your subscription with ${channel-title}", mapping={'channel-title': subscription.channel.title}), target_language=self.language) html = self.confirm_template(**vars) html = utils.compactify(html) html = string.Template(html).safe_substitute(subscription_vars) message = collective.singing.mail.create_html_mail( vars['confirmation_subject'], html, from_addr=vars['from_addr'], to_addr=subscription_vars[template_var('to_addr')], headers=vars.get('more_headers'), encoding=self.encoding) # status=None prevents message from ending up in any queue return collective.singing.message.Message(message, subscription, status=None)
def _render(self, vars, items): if getattr(self, 'template', None) is not None: # This instance has overridden the template attribute. # We'll use that template. Note that this will be a bound template, # so we will need to "unbind" it by accessing im_func directly. template = self.template.im_func else: template = component.getUtility(IHTMLComposerTemplate, name=self.template_name) html = template( self, contents=[i[0] for i in items], items=[dict(formatted=i[0], original=i[1]) for i in items], **vars) return utils.compactify(html)