Beispiel #1
0
def create_customers():
    """
    Add a Customer
    This endpoint will create a Customer based the data in the body that is posted
    """
    customer = Customer()
    customer.deserialize(request.get_json())
    customer.save()
    message = customer.serialize()
    location_url = url_for('get_customers',
                           customer_id=customer.id,
                           _external=True)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {'Location': location_url})
Beispiel #2
0
def load(filename):
    context = get_context()
    db = {}
    admin = Admin(ADMIN_USERNAME, ADMIN_PASSWORD)
    make_record(db, admin)
    try:
        with open(filename) as db_f:
            customers = [Customer.deserialize(line) for line in db_f if line.strip()]
            for customer in customers:
                make_record(db, customer)
    except FileNotFoundError:
        print("No such database. Save first?")
    context.db = db