Esempio n. 1
0
def create_face_picture(url, facebook_id, x, y, width, height):
    global FacePictures
    raw = get_raw_picture_by(facebook_id)
    face_id = uuid.uuid4().hex
    doc = {
        _FACE_ID: face_id,
        'url': url,
        'face_x': x,
        'face_y': y,
        'face_width': width,
        'face_height': height,
        'source_width': raw.get('width'),
        'source_height': raw.get('height'),
        'facebook_id': facebook_id,
        'datetime': datetime.datetime.now(),
        'nb_votes': 0,
        'nb_votes_total': 0,
        'tag': NOTTAGGED,
        'tags': {},
        'views': 0,
        'views_total': 0,
        'score': 0,
        'score_total': 0,
        'nb_favorited': 0,
        'favorite_votes': 0,
        'favorite_votes_total': 0,
        'bonusmalus': [],
        'bonusmalus_total': [],
        'has_won': False
    }
    FacePictures.insert(doc)
    return get_face_from(face_id)
Esempio n. 2
0
def create_face_picture(url, facebook_id, x, y, width, height):
    global FacePictures
    raw = get_raw_picture_by(facebook_id)
    face_id = uuid.uuid4().hex
    doc = {_FACE_ID: face_id,
           'url': url,
           'face_x': x,
           'face_y': y,
           'face_width': width,
           'face_height': height,
           'source_width': raw.get('width'),
           'source_height': raw.get('height'),
           'facebook_id': facebook_id,
           'datetime': datetime.datetime.now(),
           'nb_votes': 0,
           'nb_votes_total': 0,
           'tag': NOTTAGGED,
           'tags': {},
           'views': 0,
           'views_total': 0,
           'score': 0,
           'score_total': 0,
           'nb_favorited': 0,
           'favorite_votes': 0,
           'favorite_votes_total': 0,
           'bonusmalus': [],
           'bonusmalus_total': [],
           'has_won': False}
    FacePictures.insert(doc)
    return get_face_from(face_id)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
    def wrapper(*args, **kwargs):
        from utils.face_data import get_face_from
        face = kwargs.get('face', None)
        if face is None:
            raise Exception("@ensure_face decorator needs explicit face.")

        if not isinstance(face, dict):
            kwargs['face'] = get_face_from(face)

        return target_func(*args, **kwargs)
Esempio n. 6
0
    def wrapper(*args, **kwargs):
        from utils.face_data import get_face_from

        face = kwargs.get("face", None)
        if face is None:
            raise Exception("@ensure_face decorator needs explicit face.")

        if not isinstance(face, dict):
            kwargs["face"] = get_face_from(face)

        return target_func(*args, **kwargs)