def get_new_notifications_count(user_id): """ Returns the number of new notifications for a user. user_id: primary key of the user (integer) """ return simplejson.dumps( cacheAPI._get_new_notifications_count(user_id))
def queue_notification(sender_id, recipient_id, model_name, obj_id): """ Adds a notification for an agree, thanks, bookmark, or follow. Increments the notification count in the cache. sender_id: agree.giver_id, thank.giver_id, bookmark.user_id, or backward.source_id recipient_id: agree.review.user_id, thank.review.user_id, 0, or backward.destination_id model_name: string of class name obj_id: object.pk """ model = get_model(MODEL_APP_NAME[model_name], model_name) try: pg_notification = Notification( sender=User.objects.get(pk=sender_id), recipient=User.objects.get(pk=recipient_id), notification_type=model_name ) if model_name == "agree" or model_name == "thank": obj = model.objects.get(pk=obj_id) pg_notification.item = obj.review.item if model_name == "thank": pg_notification.note = obj.note pg_notification.save() if not cacheAPI._get_new_notifications_count(recipient_id): cacheAPI._reset_new_notifications_count(recipient_id) cacheAPI._increment_new_notifications_count(recipient_id) cacheAPI._cache_notification_for_user(pg_notification) announce_client.emit( recipient_id, 'notification', data={ 'new': 1 } # Currently un-used ) except ObjectDoesNotExist: pass
def queue_notification(sender_id, recipient_id, model_name, obj_id): """ Adds a notification for an agree, thanks, bookmark, or follow. Increments the notification count in the cache. sender_id: agree.giver_id, thank.giver_id, bookmark.user_id, or backward.source_id recipient_id: agree.review.user_id, thank.review.user_id, 0, or backward.destination_id model_name: string of class name obj_id: object.pk """ model = get_model(MODEL_APP_NAME[model_name], model_name) try: pg_notification = Notification( sender=User.objects.get(pk=sender_id), recipient=User.objects.get(pk=recipient_id), notification_type=model_name) if model_name == "agree" or model_name == "thank": obj = model.objects.get(pk=obj_id) pg_notification.item = obj.review.item if model_name == "thank": pg_notification.note = obj.note pg_notification.save() if not cacheAPI._get_new_notifications_count(recipient_id): cacheAPI._reset_new_notifications_count(recipient_id) cacheAPI._increment_new_notifications_count(recipient_id) cacheAPI._cache_notification_for_user(pg_notification) announce_client.emit( recipient_id, 'notification', data={'new': 1} # Currently un-used ) except ObjectDoesNotExist: pass
def get_new_notifications_count(user_id): """ Returns the number of new notifications for a user. user_id: primary key of the user (integer) """ return simplejson.dumps(cacheAPI._get_new_notifications_count(user_id))