def register(): resp = helpers.get_response(request) if len(resp['password']) < 6: return 'password too short', 406 usersMatch = filter(lambda u: u['username'] == resp['username'], glob.users) if len(usersMatch) != 0 : return 'Username already taken', 409 allowed_fields = ['username', 'password', 'email', 'address1', 'address2', 'city', 'firstname', 'lastname', 'postalcode', 'country', 'token'] mandatory_fields = ['username', 'password', 'email', 'address1', 'city', 'firstname', 'lastname', 'postalcode', 'country'] special_fields = ['password', 'token'] helpers.new_object(glob.users, resp, users_path, allowed_fields, mandatory_fields, special_fields) return 'Register successful', 201
def add_product(): resp = helpers.get_response(request) allowed_fields = ['title', 'description', 'dateStart', 'dateLength', 'startPrice', 'buyoutPrice', 'reservePrice', 'imgUrl'] mandatory_fields = ['title', 'description', 'dateStart', 'dateLength', 'startPrice'] user = helpers.get_by(glob.users, resp['user_id']) association_field = [{'association_name': 'user_id', 'association_value': user['id']}] product = helpers.new_object(glob.products, resp, products_path, allowed_fields, mandatory_fields, associations=association_field) return show(product['id'])