sobjects/supervising.py
changeset 9753 64d02d18c3c3
parent 9469 032825bbacab
child 10593 03ce3d24db87
equal deleted inserted replaced
9752:5df3ac51a91a 9753:64d02d18c3c3
   140         self.w(_('  from state %(fromstate)s to state %(tostate)s\n' %
   140         self.w(_('  from state %(fromstate)s to state %(tostate)s\n' %
   141                  {'fromstate': _(fromstate.name), 'tostate': _(tostate.name)}))
   141                  {'fromstate': _(fromstate.name), 'tostate': _(tostate.name)}))
   142         self.w(u'  %s' % entity.absolute_url())
   142         self.w(u'  %s' % entity.absolute_url())
   143 
   143 
   144     def _relation_context(self, changedescr):
   144     def _relation_context(self, changedescr):
   145         session = self._cw
   145         cnx = self._cw
   146         def describe(eid):
   146         def describe(eid):
   147             try:
   147             try:
   148                 return session._(session.entity_metas(eid)['type']).lower()
   148                 return cnx._(cnx.entity_metas(eid)['type']).lower()
   149             except UnknownEid:
   149             except UnknownEid:
   150                 # may occurs when an entity has been deleted from an external
   150                 # may occurs when an entity has been deleted from an external
   151                 # source and we're cleaning its relation
   151                 # source and we're cleaning its relation
   152                 return session._('unknown external entity')
   152                 return cnx._('unknown external entity')
   153         eidfrom, rtype, eidto = changedescr.eidfrom, changedescr.rtype, changedescr.eidto
   153         eidfrom, rtype, eidto = changedescr.eidfrom, changedescr.rtype, changedescr.eidto
   154         return {'rtype': session._(rtype),
   154         return {'rtype': cnx._(rtype),
   155                 'eidfrom': eidfrom,
   155                 'eidfrom': eidfrom,
   156                 'frometype': describe(eidfrom),
   156                 'frometype': describe(eidfrom),
   157                 'eidto': eidto,
   157                 'eidto': eidto,
   158                 'toetype': describe(eidto)}
   158                 'toetype': describe(eidto)}
   159 
   159 
   169 class SupervisionMailOp(SendMailOp):
   169 class SupervisionMailOp(SendMailOp):
   170     """special send email operation which should be done only once for a bunch
   170     """special send email operation which should be done only once for a bunch
   171     of changes
   171     of changes
   172     """
   172     """
   173     def _get_view(self):
   173     def _get_view(self):
   174         return self.session.vreg['components'].select('supervision_notif',
   174         return self.cnx.vreg['components'].select('supervision_notif', self.cnx)
   175                                                       self.session)
       
   176 
   175 
   177     def _prepare_email(self):
   176     def _prepare_email(self):
   178         session = self.session
   177         cnx = self.cnx
   179         config = session.vreg.config
   178         config = cnx.vreg.config
   180         uinfo = {'email': config['sender-addr'],
   179         uinfo = {'email': config['sender-addr'],
   181                  'name': config['sender-name']}
   180                  'name': config['sender-name']}
   182         view = self._get_view()
   181         view = self._get_view()
   183         content = view.render(changes=session.transaction_data.get('pendingchanges'))
   182         content = view.render(changes=cnx.transaction_data.get('pendingchanges'))
   184         recipients = view.recipients()
   183         recipients = view.recipients()
   185         msg = format_mail(uinfo, recipients, content, view.subject(), config=config)
   184         msg = format_mail(uinfo, recipients, content, view.subject(), config=config)
   186         self.to_send = [(msg, recipients)]
   185         self.to_send = [(msg, recipients)]
   187 
   186 
   188     def postcommit_event(self):
   187     def postcommit_event(self):