def __notify_followers(act, **kwargs): """ Call a function that sends notifications to the Users, following given Request or Authority, to which this request is made. """ p= kwargs.get('piarequest', None) a= kwargs.get('authority', None) if (p is None) and (a is None): return g= ContentType.objects.get_for_model items= TaggedItem.objects.filter( Q(object_id=p.id, content_type_id=g(p.__class__).id)|\ Q(object_id=a.id, content_type_id=g(a.__class__).id)) if not items: return for item in items: notifications= item.notification.filter(**act) if notifications: for notification in notifications: if send_notification(notification): pass else: print "Cannot send notification:\n %s" %\ notification.__unicode__()
def process_notifications(): """ Checks for notifications about events. """ notification_processed= 0 for notification in EventNotification.objects.filter(awaiting=True): if notification.action == 'active': # Process the notification of an element become 'active'. is_active= False try: is_active= notification.item.content_object.active except: pass if is_active: if send_notification(notification): notification.awaiting= False notification.save() notification_processed += 1 else: print >> sys.stderr, '[%s] %s' % (datetime.now().isoformat(), AppMessage('NotificFailed').message % notification.__unicode__()) return "Completed processing notifications: %d sent." % notification_processed