Reformat to follow PEP standards

This commit is contained in:
BBaoVanC 2020-10-05 01:07:22 -05:00
parent 8ae91f7ffa
commit 8c635adcc7
No known key found for this signature in database
GPG Key ID: 6D74C8B0E7D791C2
2 changed files with 40 additions and 38 deletions

View File

@ -24,7 +24,8 @@ def load_config():
for param in params: for param in params:
config[param[0]] = param[1] config[param[0]] = param[1]
else: 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 return config

View File

@ -11,26 +11,26 @@ from flask_api import status
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
import sqlalchemy 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 = Flask(__name__) # app is the Flask app
@app.route("/api/v1/locations", methods = ["GET"]) @app.route("/api/v1/locations", methods=["GET"])
def get_locations(): def get_locations():
"""Route to get locations""" """Route to get locations"""
session = Session() session = Session()
data = {} data = {}
try: 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} data[name] = {'description': desc}
except NoResultFound: except NoResultFound:
return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND
return jsonify(data) 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): def api_get_location_information(search):
"""Route to get information about a location""" """Route to get information about a location"""
session = Session() session = Session()
@ -45,13 +45,13 @@ def api_get_location_information(search):
return jsonify(data2) 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): def api_get_current_quantities(location):
"""Route to get quantities in a location""" """Route to get quantities in a location"""
session = Session() session = Session()
data = {} data = {}
try: 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(): .filter(ProductQuantity.location == location).all():
data[upc] = quantity data[upc] = quantity
return jsonify(data) return jsonify(data)
@ -59,7 +59,7 @@ def api_get_current_quantities(location):
return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND 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): def api_get_quantity_of_product_in_location(location, searchmethod, search):
"""Route to get the quantity of a product at a location""" """Route to get the quantity of a product at a location"""
session = Session() 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 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(): def api_get_products():
"""Route to get a list of products""" """Route to get a list of products"""
session = Session() session = Session()
@ -98,7 +98,7 @@ def api_get_products():
return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND 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): def api_get_product_information(searchmethod, search):
"""Route to get a information about a product""" """Route to get a information about a product"""
session = Session() session = Session()
@ -129,7 +129,7 @@ def api_get_product_information(searchmethod, search):
return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND 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(): def api_list_brands():
"""Route to list all brands""" """Route to list all brands"""
session = Session() session = Session()
@ -142,7 +142,7 @@ def api_list_brands():
return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND 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): def api_get_brand_by_name(search):
"""Route to get information about a location""" """Route to get information about a location"""
session = Session() session = Session()
@ -155,7 +155,7 @@ def api_get_brand_by_name(search):
return jsonify(data2) return jsonify(data2)
@app.route("/api/v1/create_location", methods = ["POST"]) @app.route("/api/v1/create_location", methods=["POST"])
def api_create_location(): def api_create_location():
"""Route to create a new location""" """Route to create a new location"""
session = Session() session = Session()
@ -178,7 +178,7 @@ def api_create_location():
return jsonify({'api_endpoint': f'/api/v1/location/name/{locname}'}) 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(): def api_create_brand():
"""Route to create a new brand""" """Route to create a new brand"""
session = Session() session = Session()
@ -191,7 +191,8 @@ def api_create_brand():
else: else:
branddesc = None 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}") print(f"ins is {ins}")
session.execute(ins) session.execute(ins)
print("executed ins") print("executed ins")
@ -201,7 +202,7 @@ def api_create_brand():
return jsonify({'api_endpoints': [f'/api/v1/brand/name/{brandname}']}) 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(): def api_create_product():
"""Route to create a new product""" """Route to create a new product"""
session = Session() session = Session()