reformat code with black
This commit is contained in:
+24
-24
@@ -1,31 +1,31 @@
|
||||
# coding=UTF-8
|
||||
|
||||
CANVAS = {
|
||||
'max_long_side': 500,
|
||||
'min_long_side': 20,
|
||||
'max_short_side': 150,
|
||||
'min_short_side': 20
|
||||
"max_long_side": 500,
|
||||
"min_long_side": 20,
|
||||
"max_short_side": 150,
|
||||
"min_short_side": 20,
|
||||
}
|
||||
|
||||
CANVAS_FRAME = {
|
||||
'max_long_side': 150,
|
||||
'min_long_side': 40,
|
||||
'max_short_side': 150,
|
||||
'min_short_side': 40,
|
||||
"max_long_side": 150,
|
||||
"min_long_side": 40,
|
||||
"max_short_side": 150,
|
||||
"min_short_side": 40,
|
||||
}
|
||||
|
||||
|
||||
def calculate_canvas_frame_limits(width, height):
|
||||
if width > height:
|
||||
width = min(width, CANVAS_FRAME.get('max_long_side'))
|
||||
width = max(width, CANVAS_FRAME.get('min_long_side'))
|
||||
height = min(height, CANVAS_FRAME.get('max_short_side'))
|
||||
height = max(height, CANVAS_FRAME.get('min_short_side'))
|
||||
width = min(width, CANVAS_FRAME.get("max_long_side"))
|
||||
width = max(width, CANVAS_FRAME.get("min_long_side"))
|
||||
height = min(height, CANVAS_FRAME.get("max_short_side"))
|
||||
height = max(height, CANVAS_FRAME.get("min_short_side"))
|
||||
else:
|
||||
height = min(height, CANVAS_FRAME.get('max_long_side'))
|
||||
height = max(height, CANVAS_FRAME.get('min_long_side'))
|
||||
width = min(width, CANVAS_FRAME.get('max_short_side'))
|
||||
width = max(width, CANVAS_FRAME.get('min_short_side'))
|
||||
height = min(height, CANVAS_FRAME.get("max_long_side"))
|
||||
height = max(height, CANVAS_FRAME.get("min_long_side"))
|
||||
width = min(width, CANVAS_FRAME.get("max_short_side"))
|
||||
width = max(width, CANVAS_FRAME.get("min_short_side"))
|
||||
|
||||
# round to nearest 10
|
||||
width = round(width, -1)
|
||||
@@ -39,14 +39,14 @@ def calculate_canvas_limits(width, height, framed=False):
|
||||
return calculate_canvas_frame_limits(width, height)
|
||||
|
||||
if width > height:
|
||||
width = min(width, CANVAS.get('max_long_side'))
|
||||
width = max(width, CANVAS.get('min_long_side'))
|
||||
height = min(height, CANVAS.get('max_short_side'))
|
||||
height = max(height, CANVAS.get('min_short_side'))
|
||||
width = min(width, CANVAS.get("max_long_side"))
|
||||
width = max(width, CANVAS.get("min_long_side"))
|
||||
height = min(height, CANVAS.get("max_short_side"))
|
||||
height = max(height, CANVAS.get("min_short_side"))
|
||||
else:
|
||||
height = min(height, CANVAS.get('max_long_side'))
|
||||
height = max(height, CANVAS.get('min_long_side'))
|
||||
width = min(width, CANVAS.get('max_short_side'))
|
||||
width = max(width, CANVAS.get('min_short_side'))
|
||||
height = min(height, CANVAS.get("max_long_side"))
|
||||
height = max(height, CANVAS.get("min_long_side"))
|
||||
width = min(width, CANVAS.get("max_short_side"))
|
||||
width = max(width, CANVAS.get("min_short_side"))
|
||||
|
||||
return width, height
|
||||
|
||||
+106
-36
@@ -5,7 +5,15 @@ from api.lib.utils import round_half_up
|
||||
from api.lib.limits import calculate_canvas_limits
|
||||
|
||||
|
||||
def m2_price(material, market, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True):
|
||||
def m2_price(
|
||||
material,
|
||||
market,
|
||||
designer=None,
|
||||
reseller=None,
|
||||
inquiry=None,
|
||||
rounded=True,
|
||||
inc_vat=True,
|
||||
):
|
||||
""" calculates price per square meter """
|
||||
price = material.price / 100.0
|
||||
|
||||
@@ -30,9 +38,20 @@ def m2_price(material, market, designer=None, reseller=None, inquiry=None, round
|
||||
return price
|
||||
|
||||
|
||||
def wallpaper_price(width, height, material, market, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True):
|
||||
price = m2_price(material, market, designer, reseller,
|
||||
inquiry, rounded=rounded, inc_vat=False)
|
||||
def wallpaper_price(
|
||||
width,
|
||||
height,
|
||||
material,
|
||||
market,
|
||||
designer=None,
|
||||
reseller=None,
|
||||
inquiry=None,
|
||||
rounded=True,
|
||||
inc_vat=True,
|
||||
):
|
||||
price = m2_price(
|
||||
material, market, designer, reseller, inquiry, rounded=rounded, inc_vat=False
|
||||
)
|
||||
|
||||
sqm = (width / 100) * (height / 100)
|
||||
|
||||
@@ -81,8 +100,8 @@ def canvas_cm2_price(cm2):
|
||||
|
||||
|
||||
def package_price(product_group, width, height, market):
|
||||
if market.territory == 'US':
|
||||
if product_group in ['canvas', 'poster']:
|
||||
if market.territory == "US":
|
||||
if product_group in ["canvas", "poster"]:
|
||||
if width > 110:
|
||||
return 150
|
||||
else:
|
||||
@@ -90,7 +109,17 @@ def package_price(product_group, width, height, market):
|
||||
return 0
|
||||
|
||||
|
||||
def canvas_price(width, height, market, framed=True, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True):
|
||||
def canvas_price(
|
||||
width,
|
||||
height,
|
||||
market,
|
||||
framed=True,
|
||||
designer=None,
|
||||
reseller=None,
|
||||
inquiry=None,
|
||||
rounded=True,
|
||||
inc_vat=True,
|
||||
):
|
||||
cm2 = width * height
|
||||
|
||||
cm2_price = canvas_cm2_price(cm2)
|
||||
@@ -113,7 +142,7 @@ def canvas_price(width, height, market, framed=True, designer=None, reseller=Non
|
||||
if inquiry:
|
||||
price *= (float(inquiry.pricepremium) / 100) + 1
|
||||
|
||||
price += package_price('canvas', width, height, market)
|
||||
price += package_price("canvas", width, height, market)
|
||||
|
||||
price *= market.exchange_rate
|
||||
|
||||
@@ -126,7 +155,9 @@ def canvas_price(width, height, market, framed=True, designer=None, reseller=Non
|
||||
return price
|
||||
|
||||
|
||||
def canvas_frame_price(width, height, market, reseller=None, rounded=True, inc_vat=True):
|
||||
def canvas_frame_price(
|
||||
width, height, market, reseller=None, rounded=True, inc_vat=True
|
||||
):
|
||||
width, height = calculate_canvas_limits(width, height, framed=True)
|
||||
cm2 = width * height
|
||||
cm2_price = canvas_cm2_price(cm2)
|
||||
@@ -139,7 +170,7 @@ def canvas_frame_price(width, height, market, reseller=None, rounded=True, inc_v
|
||||
if reseller:
|
||||
price *= (float(reseller.pricepremium) / 100) + 1
|
||||
|
||||
price += package_price('canvas', width, height, market)
|
||||
price += package_price("canvas", width, height, market)
|
||||
|
||||
price *= market.exchange_rate
|
||||
|
||||
@@ -178,13 +209,23 @@ def poster_cm2_price(cm2):
|
||||
return cm2_price
|
||||
|
||||
|
||||
def poster_price(width, height, market, hanger=True, designer=None, reseller=None, inquiry=None, rounded=True, inc_vat=True):
|
||||
def poster_price(
|
||||
width,
|
||||
height,
|
||||
market,
|
||||
hanger=True,
|
||||
designer=None,
|
||||
reseller=None,
|
||||
inquiry=None,
|
||||
rounded=True,
|
||||
inc_vat=True,
|
||||
):
|
||||
cm2 = width * height
|
||||
cm2_price = poster_cm2_price(cm2)
|
||||
price = cm2 * cm2_price
|
||||
price = max(price, 200) # the price can never go below 200 SEK
|
||||
|
||||
if(hanger):
|
||||
if hanger:
|
||||
price += _price_for_poster_hanger_size(width)
|
||||
|
||||
price *= market.price_adjustments
|
||||
@@ -198,7 +239,7 @@ def poster_price(width, height, market, hanger=True, designer=None, reseller=Non
|
||||
if inquiry:
|
||||
price *= (float(inquiry.pricepremium) / 100) + 1
|
||||
|
||||
price += package_price('poster', width, height, market)
|
||||
price += package_price("poster", width, height, market)
|
||||
|
||||
price *= market.exchange_rate
|
||||
|
||||
@@ -214,14 +255,16 @@ def poster_price(width, height, market, hanger=True, designer=None, reseller=Non
|
||||
def poster_hanger_price(width, market, reseller=None, rounded=True, inc_vat=True):
|
||||
"""calculates price for poster hanger only"""
|
||||
price = _price_for_poster_hanger_size(width)
|
||||
price += 50 # add 50 SEK extra since they are buying only the hanger
|
||||
price += 50 # add 50 SEK extra since they are buying only the hanger
|
||||
|
||||
price *= market.price_adjustments
|
||||
|
||||
if reseller:
|
||||
price *= (float(reseller.pricepremium) / 100) + 1
|
||||
|
||||
price += package_price('poster', width, 10, market) # we assume the poster hanger has a height of 10cm here
|
||||
price += package_price(
|
||||
"poster", width, 10, market
|
||||
) # we assume the poster hanger has a height of 10cm here
|
||||
|
||||
price *= market.exchange_rate
|
||||
|
||||
@@ -250,37 +293,64 @@ def _price_for_poster_hanger_size(size):
|
||||
if size > 125 and size <= 150:
|
||||
return 262
|
||||
|
||||
raise ValueError('Invalid poster hanger size: {}'.format(size))
|
||||
raise ValueError("Invalid poster hanger size: {}".format(size))
|
||||
|
||||
|
||||
def inquiry_price(inquiry, inc_price_retouch=True, rounded=True, inc_vat=True, **kwargs):
|
||||
width = kwargs.get('width', inquiry.width)
|
||||
height = kwargs.get('height', inquiry.height)
|
||||
material = kwargs.get('material', inquiry.material)
|
||||
framed = kwargs.get('framed', inquiry.framed)
|
||||
hanger = kwargs.get('hanger', inquiry.hanger)
|
||||
reseller = kwargs.get('reseller', inquiry.dealer_store)
|
||||
def inquiry_price(
|
||||
inquiry, inc_price_retouch=True, rounded=True, inc_vat=True, **kwargs
|
||||
):
|
||||
width = kwargs.get("width", inquiry.width)
|
||||
height = kwargs.get("height", inquiry.height)
|
||||
material = kwargs.get("material", inquiry.material)
|
||||
framed = kwargs.get("framed", inquiry.framed)
|
||||
hanger = kwargs.get("hanger", inquiry.hanger)
|
||||
reseller = kwargs.get("reseller", inquiry.dealer_store)
|
||||
|
||||
if inquiry.product_group == 'photo-wallpaper':
|
||||
price = wallpaper_price(width, height, material, inquiry.market,
|
||||
designer=inquiry.designer, reseller=reseller, inquiry=inquiry, rounded=False, inc_vat=False)
|
||||
elif inquiry.product_group == 'canvas':
|
||||
price = canvas_price(width, height, inquiry.market,
|
||||
designer=inquiry.designer, reseller=reseller, inquiry=inquiry, framed=framed, rounded=False, inc_vat=False)
|
||||
elif inquiry.product_group == 'poster':
|
||||
price = poster_price(width, height, inquiry.market,
|
||||
designer=inquiry.designer, reseller=reseller, inquiry=inquiry, hanger=hanger, rounded=False, inc_vat=False)
|
||||
if inquiry.product_group == "photo-wallpaper":
|
||||
price = wallpaper_price(
|
||||
width,
|
||||
height,
|
||||
material,
|
||||
inquiry.market,
|
||||
designer=inquiry.designer,
|
||||
reseller=reseller,
|
||||
inquiry=inquiry,
|
||||
rounded=False,
|
||||
inc_vat=False,
|
||||
)
|
||||
elif inquiry.product_group == "canvas":
|
||||
price = canvas_price(
|
||||
width,
|
||||
height,
|
||||
inquiry.market,
|
||||
designer=inquiry.designer,
|
||||
reseller=reseller,
|
||||
inquiry=inquiry,
|
||||
framed=framed,
|
||||
rounded=False,
|
||||
inc_vat=False,
|
||||
)
|
||||
elif inquiry.product_group == "poster":
|
||||
price = poster_price(
|
||||
width,
|
||||
height,
|
||||
inquiry.market,
|
||||
designer=inquiry.designer,
|
||||
reseller=reseller,
|
||||
inquiry=inquiry,
|
||||
hanger=hanger,
|
||||
rounded=False,
|
||||
inc_vat=False,
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
'Invalid product group: {}'.format(inquiry.product_group))
|
||||
raise ValueError("Invalid product group: {}".format(inquiry.product_group))
|
||||
|
||||
effect_price = inquiry.price_effect
|
||||
if effect_price:
|
||||
price += float(effect_price)
|
||||
|
||||
if inc_price_retouch:
|
||||
retouch_price = inquiry.local_price_retouch(
|
||||
rounded=False, inc_vat=False)
|
||||
retouch_price = inquiry.local_price_retouch(rounded=False, inc_vat=False)
|
||||
if retouch_price:
|
||||
price += retouch_price
|
||||
|
||||
|
||||
+7
-7
@@ -13,14 +13,14 @@ def slugify(text):
|
||||
text = text.lower()
|
||||
|
||||
# replace unwanted chars
|
||||
numbers = re.compile('(?<=\d),(?=\d)')
|
||||
text = numbers.sub('', text)
|
||||
unwanted_chars = re.compile(r'[^_a-z0-9/]+')
|
||||
text = unwanted_chars.sub('_', text)
|
||||
numbers = re.compile("(?<=\d),(?=\d)")
|
||||
text = numbers.sub("", text)
|
||||
unwanted_chars = re.compile(r"[^_a-z0-9/]+")
|
||||
text = unwanted_chars.sub("_", text)
|
||||
|
||||
# remove redundant _
|
||||
duplicated_underscores = re.compile('_{2,}')
|
||||
text = duplicated_underscores.sub('_', text)
|
||||
text = text.strip('_')
|
||||
duplicated_underscores = re.compile("_{2,}")
|
||||
text = duplicated_underscores.sub("_", text)
|
||||
text = text.strip("_")
|
||||
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user