Reformat to follow PEP standards
This commit is contained in:
		
							
								
								
									
										3
									
								
								libdb.py
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								libdb.py
									
									
									
									
									
								
							@@ -24,7 +24,8 @@ def load_config():
 | 
			
		||||
        for param in params:
 | 
			
		||||
            config[param[0]] = param[1]
 | 
			
		||||
    else:
 | 
			
		||||
        raise Exception('Section {0} not found in the {1} file'.format(section, filename))
 | 
			
		||||
        raise Exception(
 | 
			
		||||
            'Section {0} not found in the {1} file'.format(section, filename))
 | 
			
		||||
    return config
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										31
									
								
								webapi.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								webapi.py
									
									
									
									
									
								
							@@ -11,26 +11,26 @@ from flask_api import status
 | 
			
		||||
 | 
			
		||||
from sqlalchemy.orm.exc import NoResultFound
 | 
			
		||||
import sqlalchemy
 | 
			
		||||
from libdb import engine, Session, Location, ProductQuantity, Product, Brand
 | 
			
		||||
from libdb import Session, Location, ProductQuantity, Product, Brand
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
app = Flask(__name__)  # app is the Flask app
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/locations", methods = ["GET"])
 | 
			
		||||
@app.route("/api/v1/locations", methods=["GET"])
 | 
			
		||||
def get_locations():
 | 
			
		||||
    """Route to get locations"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
    data = {}
 | 
			
		||||
    try:
 | 
			
		||||
        for name,desc in session.query(Location.name, Location.description):
 | 
			
		||||
        for name, desc in session.query(Location.name, Location.description):
 | 
			
		||||
            data[name] = {'description': desc}
 | 
			
		||||
    except NoResultFound:
 | 
			
		||||
        return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND
 | 
			
		||||
    return jsonify(data)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/location/name/<search>", methods = ["GET"])
 | 
			
		||||
@app.route("/api/v1/location/name/<search>", methods=["GET"])
 | 
			
		||||
def api_get_location_information(search):
 | 
			
		||||
    """Route to get information about a location"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
@@ -45,13 +45,13 @@ def api_get_location_information(search):
 | 
			
		||||
    return jsonify(data2)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/location/<location>/quantities", methods = ["GET"])
 | 
			
		||||
@app.route("/api/v1/location/<location>/quantities", methods=["GET"])
 | 
			
		||||
def api_get_current_quantities(location):
 | 
			
		||||
    """Route to get quantities in a location"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
    data = {}
 | 
			
		||||
    try:
 | 
			
		||||
        for upc,quantity in session.query(ProductQuantity.product_upc, ProductQuantity.quantity) \
 | 
			
		||||
        for upc, quantity in session.query(ProductQuantity.product_upc, ProductQuantity.quantity) \
 | 
			
		||||
                .filter(ProductQuantity.location == location).all():
 | 
			
		||||
            data[upc] = quantity
 | 
			
		||||
        return jsonify(data)
 | 
			
		||||
@@ -59,7 +59,7 @@ def api_get_current_quantities(location):
 | 
			
		||||
        return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/location/<location>/quantity/<searchmethod>/<search>", methods = ["GET"])
 | 
			
		||||
@app.route("/api/v1/location/<location>/quantity/<searchmethod>/<search>", methods=["GET"])
 | 
			
		||||
def api_get_quantity_of_product_in_location(location, searchmethod, search):
 | 
			
		||||
    """Route to get the quantity of a product at a location"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
@@ -82,7 +82,7 @@ def api_get_quantity_of_product_in_location(location, searchmethod, search):
 | 
			
		||||
        return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/products", methods = ["GET"])
 | 
			
		||||
@app.route("/api/v1/products", methods=["GET"])
 | 
			
		||||
def api_get_products():
 | 
			
		||||
    """Route to get a list of products"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
@@ -98,7 +98,7 @@ def api_get_products():
 | 
			
		||||
        return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/product/<searchmethod>/<search>", methods = ["GET"])
 | 
			
		||||
@app.route("/api/v1/product/<searchmethod>/<search>", methods=["GET"])
 | 
			
		||||
def api_get_product_information(searchmethod, search):
 | 
			
		||||
    """Route to get a information about a product"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
@@ -129,7 +129,7 @@ def api_get_product_information(searchmethod, search):
 | 
			
		||||
        return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/brands", methods = ["GET"])
 | 
			
		||||
@app.route("/api/v1/brands", methods=["GET"])
 | 
			
		||||
def api_list_brands():
 | 
			
		||||
    """Route to list all brands"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
@@ -142,7 +142,7 @@ def api_list_brands():
 | 
			
		||||
        return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/brand/name/<search>", methods = ["GET"])
 | 
			
		||||
@app.route("/api/v1/brand/name/<search>", methods=["GET"])
 | 
			
		||||
def api_get_brand_by_name(search):
 | 
			
		||||
    """Route to get information about a location"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
@@ -155,7 +155,7 @@ def api_get_brand_by_name(search):
 | 
			
		||||
    return jsonify(data2)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/create_location", methods = ["POST"])
 | 
			
		||||
@app.route("/api/v1/create_location", methods=["POST"])
 | 
			
		||||
def api_create_location():
 | 
			
		||||
    """Route to create a new location"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
@@ -178,7 +178,7 @@ def api_create_location():
 | 
			
		||||
    return jsonify({'api_endpoint': f'/api/v1/location/name/{locname}'})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/create_brand", methods = ["POST"])
 | 
			
		||||
@app.route("/api/v1/create_brand", methods=["POST"])
 | 
			
		||||
def api_create_brand():
 | 
			
		||||
    """Route to create a new brand"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
@@ -191,7 +191,8 @@ def api_create_brand():
 | 
			
		||||
    else:
 | 
			
		||||
        branddesc = None
 | 
			
		||||
 | 
			
		||||
    ins = sqlalchemy.insert(Brand).values(name=brandname, description=branddesc)
 | 
			
		||||
    ins = sqlalchemy.insert(Brand).values(
 | 
			
		||||
        name=brandname, description=branddesc)
 | 
			
		||||
    print(f"ins is {ins}")
 | 
			
		||||
    session.execute(ins)
 | 
			
		||||
    print("executed ins")
 | 
			
		||||
@@ -201,7 +202,7 @@ def api_create_brand():
 | 
			
		||||
    return jsonify({'api_endpoints': [f'/api/v1/brand/name/{brandname}']})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/api/v1/create_product", methods = ["POST"])
 | 
			
		||||
@app.route("/api/v1/create_product", methods=["POST"])
 | 
			
		||||
def api_create_product():
 | 
			
		||||
    """Route to create a new product"""
 | 
			
		||||
    session = Session()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user