Author: brosner
Date: Mon Oct 13 14:40:22 2008
New Revision: 106

Modified:
    trunk/notification/engine.py
    trunk/notification/models.py

Log:
Renamed current send to send_now and made send a wrapper around send and  
queue. This allows for a global queue toggle as well as per-call overrides  
using `queue` and `now` kwargs.

Modified: trunk/notification/engine.py
==============================================================================
--- trunk/notification/engine.py        (original)
+++ trunk/notification/engine.py        Mon Oct 13 14:40:22 2008
@@ -44,7 +44,7 @@
                  logging.info("emitting notice to %s" % user)
                  # call this once per user to be atomic and allow for  
logging to
                  # accurately show how long each takes.
-                notification.send([user], label, extra_context, on_site)
+                notification.send_now([user], label, extra_context,  
on_site)
                  sent += 1
              queued_batch.delete()
              batches += 1

Modified: trunk/notification/models.py
==============================================================================
--- trunk/notification/models.py        (original)
+++ trunk/notification/models.py        Mon Oct 13 14:40:22 2008
@@ -30,6 +30,8 @@
  except ImportError:
      from django.core.mail import send_mail

+QUEUE_ALL = getattr(settings, "NOTIFICATION_QUEUE_ALL", False)
+
  class LanguageStoreNotAvailable(Exception):
      pass

@@ -225,7 +227,7 @@
              'notification/%s' % format), context_instance=context)
      return format_templates

-def send(users, label, extra_context=None, on_site=True):
+def send_now(users, label, extra_context=None, on_site=True):
      """
      Creates a new notice.

@@ -302,6 +304,26 @@
      # reset environment to original language
      activate(current_language)

+def send(*args, **kwargs):
+    """
+    A basic interface around both queue and send_now. This honors a global
+    flag NOTIFICATION_QUEUE_ALL that helps determine whether all calls  
should
+    be queued or not. A per call ``queue`` or ``now`` keyword argument can  
be
+    used to always override the default global behavior.
+    """
+    queue_flag = kwargs.pop("queue", False)
+    now_flag = kwargs.pop("now", False)
+    assert not (queue_flag and now_flag), "'queue' and 'now' cannot both  
be True."
+    if queue_flag:
+        return queue(*args, **kwargs)
+    elif now_flag:
+        return send_now(*args, **kwargs)
+    else:
+        if QUEUE_ALL:
+            return queue(*args, **kwargs)
+        else:
+            return send_now(*args, **kwargs)
+
  def queue(users, label, extra_context=None, on_site=True):
      """
      Queue the notification in NoticeQueueBatch. This allows for large  
amounts

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to