common/mixins.py
changeset 2778 3f6dfc312760
parent 2748 d2fcf19bfb34
child 2784 f395115070c1
equal deleted inserted replaced
2777:8f7fcbe11879 2778:3f6dfc312760
   166     __implements__ = (IWorkflowable,)
   166     __implements__ = (IWorkflowable,)
   167 
   167 
   168     @property
   168     @property
   169     def state(self):
   169     def state(self):
   170         try:
   170         try:
   171             return self.in_state[0].name
   171             return self.related('in_state', entities=True)[0].get_value('name')
   172         except IndexError:
   172         except IndexError:
   173             self.warning('entity %s has no state', self)
   173             self.warning('entity %s has no state', self)
   174             return None
   174             return None
   175 
   175 
   176     @property
   176     @property
   257     primary_email / use_email scheme
   257     primary_email / use_email scheme
   258     """
   258     """
   259     __implements__ = (IEmailable,)
   259     __implements__ = (IEmailable,)
   260 
   260 
   261     def get_email(self):
   261     def get_email(self):
   262         if getattr(self, 'primary_email', None):
   262         emails = self.related('primary_email', 'subject', entities=True) or \
   263             return self.primary_email[0].address
   263                  self.related('use_email', 'subject', entities=True)
   264         if getattr(self, 'use_email', None):
   264         if emails:
   265             return self.use_email[0].address
   265             return emails[0].get_value('address')
   266         return None
   266         return None
   267 
   267 
   268     @classmethod
   268     @classmethod
   269     def allowed_massmail_keys(cls):
   269     def allowed_massmail_keys(cls):
   270         """returns a set of allowed email substitution keys
   270         """returns a set of allowed email substitution keys
   281         build email bodies.
   281         build email bodies.
   282 
   282 
   283         NOTE: the dictionary keys should match the list returned by the
   283         NOTE: the dictionary keys should match the list returned by the
   284         `allowed_massmail_keys` method.
   284         `allowed_massmail_keys` method.
   285         """
   285         """
   286         return dict( (attr, getattr(self, attr)) for attr in self.allowed_massmail_keys() )
   286         return dict( (attr, self.cwgetattr(attr))
       
   287                      for attr in self.allowed_massmail_keys() )
   287 
   288 
   288 
   289 
   289 
   290 
   290 MI_REL_TRIGGERS = {
   291 MI_REL_TRIGGERS = {
   291     ('in_state',    'subject'): WorkflowableMixIn,
   292     ('in_state',    'subject'): WorkflowableMixIn,