コード例 #1
0
ファイル: api.py プロジェクト: dennisai/mavenize-beta
def get_new_bookmarks_count(user_id):
    """
    Returns the number of new bookmarks for a user.
        user_id: primary key of the user (integer)
    """
    return simplejson.dumps(
        cacheAPI._get_new_bookmarks_count(user_id))
コード例 #2
0
def queue_bookmark_notifications(user_id, item_id):
    """
    Emits a notification via SocketIO to the friends of the user
    who have bookmarked the same item.
        user_id: the primary key of the user (integer)
        item_id: the primary key of the item (integer)
    """
    following = list(
        Forward.objects.filter(source_id=user_id).values_list('destination_id',
                                                              flat=True))
    followers = list(
        Backward.objects.filter(destination_id=user_id).values_list(
            'source_id', flat=True))
    friends = list(set(following) & set(followers))
    to_notify = Bookmark.objects.filter(user__in=friends, item=item_id) \
                                .values_list('user_id', flat=True)
    for user in to_notify:
        if not cacheAPI._get_new_bookmarks_count(user):
            cacheAPI._reset_new_bookmarks_count(user)
        cacheAPI._increment_new_bookmarks_count(user)
        announce_client.register_group(user, 'bookmarks')
    announce_client.broadcast_group(
        group_name='bookmarks',
        channel='bookmark',
        data={'new': 1}  # Currently un-used
    )
    for user in to_notify:
        announce_client.unregister_group(user, 'bookmarks')
コード例 #3
0
ファイル: signalAPI.py プロジェクト: dennisai/mavenize-beta
def queue_bookmark_notifications(user_id, item_id):
    """
    Emits a notification via SocketIO to the friends of the user
    who have bookmarked the same item.
        user_id: the primary key of the user (integer)
        item_id: the primary key of the item (integer)
    """
    following = list(Forward.objects.filter(source_id=user_id)
                            .values_list('destination_id', flat=True))
    followers =list(Backward.objects.filter(destination_id=user_id)
                            .values_list('source_id', flat=True))
    friends = list(set(following) & set(followers))
    to_notify = Bookmark.objects.filter(user__in=friends, item=item_id) \
                                .values_list('user_id', flat=True)
    for user in to_notify:
        if not cacheAPI._get_new_bookmarks_count(user):
            cacheAPI._reset_new_bookmarks_count(user)
        cacheAPI._increment_new_bookmarks_count(user)
        announce_client.register_group(user, 'bookmarks')
    announce_client.broadcast_group(
        group_name='bookmarks',
        channel='bookmark',
        data = { 'new': 1 } # Currently un-used
    )
    for user in to_notify:
        announce_client.unregister_group(user, 'bookmarks')
コード例 #4
0
def get_new_bookmarks_count(user_id):
    """
    Returns the number of new bookmarks for a user.
        user_id: primary key of the user (integer)
    """
    return simplejson.dumps(cacheAPI._get_new_bookmarks_count(user_id))