[notification] drop on commit sending of message feature of NotificationView
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 21 May 2014 22:54:46 +0200
changeset 9826 7c17659c9eae
parent 9825 946b483bc8a1
child 9873 1257e909d25e
[notification] drop on commit sending of message feature of NotificationView It duplicates feature already provided by cw.hooks.notification.notify_on_commit function. Simplify the API on the way.
sobjects/notification.py
--- a/sobjects/notification.py	Fri Mar 21 08:28:32 2014 +0100
+++ b/sobjects/notification.py	Wed May 21 22:54:46 2014 +0200
@@ -80,15 +80,8 @@
 
     # this is usually the method to call
     def render_and_send(self, **kwargs):
-        """generate and send an email message for this view"""
-        delayed = kwargs.pop('delay_to_commit', None)
-        for recipients, msg in self.render_emails(**kwargs):
-            if delayed is None:
-                self.send(recipients, msg)
-            elif delayed:
-                self.send_on_commit(recipients, msg)
-            else:
-                self.send_now(recipients, msg)
+        """generate and send email messages for this view"""
+        self._cw.vreg.config.sendmails(self.render_emails(**kwargs))
 
     def cell_call(self, row, col=0, **kwargs):
         self.w(self._cw._(self.content) % self.context(**kwargs))
@@ -146,16 +139,11 @@
                         continue
                     msg = format_mail(self.user_data, [emailaddr], content, subject,
                                       config=self._cw.vreg.config, msgid=msgid, references=refs)
-                    yield [emailaddr], msg
+                    yield msg, [emailaddr]
                 finally:
-                    # ensure we have a cnxset since commit will fail if there is
-                    # some operation but no cnxset. This may occurs in this very
-                    # specific case (eg SendMailOp)
-                    with cnx.ensure_cnx_set:
-                        cnx.commit()
                     self._cw = req
 
-    # recipients / email sending ###############################################
+    # recipients handling ######################################################
 
     def recipients(self):
         """return a list of either 2-uple (email, language) or user entity to
@@ -166,13 +154,6 @@
             row=self.cw_row or 0, col=self.cw_col or 0)
         return finder.recipients()
 
-    def send_now(self, recipients, msg):
-        self._cw.vreg.config.sendmails([(msg, recipients)])
-
-    def send_on_commit(self, recipients, msg):
-        SendMailOp(self._cw, recipients=recipients, msg=msg)
-    send = send_on_commit
-
     # email generation helpers #################################################
 
     def construct_message_id(self, eid):