47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
# coding=UTF-8
|
|
|
|
from api.extensions import db
|
|
from api.lib.utils import lru_with_ttl
|
|
|
|
@lru_with_ttl(ttl_seconds=300)
|
|
def get_all_external_print_products():
|
|
sql="select external_product_id, price_sek, group_id from external_print_products"
|
|
result = db.session.execute(sql)
|
|
rows = result.fetchall()
|
|
|
|
prices = {}
|
|
for row in rows:
|
|
external_id = row[0]
|
|
price = float(row[1])
|
|
group_id = row[2]
|
|
prices[external_id] = {"price": price, "group_id": group_id}
|
|
|
|
return prices
|
|
|
|
|
|
def get_external_print_product(id):
|
|
all = get_all_external_print_products()
|
|
|
|
if id not in all:
|
|
raise ValueError("Invalid external product id: {}".format(id))
|
|
|
|
external_product = all.get(id)
|
|
|
|
return external_product
|
|
|
|
|
|
def get_cheapest_canvas_product():
|
|
sql = "select external_product_id from external_print_products where group_id = 2 order by price_sek limit 1"
|
|
result = db.session.execute(sql)
|
|
external_id = result.first()[0]
|
|
|
|
return external_id
|
|
|
|
|
|
def get_cheapest_poster_product():
|
|
sql = "select external_product_id from external_print_products where group_id in (7,8) order by price_sek limit 1"
|
|
result = db.session.execute(sql)
|
|
external_id = result.first()[0]
|
|
|
|
return external_id
|