sobjects/notification.py
changeset 9402 2c48c091b6a2
parent 9387 f31f0c8bda4f
child 9481 7e35d62c67a9
child 9699 990676d3f39f
equal deleted inserted replaced
9127:aff75b69db92 9402:2c48c091b6a2
   126                 emailaddr, lang = something
   126                 emailaddr, lang = something
   127                 self._cw.set_language(lang)
   127                 self._cw.set_language(lang)
   128             # since the same view (eg self) may be called multiple time and we
   128             # since the same view (eg self) may be called multiple time and we
   129             # need a fresh stream at each iteration, reset it explicitly
   129             # need a fresh stream at each iteration, reset it explicitly
   130             self.w = None
   130             self.w = None
   131             # XXX call render before subject to set .row/.col attributes on the
       
   132             #     view
       
   133             try:
   131             try:
   134                 content = self.render(row=0, col=0, **kwargs)
   132                 # XXX call render before subject to set .row/.col attributes on the
   135                 subject = self.subject()
   133                 #     view
   136             except SkipEmail:
   134                 try:
   137                 continue
   135                     content = self.render(row=0, col=0, **kwargs)
   138             except Exception as ex:
   136                     subject = self.subject()
   139                 # shouldn't make the whole transaction fail because of rendering
   137                 except SkipEmail:
   140                 # error (unauthorized or such) XXX check it doesn't actually
   138                     continue
   141                 # occurs due to rollback on such error
   139                 except Exception as ex:
   142                 self.exception(str(ex))
   140                     # shouldn't make the whole transaction fail because of rendering
   143                 continue
   141                     # error (unauthorized or such) XXX check it doesn't actually
   144             msg = format_mail(self.user_data, [emailaddr], content, subject,
   142                     # occurs due to rollback on such error
   145                               config=self._cw.vreg.config, msgid=msgid, references=refs)
   143                     self.exception(str(ex))
   146             yield [emailaddr], msg
   144                     continue
   147             if isinstance(something, Entity):
   145                 msg = format_mail(self.user_data, [emailaddr], content, subject,
   148                 self._cw.commit()
   146                                   config=self._cw.vreg.config, msgid=msgid, references=refs)
   149                 self._cw.close()
   147                 yield [emailaddr], msg
   150                 self._cw = req
   148             except:
       
   149                 if isinstance(something, Entity):
       
   150                     self._cw.rollback()
       
   151                 raise
       
   152             else:
       
   153                 if isinstance(something, Entity):
       
   154                     self._cw.commit()
       
   155             finally:
       
   156                 if isinstance(something, Entity):
       
   157                     self._cw.close()
       
   158                     self._cw = req
   151         # restore language
   159         # restore language
   152         req.set_language(origlang)
   160         req.set_language(origlang)
   153 
   161 
   154     # recipients / email sending ###############################################
   162     # recipients / email sending ###############################################
   155 
   163 
   196             if val and isinstance(val, unicode) and val.strip():
   204             if val and isinstance(val, unicode) and val.strip():
   197                kwargs[key] = self._cw._(val)
   205                kwargs[key] = self._cw._(val)
   198         kwargs.update({'user': self.user_data['login'],
   206         kwargs.update({'user': self.user_data['login'],
   199                        'eid': entity.eid,
   207                        'eid': entity.eid,
   200                        'etype': entity.dc_type(),
   208                        'etype': entity.dc_type(),
   201                        'url': entity.absolute_url(),
   209                        'url': entity.absolute_url(__secure__=True),
   202                        'title': entity.dc_long_title(),})
   210                        'title': entity.dc_long_title(),})
   203         return kwargs
   211         return kwargs
   204 
   212 
   205 
   213 
   206 class StatusChangeMixIn(object):
   214 class StatusChangeMixIn(object):