示例#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)
示例#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)
示例#3
0
def update_user_details(user, data):
    global Users
    fb_data = {}
    for k, v in data.items():
        if not k in ('id'):
            fb_data.update({k: v})
    user.update(fb_data)
    Users.save(user)
    return user
示例#4
0
def update_user_details(user, data):
    global Users
    fb_data = {}
    for k, v in data.items():
        if not k in ('id'):
            fb_data.update({k: v})
    user.update(fb_data)
    Users.save(user)
    return user
示例#5
0
def get_create_user_from(user_id, user_type=LOGGED_IN):
    global Users
    user = Users.find_one({'type': user_type, 'ident': user_id})
    if not user:
        max_votes_regular = MAX_VOTES_LOGGED_IN if user_type == LOGGED_IN else MAX_VOTES_ANONYMOUS
        Users.insert({'type': user_type, 'ident': user_id,
                      'nb_remaing_votes_regular': max_votes_regular,
                      'nb_remaing_votes_favorite': NB_MAX_VOTES_FAVORITES})
        user = Users.find_one({'type': user_type, 'ident': user_id})
    return user
示例#6
0
def get_create_user_from(user_id, user_type=LOGGED_IN):
    global Users
    user = Users.find_one({'type': user_type, 'ident': user_id})
    if not user:
        max_votes_regular = MAX_VOTES_LOGGED_IN if user_type == LOGGED_IN else MAX_VOTES_ANONYMOUS
        Users.insert({
            'type': user_type,
            'ident': user_id,
            'nb_remaing_votes_regular': max_votes_regular,
            'nb_remaing_votes_favorite': NB_MAX_VOTES_FAVORITES
        })
        user = Users.find_one({'type': user_type, 'ident': user_id})
    return user
示例#7
0
文件: api.py 项目: jieyuxu/QRoom
def getUser(net_id):
    user = sess.query(Users)\
            .filter(Users.net_id == net_id)\
            .first()

    if user is None:
        print("it tis none")
        user = Users(net_id=net_id,
                     contact=net_id + '@princeton.edu',
                     admin=False)
        sess.add(user)
        sess.commit()
    return user
示例#8
0
                    latitude=40.3496224,
                    longitude=-74.6526984)

# @40.3423081,-74.6596026

group1 = Groups(open_time=time(8, 00, 00), close_time=time(5, 00, 00))
group2 = Groups(open_time=time(8, 00, 00), close_time=time(20, 00, 00))

room1 = Rooms(building=firestone, room_name='101', group=group1)
room2 = Rooms(building=frist, room_name='102', group=group2)
room3 = Rooms(building=lewis, room_name='103', group=group1)
room4 = Rooms(building=firestone, room_name='104', group=group1)
room5 = Rooms(building=sherred, room_name='006', group=group2)
room6 = Rooms(building=philly, room_name='312', group=group1)

paul = Users(net_id="pe5", contact='*****@*****.**', admin=True)
bob = Users(net_id="rdondero", contact='*****@*****.**', admin=True)

saishaa = Users(net_id="saishaa", contact="*****@*****.**", admin=True)
suki = Users(net_id="sukiy", contact="*****@*****.**", admin=True)
amy = Users(net_id="jyxu", contact="*****@*****.**", admin=True)
jeanna = Users(net_id="jmjoseph", contact="*****@*****.**", admin=True)

event1 = Events(user=paul,
                event_title="Paul's birthday",
                start_time=datetime(2020, 11, 28, 23, 55, 59, 342380),
                end_time=datetime(2020, 11, 29, 23, 55, 59, 0),
                room=room1,
                passed=False)

event2 = Events(user=saishaa,
示例#9
0
def decrease_vote_counter(user, vote_type=REGULAR):
    global Users
    key = 'nb_remaing_votes_%s' % 'regular' if vote_type == REGULAR else 'favorite'
    user.update({key: user.get(key, 1) - 1})
    Users.save(user)
示例#10
0
def user_from_user_id(user_id):
    global Users
    return Users.find_one({'ident': user_id})
示例#11
0
def user_from_user_id(user_id):
    global Users
    return Users.find_one({'ident': user_id})