Beispiel #1
0
def place_create(place):
    """
    It stores a new place.

    Parameters:
    - place: the Place containing the new information to store.

    It returns a tuple: 
    - the created place (or None in case of errors in the input),
    - the status (a string indicating whether an error occurred),
    - the http code indicating the type of error, if any
    """
    try:
        res = Place.store(place, None)
    except (TypeError, ValueError, InvalidKeyException) as e:
        return None, str(e), 400

    return res, "OK", 200
Beispiel #2
0
def place_update(in_place, place_id, place_key_str):
    """
    It updates the place.

    Parameters:
    - in_place: the Place containing the information to update
    - place_id: the string id of the Place
    - place_key_str: the urlsafe string representing the key.

    Only one between place_id and place_key_str should be set, since they represent the same information, 
    but encoded in two different ways. They are both accepted for generality. If both are set, the id is used.

    It returns a tuple: 
    - the place with updated information (or None in case of errors in the input),
    - the status (a string indicating whether an error occurred),
    - the http code indicating the type of error, if any
    """
    try:
        res = Place.store(
            in_place, Place.make_key(place_id, place_key_str))
    except (TypeError, ValueError, InvalidKeyException) as e:
        return None, str(e), 400

    return res, "OK", 200