Ejemplo n.º 1
0
def insert():
    role = request.form.get('role')
    district_id = request.form.get('district_id', None)

    if role == User.ROLE_FARMER or role == User.ROLE_DISTRICT_LEADER:
        if not district_id:
            abort(400, 'district_id is required')

        district = District.get_by_id(district_id)
        if not district:
            abort(400, '{} is an invalid district_id'.format(district_id))

    new = User(id=User.id(),
               role=role,
               district_id=district_id,
               phone_number=request.form.get('phone_number'),
               first_name=request.form.get('first_name'),
               last_name=request.form.get('last_name', None))

    new.put()
    return new.to_dict()
def insert():
    role = request.form.get('role')
    district_id = request.form.get('district_id', None)

    if role == User.ROLE_FARMER or role == User.ROLE_DISTRICT_LEADER:
        if not district_id:
            abort(400, 'district_id is required')

        district = District.get_by_id(district_id)
        if not district:
            abort(400, '{} is an invalid district_id'.format(district_id))

    new = User(id=User.id(),
               role=role,
               district_id=district_id,
               phone_number=request.form.get('phone_number'),
               first_name=request.form.get('first_name'),
               last_name=request.form.get('last_name', None))

    new.put()
    return new.to_dict()
def retrieve(district_id):
    district = District.get_by_id(district_id)
    if not district:
        abort(404, 'this resource does not exist')

    return district.to_dict()