Example #1
0
def create_favorite_for(user, face_id):
    global Favorites
    global Users

    if face_id in user.get('favorites', []):
        return False

    if user.get('nb_favorited') >= NB_MAX_FAVORITES:
        return False

    # create favorite object
    Favorites.insert({_FACE_ID: face_id,
                      'user_id': user.get('ident'),
                      'datetime': now()})

    # update facepicture counter for favorites
    face = get_face_from(face_id)
    update_face(face, {'nb_favorited': face.get('nb_favorited', 0) + 1})

    # update user counter + list of favs
    user.update({'favorites': user.get('favorites', []) + [face_id, ]})
    Users.save(user)

    # maybe update winner cache
    update_winner_cache_if_winner(face)
Example #2
0
def create_favorite_for(user, face_id):
    global Favorites
    global Users

    if face_id in user.get('favorites', []):
        return False

    if user.get('nb_favorited') >= NB_MAX_FAVORITES:
        return False

    # create favorite object
    Favorites.insert({
        _FACE_ID: face_id,
        'user_id': user.get('ident'),
        'datetime': now()
    })

    # update facepicture counter for favorites
    face = get_face_from(face_id)
    update_face(face, {'nb_favorited': face.get('nb_favorited', 0) + 1})

    # update user counter + list of favs
    user.update({'favorites': user.get('favorites', []) + [
        face_id,
    ]})
    Users.save(user)

    # maybe update winner cache
    update_winner_cache_if_winner(face)
Example #3
0
def favorites_ids_for_user(user):
    global Favorites
    return Favorites.find({'user_id': user.get('ident')})
Example #4
0
def favorites_ids_for_user(user):
    global Favorites
    return Favorites.find({'user_id': user.get('ident')})