def _calc_menu_entry(self, customization, data, newIds):
        # condition
        talEngine = Expressions.getEngine()
        condition = customization['condition-tales']
        if condition:
            compiledCondition = talEngine.compile(condition)
            try:
                result = compiledCondition(talEngine.getContext(data))
            except KeyError:
                return
            if not result and customization['element-id']:
                newIds.append(customization['element-id'])
                return

        # URL
        url = talEngine.compile(customization['element-tales'])
        try:
            compiledURL = url(talEngine.getContext(data))
        except KeyError:
            logger.error("customize-factoriesmenu error: can't use the \"%s\" TALES expression" % condition)
            return
        # ICON
        icon = talEngine.compile(customization['icon-tales'])
        try:
            compiledIcon = icon(talEngine.getContext(data))
        except KeyError:
            compiledIcon = None
        
        if compiledURL:
            newElement = self._formatNewEntry(customization, compiledURL, compiledIcon)
            if newElement['extra']['id']:
                newIds.append(newElement['extra']['id'])
            return newElement
示例#2
0
文件: select.py 项目: Vinsurya/Plone
    def vocabulary(self):
        """Vocabulary can be a static list of values, or a vocabulary:TAL espression"""
        raw_vocabulary = self.configuration.get('vocabulary')
        values = raw_vocabulary.rstrip().decode('utf-8').splitlines()
        talEngine = Expressions.getEngine()
        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        evals = {
            'portal': portal_state.portal(),
            'context': self.context,
            'request': self.request,
        }

        results = []
        for value in values:
            if value and value.startswith('vocabulary:'):
                tales = value[11:]    
                try:
                    compiledExpr = talEngine.compile(tales)
                    result = compiledExpr(talEngine.getContext(evals))
                    results.extend(result)
                except CompilerError, e:
                    logger.error("Error compiling %s: %s" % (tales, e))
                    continue
                except Exception, e:
                    logger.error("Error evaluating %s: %s" % (tales, e))
                    continue
 def setUp(self):
     self.e = e = Expressions.getEngine()
     self.ec = e.getContext(
         one = 1,
         d = {'one': 1, 'b': 'b', '': 'blank', '_': 'under'},
         blank = '',
         )
示例#4
0
    def vocabulary(self):
        """Vocabulary can be a static list of values, or a vocabulary:TAL espression"""
        raw_vocabulary = self.configuration.get('vocabulary')
        values = raw_vocabulary.rstrip().decode('utf-8').splitlines()
        talEngine = Expressions.getEngine()
        portal_state = getMultiAdapter((self.context, self.request),
                                       name=u'plone_portal_state')
        evals = {
            'portal': portal_state.portal(),
            'context': self.context,
            'request': self.request,
        }

        results = []
        for value in values:
            if value and value.startswith('vocabulary:'):
                tales = value[11:]
                try:
                    compiledExpr = talEngine.compile(tales)
                    result = compiledExpr(talEngine.getContext(evals))
                    results.extend(result)
                except CompilerError, e:
                    logger.error("Error compiling %s: %s" % (tales, e))
                    continue
                except Exception, e:
                    logger.error("Error evaluating %s: %s" % (tales, e))
                    continue
    def getExtraRecipients(self, recompile=0):
        """Provides a TALES compiled extra list of recipients
        recompile=1 -> recompile TAL expression"""

        talEngine = Expressions.getEngine()
        try:
            dummy = self._v_extraRecipients
        except AttributeError, e:
            recompile = 1
    def getRenderTemplate(self, recompile=0):
        """Returns the template that renders the HTML newsletter
        recompile=1 -> recompile TAL expression"""

        talEngine = Expressions.getEngine()
        try:
            dummy = self._v_renderTemplate
        except AttributeError, e:
            recompile = 1
 def checkTalExpressions(self, talExpressions, state=None, errors=None):
     """
     Check TALES expressions for edit_form validation
     """
     talEngine = Expressions.getEngine()
     for fieldId, value in talExpressions:
         if not value:
             continue
         try:
             dummy = talEngine.compile(value)
         except CompilerError, e:
             msg = _('TALES compilation error: ${error}', mapping={'error':str(e)})
             if state is not None:
                 state.setError(fieldId, msg)
             if errors is not None:
                 errors[fieldId] = msg
示例#8
0
文件: column.py 项目: Vinsurya/Plone
 def render_view(self, foo, index, storage=None):
     """Whatever dummy value we receive, the result will be a TAL expression evaluation"""
     self.data = None
     expression = self.configuration.get('vocabulary')
     if expression:
         expression = expression.splitlines()[0]
         talEngine = Expressions.getEngine()
         compiledExpr = talEngine.compile(expression)
         try:
             self.data = compiledExpr(talEngine.getContext(self.eval_mappings(index=index, storage=storage)))
         except CompilerError:
             logger.debug("Can't evaluate %s" % expression)
             self.data = None
         except Exception:
             logger.debug("Error evaluating %s or row %d" % (expression, index))
             self.data = None
     return self.view_template(data=self.data)
示例#9
0
文件: column.py 项目: Vinsurya/Plone
 def data_for_display(self, foo, backend=False, row_index=None):
     """Data is always ignored""" 
     if backend:
         raise NotImplementedError("ComputedColumn will not output anything for backend mode")
     expression = self.configuration.get('vocabulary')
     if expression:
         expression = expression.splitlines()[0]
         talEngine = Expressions.getEngine()
         compiledExpr = talEngine.compile(expression)
         try:
             data = compiledExpr(talEngine.getContext(self.eval_mappings(index=row_index)))
         except CompilerError:
             logger.debug("Can't evaluate %s" % expression)
             data = None
         except Exception:
             logger.debug("Error evaluating %s or row %d" % (expression, row_index))
             data = None
     return data
示例#10
0
 def render_view(self, foo, index, storage=None):
     """Whatever dummy value we receive, the result will be a TAL expression evaluation"""
     self.data = None
     expression = self.configuration.get('vocabulary')
     if expression:
         expression = expression.splitlines()[0]
         talEngine = Expressions.getEngine()
         compiledExpr = talEngine.compile(expression)
         try:
             self.data = compiledExpr(
                 talEngine.getContext(
                     self.eval_mappings(index=index, storage=storage)))
         except CompilerError:
             logger.debug("Can't evaluate %s" % expression)
             self.data = None
         except Exception:
             logger.debug("Error evaluating %s or row %d" %
                          (expression, index))
             self.data = None
     return self.view_template(data=self.data)
示例#11
0
 def data_for_display(self, foo, backend=False, row_index=None):
     """Data is always ignored"""
     if backend:
         raise NotImplementedError(
             "ComputedColumn will not output anything for backend mode")
     expression = self.configuration.get('vocabulary')
     if expression:
         expression = expression.splitlines()[0]
         talEngine = Expressions.getEngine()
         compiledExpr = talEngine.compile(expression)
         try:
             data = compiledExpr(
                 talEngine.getContext(self.eval_mappings(index=row_index)))
         except CompilerError:
             logger.debug("Can't evaluate %s" % expression)
             data = None
         except Exception:
             logger.debug("Error evaluating %s or row %d" %
                          (expression, row_index))
             data = None
     return data
示例#12
0
    def _calc_menu_entry(self, customization, data, newIds):
        # condition
        talEngine = Expressions.getEngine()
        condition = customization['condition-tales']
        if condition:
            compiledCondition = talEngine.compile(condition)
            try:
                result = compiledCondition(talEngine.getContext(data))
            except KeyError:
                return
            if not result and customization['element-id']:
                newIds.append(customization['element-id'])
                return

        # URL
        url = talEngine.compile(customization['element-tales'])
        try:
            compiledURL = url(talEngine.getContext(data))
        except KeyError:
            logger.error(
                'customize-factoriesmenu error: can\'t use the "%s" '
                'TALES expression' % condition
            )
            return
        # ICON
        icon = talEngine.compile(customization['icon-tales'])
        try:
            compiledIcon = icon(talEngine.getContext(data))
        except KeyError:
            compiledIcon = None

        if compiledURL:
            newElement = self._formatNewEntry(
                customization, compiledURL, compiledIcon)
            if newElement['extra']['id']:
                newIds.append(newElement['extra']['id'])
            return newElement