56 lines
1.7 KiB
Python
56 lines
1.7 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(new_version):
|
|
if new_version:
|
|
# We simply return the smallest size, assuming that is also the cheapest.
|
|
# It is technically possible that a larger size is cheaper, but unlikely, so we avoid the extra complexity
|
|
# of calculating the guaranteed cheapest product.
|
|
return 'canvas_200x300-mm-8x12-inch_canvas_wood-fsc-slim_4-0_ver'
|
|
|
|
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(new_version):
|
|
if new_version:
|
|
return 'flat_250x250-mm-10x10-inch_200-gsm-80lb-uncoated_4-0_ver'
|
|
|
|
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
|