def composer_more_vars(self, subscription, items): """Less generic variables. """ vars = {} channel = subscription.channel site = component.getUtility(IPloneSiteRoot) site = utils.fix_request(site, 0) secret_var = '$%s' % template_var('secret') subscription_channel_url='' for item in channel.aq_chain: if IDanceFloorParty.providedBy(item): subscription_channel_url=channel.absolute_url() if not subscription_channel_url: subscription_channel_url=channel.portal_newsletters.absolute_url() vars['confirm_url'] = ( '%s/confirm-subscription.html?secret=%s' % (subscription_channel_url, secret_var)) vars['unsubscribe_url'] = ( '%s/unsubscribe.html?secret=%s' % (channel.absolute_url(), secret_var)) vars['my_subscriptions_url'] = ( '%s/../../my-subscriptions.html?secret=%s' % (channel.absolute_url(), secret_var)) vars['to_addr'] = '$%s' % template_var('to_addr') return vars
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_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 composer_more_vars(self, subscription, items): """Less generic variables. """ vars = {} channel = subscription.channel site = component.getUtility(IPloneSiteRoot) site = utils.fix_request(site, 0) secret_var = '$%s' % template_var('secret') subscription_channel_url = '' for item in channel.aq_chain: if IDanceFloorParty.providedBy(item): subscription_channel_url = channel.absolute_url() if not subscription_channel_url: subscription_channel_url = channel.portal_newsletters.absolute_url() vars['confirm_url'] = ('%s/confirm-subscription.html?secret=%s' % (subscription_channel_url, secret_var)) vars['unsubscribe_url'] = ('%s/unsubscribe.html?secret=%s' % (channel.absolute_url(), secret_var)) vars['my_subscriptions_url'] = ( '%s/../../my-subscriptions.html?secret=%s' % (channel.absolute_url(), secret_var)) vars['to_addr'] = '$%s' % template_var('to_addr') return vars