Пример #1
0
def performTemplating(signup_sheet, person, email_type):

    #Get our email specifications from our configuration
    emailSpecs = config.EHS_EMAIL_TYPES[email_type]

    #Get the right type of email field's contents here
    email_body = getattr(signup_sheet, emailSpecs['bodyField']).decode('utf-8')

    templateContext = getTemplateContext(person)

    #Load our body text into the templating engine
    template, syntax_errors = config.EHS_TEMPLATING_ENGINE.loadString(
        email_body, False)

    if syntax_errors:
        raise EmailTemplatingException(syntax_errors,
                                       config.SYNTAX_ERROR)

    #Evaluate our template based upon our selected context (person)
    result, evaluation_errors = template.evaluate(templateContext)

    if evaluation_errors:
        raise EmailTemplatingException(evaluation_errors,
                                       config.EVALUATION_ERROR)

    return result
Пример #2
0
    def render_slide(self, slide):
        if easytemplate_installed and \
                self.settings.easytemplate_enabled:

            context = getTemplateContext(self.context, expose_schema=False)
            text, errors = applyTemplate(context, slide, logger)

            if not errors:
                slide = text

        return self.transform(slide)
Пример #3
0
    def _cookTemplate(self):
        """ Cook the view mode output. """

        context = getTemplateContext(self.context)

        text = self.getTemplateSource()
        t, messages = self.compile(text)

        self.outputTemplateErrors(messages)
        if not t:
            return ERROR_MESSAGE

        output, messages = t.evaluate(context)
        self.outputTemplateErrors(messages)
        if not output:
            return ERROR_MESSAGE

        return unicode(output).encode("utf-8")
    def testTemplate(self):
        """ Return template output without HTML transformations.
        Useful for template debugging.
        """

        context = getTemplateContext(self)        
        text = self.getTemplateSource()        
        t, messages = self.compile(text)            
        if len(messages) > 0:
            return str(messages)

        response = self.REQUEST.RESPONSE
        response.setHeader('Content-type', "text/plain")

        output, messages = t.evaluate(context)
        if len(messages) > 0:
            response.write(str(messages))
        else:
            response.write(str(output))
Пример #5
0
    def _getCooked(self, instance, text):
        """ Cook the view mode output. """

        # Convert all template code to unicode first
        if type(text) == str:
            text = text.decode("utf-8")

        # expose_schema must be False, or we get recursive
        # loop here (expose schema tries to expose this field)
        context = getTemplateContext(instance, expose_schema=False)

        t, messages = self.compile(text)

        self.outputTemplateErrors(instance, messages)
        if t is None:
            return ERROR_MESSAGE

        output, messages = t.evaluate(context)
        self.outputTemplateErrors(instance, messages)
        if output is None:
            return ERROR_MESSAGE

        return unicode(output).encode("utf-8")
    def getTemplatedText(self):
        """ Cook the view mode output. """

        context = getTemplateContext(self)        
        text = self.getTemplateSource()
        t, messages = self.compile(text)
        self.outputTemplateErrors(messages)
        if not t:            
            return ERROR_MESSAGE

        output, messages = t.evaluate(context)
        self.outputTemplateErrors(messages)
        if not output:
            return ERROR_MESSAGE            
        # TODO: Didn't find instructions how this should be really done
        # I am not going to spent another night going through
        # piles of old undocumented codebase to figure this out.
        # I so hate Plone.

        # XXX 2011-06: latest hot fixes to portal_transforms screw this
        #transforms = getToolByName(self, 'portal_transforms')                
        #output = transforms.convertTo("text/html", output, context=self)
        return unicode(output).encode("utf-8")
Пример #7
0
def cook(instance, request, text):
    """ Shortcut method to render a template.
    
    
    @param text: Templat text as unicode string
    """
    
    # expose_schema must be False, or we get recursive
    # loop here (expose schema tries to expose this field)
    context = getTemplateContext(instance, expose_schema=False)        
        
    t, messages = compile(text)        
        
    outputTemplateErrors(messages, instance)
    if t is None:            
        return ERROR_MESSAGE
        
    output, messages = t.evaluate(context)
    outputTemplateErrors(messages, request=request, context=instance)
    if output is None:
        return ERROR_MESSAGE            
    
    return unicode(output).encode("utf-8")    
 def _getCooked(self, instance, text):
     """ Cook the view mode output. """
     
     
     # Convert all template code to unicode first
     if type(text) == str:
         text = text.decode("utf-8")
     
     # expose_schema must be False, or we get recursive
     # loop here (expose schema tries to expose this field)
     context = getTemplateContext(instance, expose_schema=False)        
         
     t, messages = self.compile(text)        
     
     self.outputTemplateErrors(instance, messages)
     if t is None:            
         return ERROR_MESSAGE
         
     output, messages = t.evaluate(context)
     self.outputTemplateErrors(instance, messages)
     if output is None:
         return ERROR_MESSAGE            
     
     return unicode(output).encode("utf-8")
 def getTemplateContext(self):
     
     # Portlet might be assigned to non
     return getTemplateContext(self.context, expose_schema=False)
Пример #10
0
    def __call__(self):
                        
        context = obj = self.event.object
        templateContext = getTemplateContext(context)
        
        # Flag if we have errors from any template formatter
        any_errors = False
            
        recipients, errors = applyTemplate(templateContext, self.element.recipients, logger=logger)
        any_errors |= errors
        if recipients == None:
            raise ValueError("Bad recipients value:" + str(self.element.recipients.encode("utf-8")))
            
        emails = recipients.strip().split(",")
        emails = [ email for email in emails if (email != None and email != '')]                
        recipients = [str(email.strip()) for email in emails]
        
        mailhost = getToolByName(aq_inner(self.context), "MailHost")
        if not mailhost:
            raise ComponentLookupError('You must have a Mailhost utility to execute this action')
        
        source = self.element.source
        source, errors = applyTemplate(templateContext, source, logger=logger)
        any_errors |= errors        
        
        urltool = getToolByName(aq_inner(self.context), "portal_url")
        portal = urltool.getPortalObject()
        email_charset = portal.getProperty('email_charset')
        
        if not source or len(source) == 0:
            # no source provided, looking for the site wide from email
            # address
            from_address = portal.getProperty('email_from_address')
            if not from_address:
                raise ValueError, 'You must provide a source address for this \
action or enter an email in the portal properties'
            from_name = portal.getProperty('email_from_name')
            source = "%s <%s>" % (from_name, from_address)

        message, errors = applyTemplate(templateContext, self.element.message, logger=logger)
        any_errors |= errors
        
        #subject_source = self.sanify_encoding(self.element.subject)
        subject_source = self.element.subject

        subject, errors = applyTemplate(templateContext, subject_source, logger=logger)
        any_errors |= errors
        

        
        # TODO: Should these to be added to status messaegs
        if len(recipients) == 0:
            raise ValueError("Recipients could not be defined from template:" + self.element.recipients.encode("utf-8"))

        if subject == None or len(subject) == 0:            
            raise ValueError("Subject could not be defined from template:" + self.element.subject.encode("utf-8"))

        if source == None or len(source) == 0:
            raise ValueError("Source could not be defined from template:" + self.element.source.encode("utf-8"))

        if any_errors:
            # These has been outputted already above
            return
        
        for email_recipient in recipients:
            
            assert len(email_recipient.strip()) > 0, "Email recipient is empty, all recipients:" + str(recipients)

            mailhost.secureSend(message, email_recipient, source,
                                subject=subject, subtype='plain',
                                charset=email_charset, debug=False)

        return True
    def getTemplateContext(self):

        # Portlet might be assigned to non
        return getTemplateContext(self.context, expose_schema=False)