Example #1
0
    - the status (a string indicating whether an error occurred),
    - the http code indicating the type of error, if any
    """
    if user_id is not None or user_key_str is not None:
        try:
            rating.user = PFuser.make_key(user_id, user_key_str)
        except TypeError, e:
            return None, str(e), 400
    # TODO: limit only to logged users (need to be commented now to upload data from old datasets)
#     else:
#         return None, "The user must login before creating a rating!", 403

    logging.info("Rating user: " + str(rating.user))

    try:
        res = Rating.store(rating)
    except (TypeError, ValueError) as e:
        return None, str(e), 400

    client = memcache.Client()
    users = client.gets('updated_users')
    if users is None:
        client.add('updated_users', [])
        users = client.gets('updated_users')

    if not rating.user.id() in users:
        users.append(rating.user.id())
        i = 0
        while i < 20:
            i += 1
            if client.cas('updated_users', users):