Esempio n. 1
0
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
Esempio n. 2
0
 def site(self):
     """ Get the plone site. Bit hackish, to make it work with the
     simple test setup in transform.txt while still being properly
     wrapped """
     site = getSite()
     if not site:
         site = component.getUtility(IPloneSiteRoot)
         site = utils.fix_request(site, 0)
     return site
Esempio n. 3
0
    def _vars(self, subscription, items=()):
        """Provide variables for the template.

        Override this or '_more_vars' in your custom HTMLComposer to
        pass different variables to the templates.
        """
        vars = {}
        site = component.getUtility(Products.CMFPlone.interfaces.IPloneSiteRoot)
        site = utils.fix_request(site, 0)
        fix_urls = lambda t: transform.URL(site).__call__(t, subscription)

        vars['channel'] = subscription.channel
        vars['site_url'] = site.absolute_url()
        site_title = site.Title()
        if not isinstance(site_title, unicode):
            site_title = unicode(site_title, 'UTF-8')
        vars['site_title'] = site_title
        vars['channel_title'] = subscription.channel.title
        vars['subject'] = self.subject
        # Why would header_text or footer_text ever be None?
        vars['header_text'] = fix_urls(self.header_text or u"")
        vars['footer_text'] = fix_urls(self.footer_text or u"")
        vars['stylesheet'] = self.stylesheet
        vars['from_addr'] = self._from_address
        headers = vars['more_headers'] = {}
        if self.replyto_address:
            headers['Reply-To'] = self.replyto_address

        # This is so brittle, it hurts my eyes.  Someone convince me
        # that this needs to become another component:
        site_path = site.getPhysicalPath()
        for index, item in enumerate(items):
            formatted, original = item
            title = getattr(original, 'Title', lambda: formatted)()
            url = "/".join(original.getPhysicalPath()[len(site_path):])
            vars['item%s_url' % index] = url
            vars['item%s_title' % index] = title

        vars.update(self._more_vars(subscription, items))

        def subs(name):
            vars[name] = string.Template(vars[name]).safe_substitute(vars)
        for name in 'subject', 'header_text', 'footer_text':
            subs(name)

        # It'd be nice if we could use an adapter here to override
        # variables.  We'd probably want to pass 'items' along to that
        # adapter.

        return vars
Esempio n. 4
0
    def _vars(self, subscription, items=()):
        """Provide variables for the template.

        Override this or '_more_vars' in your custom HTMLComposer to
        pass different variables to the templates.
        """
        vars = {}
        site = component.getUtility(
            Products.CMFPlone.interfaces.IPloneSiteRoot)
        site = utils.fix_request(site, 0)
        fix_urls = lambda t: transform.URL(site).__call__(t, subscription)

        vars['channel'] = subscription.channel
        vars['site_url'] = site.absolute_url()
        site_title = site.Title()
        if not isinstance(site_title, unicode):
            site_title = unicode(site_title, 'UTF-8')
        vars['site_title'] = site_title
        vars['channel_title'] = subscription.channel.title
        vars['subject'] = self.subject
        # Why would header_text or footer_text ever be None?
        vars['header_text'] = fix_urls(self.header_text or u"")
        vars['footer_text'] = fix_urls(self.footer_text or u"")
        vars['stylesheet'] = self.stylesheet
        vars['from_addr'] = self._from_address
        headers = vars['more_headers'] = {}
        if self.replyto_address:
            headers['Reply-To'] = self.replyto_address

        # This is so brittle, it hurts my eyes.  Someone convince me
        # that this needs to become another component:
        for index, item in enumerate(items):
            formatted, original = item
            title = getattr(original, 'Title', lambda: formatted)()
            vars['item%s_title' % index] = title

        vars.update(self._more_vars(subscription, items))

        def subs(name):
            vars[name] = string.Template(vars[name]).safe_substitute(vars)

        for name in 'subject', 'header_text', 'footer_text':
            subs(name)

        # It'd be nice if we could use an adapter here to override
        # variables.  We'd probably want to pass 'items' along to that
        # adapter.

        return vars
Esempio n. 5
0
 def __call__(self):
     #site = get_site()
     site = getSite()
     name = get_name_for_site(site)
     lookup_utility = None
     try:
         lookup_utility = component.queryUtility(ILocalNewsletterLookup, name=name)
     except KeyError:
         logger.exception('Error looking up utility: %s ' % name)
     except AttributeError:
         logger.exception('Error looking up utility: %s ' % name)
     if lookup_utility:
         local_lookup_utility = lookup_utility.get('newsletter_lookup', None)
         if local_lookup_utility:
             for channel in local_lookup_utility.local_channels():
                 channel = fix_request(channel, 0)
                 yield channel
Esempio n. 6
0
 def __call__(self):
     site = getSite()
     name = get_name_for_site(site)
     lookup_utility = None
     try:
         lookup_utility = component.queryUtility(ILocalNewsletterLookup,
                                                 name=name)
     except KeyError:
         logger.exception('Error looking up utility: %s ' % name)
     except AttributeError:
         logger.exception('Error looking up utility: %s ' % name)
     if lookup_utility:
         local_lookup_utility = lookup_utility.get('newsletter_lookup',
                                                   None)
         if local_lookup_utility:
             for channel in local_lookup_utility.local_channels():
                 channel = fix_request(channel, 0)
                 yield channel
Esempio n. 7
0
 def _more_vars(self, subscription, items):
     """Less generic variables.
     """
     vars = {}
     channel = subscription.channel
     site = component.getUtility(
         Products.CMFPlone.interfaces.IPloneSiteRoot)
     site = utils.fix_request(site, 0)
     secret_var = '$%s' % template_var('secret')
     vars['confirm_url'] = (
         '%s/confirm-subscription.html?secret=%s' %
         (site.portal_newsletters.absolute_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
Esempio n. 8
0
 def _more_vars(self, subscription, items):
     """Less generic variables.
     """
     vars = {}
     channel = subscription.channel
     site = component.getUtility(Products.CMFPlone.interfaces.IPloneSiteRoot)
     site = utils.fix_request(site, 0)
     secret_var = '$%s' % template_var('secret')
     vars['confirm_url'] = (
         '%s/confirm-subscription.html?secret=%s' %
         (site.portal_newsletters.absolute_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
Esempio n. 9
0
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
Esempio n. 10
0
 def site_url(self):
     site = component.getUtility(IPloneSiteRoot)
     url = utils.fix_request(site, 0).absolute_url()
     if url.endswith('/'):
         return url[:-1]
     return url
Esempio n. 11
0
 def site_url(self):
     site = component.getUtility(IPloneSiteRoot)
     url = utils.fix_request(site, 0).absolute_url()
     if url.endswith('/'):
         return url[:-1]
     return url