コード例 #1
0
ファイル: logic.py プロジェクト: sphoebs/rockshell
def rating_count(user_id=None, user_str=None, place_id=None, place_str=None):
    """
    It counts the number of ratings for a user, a place or both.

    Parameters:
    - user_id and user_str: key (str = urlsafe) for the PFuser, only one needed
    - place_id and place_str: key (str = urlsafe) for the Place, only one needed


    It returns a tuple: 
    - the number of ratings,
    - the status (a string indicating whether an error occurred)
    - the http code indicating the type of error, if any
    """
    try:
        user_key = PFuser.make_key(user_id, user_str)
        place_key = Place.make_key(place_id, place_str)
        count = Rating.count(user_key, place_key)
    except TypeError as e:
        return None, str(e), 400

    return count, "OK", 200