def getMailTemplate(self, obj, what, ec_bindings=None): """Return the template to notify for the ``what`` of an object ``obj``, ``what`` being one of the implemented notification ("*item_modification*", "*wf_transition*", etc.), or ``None`` if none could be found. ``ec_bindings`` is a mapping which is injected into the expression context of the expression of the rules. """ rules = self.getProperty('on_%s_mail_template' % what, None) if rules is None: raise NotImplementedError, \ 'Notification on "%s" is not implemented.' ec = getExpressionContext(obj, ec_bindings) template = None for rule in rules: try: match_expr, template_expr = rule.split(RULE_DELIMITER) match_expr, template_expr = match_expr.strip( ), template_expr.strip() except ValueError: LOG.error("'%s' is not a valid rule "\ "('on_%s_mail_template' on '%s')", rule, what, obj.absolute_url(1)) continue match_expr = match_expr.strip() template_expr = template_expr.strip() try: if not self._match(match_expr, ec): continue except ConflictError: raise except: LOG.error("Error in 'on_%s_mail_template' rule "\ "('%s') for '%s'", what, match_expr, obj.absolute_url(1), exc_info=True) continue try: template = Expression(template_expr)(ec) except ConflictError: raise except: LOG.error("Error in 'on_%s_mail_template' rule "\ "('%s') for '%s'", what, template_expr, obj.absolute_url(1), exc_info=True) continue if type(template) == StringType: template = obj.restrictedTraverse(template, None) if template is not None: break return template
def getTemplate(self, obj, what, ec_bindings=None): """Return the template to notify for the ``what`` of an object ``obj``, ``what`` being one of the implemented notification ("*item_modification*", "*wf_transition*", etc.), or ``None`` if none could be found. ``ec_bindings`` is a mapping which is injected into the expression context of the expression of the rules. """ rules = self.getProperty('on_%s_mail_template' % what, None) if rules is None: raise NotImplementedError, \ 'Notification on "%s" is not implemented.' ec = getExpressionContext(obj, ec_bindings) template = None for rule in rules: try: match_expr, template_expr = rule.split(RULE_DELIMITER) match_expr, template_expr = match_expr.strip(), template_expr.strip() except ValueError: LOG.error("'%s' is not a valid rule "\ "('on_%s_mail_template' on '%s')", rule, what, obj.absolute_url(1)) continue match_expr = match_expr.strip() template_expr = template_expr.strip() try: if not self._match(match_expr, ec): continue except ConflictError: raise except: LOG.error("Error in 'on_%s_mail_template' rule "\ "('%s') for '%s'", what, match_expr, obj.absolute_url(1), exc_info=True) continue try: template = Expression(template_expr)(ec) except ConflictError: raise except: LOG.error("Error in 'on_%s_mail_template' rule "\ "('%s') for '%s'", what, template_expr, obj.absolute_url(1), exc_info=True) continue if type(template) == StringType: template = obj.restrictedTraverse(template, None) if template is not None: break return template
def ignoreNotification(self, obj): """Return whether notification have been set to be ignored for ``obj``. """ ec = getExpressionContext(obj) for match_expr in self.getProperty('ignore_rules', ()): try: if self._match(match_expr, ec): return True except ConflictError: raise except: LOG.error("Error in 'ignore_rules' rule "\ "('%s') for '%s'", match_expr, obj.absolute_url(1), exc_info=True) return False
def getUsersToNotify(self, obj, what, ec_bindings=None): """Return a mapping from label to a list of user/how tuples, based on the passed ``what`` and ``ob``. ``what`` is one of the implemented notifications (*item_modification*, *wf_transition*, etc.). ``how`` is a string that says which delivery method to use. ``ec_bindings`` is a mapping which is injected into the expression context of the expression of the rules. """ rules = self.getProperty('on_%s_users' % what, None) if rules is None: raise NotImplementedError, \ "Notification on '%s' is not implemented." % what ec = getExpressionContext(obj, ec_bindings) users_by_label = {} ignore_next_rules = False for rule in rules: try: match_expr, users_expr = rule.split(RULE_DELIMITER, 1) parts = users_expr.split(RULE_DELIMITER) label = '' how = ('mail',) if len(parts) > 1: users_expr, label = parts[:2] if len(parts) > 2: how = tuple([p.strip() for p in parts[2:]]) except ValueError: LOG.error("'%s' is not a valid rule "\ "('on_%s_users' on '%s')", rule, what, obj.absolute_url(1)) continue match_expr = match_expr.strip() users_expr = users_expr.strip() label = label.strip() users = users_by_label.get(label, []) try: if not self._match(match_expr, ec): continue except ConflictError: raise except: LOG.error("Error in 'on_%s_users' rule "\ "('%s') for '%s'", what, match_expr, obj.absolute_url(1), exc_info=True) continue if users_expr == '*': users.extend([(u, how) for u in self.getAllUsers()]) ignore_next_rules = True else: try: users.extend([(u, how) for u in Expression(users_expr)(ec)]) except ConflictError: raise except: LOG.error("Error in 'on_%s_users' rule "\ "('%s') for '%s'", what, users_expr, obj.absolute_url(1), exc_info=True) users_by_label[label] = users if ignore_next_rules: break return users_by_label
def getUsersToNotify(self, obj, what, ec_bindings=None): """Return a mapping of list of users to notify by label for the ``what`` of ``obj``, ``what`` being one of the implemented notification (*item_modification*, *wf_transition*, etc.). ``ec_bindings`` is a mapping which is injected into the expression context of the expression of the rules. """ rules = self.getProperty('on_%s_users' % what, None) if rules is None: raise NotImplementedError, \ "Notification on '%s' is not implemented." % what ec = getExpressionContext(obj, ec_bindings) users_by_label = {} ignore_next_rules = False for rule in rules: try: match_expr, users_expr = rule.split(RULE_DELIMITER, 1) if RULE_DELIMITER in users_expr: users_expr, label = users_expr.split(RULE_DELIMITER) else: label = '' except ValueError: LOG.error("'%s' is not a valid rule "\ "('on_%s_users' on '%s')", rule, what, obj.absolute_url(1)) continue match_expr = match_expr.strip() users_expr = users_expr.strip() label = label.strip() users = users_by_label.get(label, []) try: if not self._match(match_expr, ec): continue except ConflictError: raise except: LOG.error("Error in 'on_%s_users' rule "\ "('%s') for '%s'", what, match_expr, obj.absolute_url(1), exc_info=True) continue if users_expr == '*': users.extend(self.getAllUsers()) ignore_next_rules = True else: try: users.extend(Expression(users_expr)(ec)) except ConflictError: raise except: LOG.error("Error in 'on_%s_users' rule "\ "('%s') for '%s'", what, users_expr, obj.absolute_url(1), exc_info=True) users_by_label[label] = users if ignore_next_rules: break return users_by_label
def getUsersToNotify(self, obj, what, ec_bindings=None): """Return a mapping from label to a list of user/how tuples, based on the passed ``what`` and ``ob``. ``what`` is one of the implemented notifications (*item_modification*, *wf_transition*, etc.). ``how`` is a string that says which delivery method to use. ``ec_bindings`` is a mapping which is injected into the expression context of the expression of the rules. """ rules = self.getProperty('on_%s_users' % what, None) if rules is None: raise NotImplementedError, \ "Notification on '%s' is not implemented." % what ec = getExpressionContext(obj, ec_bindings) users_by_label = {} ignore_next_rules = False for rule in rules: try: match_expr, users_expr = rule.split(RULE_DELIMITER, 1) parts = users_expr.split(RULE_DELIMITER) label = '' how = ('mail', ) if len(parts) > 1: users_expr, label = parts[:2] if len(parts) > 2: how = tuple([p.strip() for p in parts[2:]]) except ValueError: LOG.error("'%s' is not a valid rule "\ "('on_%s_users' on '%s')", rule, what, obj.absolute_url(1)) continue match_expr = match_expr.strip() users_expr = users_expr.strip() label = label.strip() users = users_by_label.get(label, []) try: if not self._match(match_expr, ec): continue except ConflictError: raise except: LOG.error("Error in 'on_%s_users' rule "\ "('%s') for '%s'", what, match_expr, obj.absolute_url(1), exc_info=True) continue if users_expr == '*': users.extend([(u, how) for u in self.getAllUsers()]) ignore_next_rules = True else: try: users.extend([(u, how) for u in Expression(users_expr)(ec)]) except ConflictError: raise except: LOG.error("Error in 'on_%s_users' rule "\ "('%s') for '%s'", what, users_expr, obj.absolute_url(1), exc_info=True) users_by_label[label] = users if ignore_next_rules: break return users_by_label