Skip to content

Commit

Permalink
chore: Change / Deactivate some logging some loggings (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
sveneberth authored Jan 23, 2025
1 parent ebbf8ef commit a61ca57
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/viur/shop/modules/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(
shop: "Shop" = None,
*args, **kwargs
):
logger.debug(f"{self.__class__.__name__}<ShopModuleAbstract>.__init__()")
# logger.debug(f"{self.__class__.__name__}<ShopModuleAbstract>.__init__()")
if shop is None:
raise ValueError("Missing shop argument!")
if moduleName is None:
Expand Down
4 changes: 1 addition & 3 deletions src/viur/shop/modules/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def baseSkel(
def canView(self, skelType: SkelType, skel: SkeletonInstance) -> bool:
if super().canView(skelType, skel):
return True
logger.debug(f"{skel=}")
if skelType == "leaf":
nearest_node_key = skel["parententry"]
else:
Expand Down Expand Up @@ -115,7 +114,6 @@ def get_available_root_nodes(self, *args, **kwargs) -> list[dict[t.Literal["name

if user := current.user.get():
for wishlist in user["wishlist"]:
logger.debug(f"{wishlist = }")
root_nodes.append({
"key": wishlist["key"],
"name": wishlist["name"],
Expand Down Expand Up @@ -282,7 +280,7 @@ def add_or_update_article(
if not article_skel.fromDB(article_key):
raise errors.NotFound(f"Article with key {article_key=} does not exist!")
if not article_skel["shop_listed"]:
logger.debug(f"not listed: {article_skel=}")
# logger.debug(f"not listed: {article_skel=}")
raise errors.UnprocessableEntity(f"Article is not listed for the shop!")
# Copy values from the article
for bone in skel.keys():
Expand Down
2 changes: 1 addition & 1 deletion src/viur/shop/modules/discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def remove(
.fetch(100)
)

logger.debug(f"<{len(node_skels)}>{node_skels=}")
# logger.debug(f"<{len(node_skels)}>{node_skels=}")
for node_skel in node_skels:
# TODO: remove node, if no custom name, shipping, etc. is set? remove_parent flag?
self.shop.cart.cart_update(
Expand Down
10 changes: 5 additions & 5 deletions src/viur/shop/modules/discount_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ def onEdited(self, skel: SkeletonInstance):
self.on_changed(skel, "edited")

def on_change(self, skel, event: str):
logger.debug(pprint.pformat(skel, width=120))
# logger.debug(pprint.pformat(skel, width=120))
skel_old = self.viewSkel()
if skel["key"] is not None: # not on add
skel_old.fromDB(skel["key"])
current.request_data.get()[f'shop_skel_{skel["key"]}'] = skel_old

def on_changed(self, skel, event: str):
logger.debug(pprint.pformat(skel, width=120))
# logger.debug(pprint.pformat(skel, width=120))
if skel["code_type"] == CodeType.INDIVIDUAL and not skel["is_subcode"]:
skel_old = current.request_data.get()[f'shop_skel_{skel["key"]}']
query = self.viewSkel().all().filter("parent_code.dest.__key__ =", skel["key"])
counter = query.count()
logger.debug(f"{counter = }")
# logger.debug(f"{counter = }")
if skel["individual_codes_amount"] > counter:
self.generate_subcodes(skel["key"], skel["individual_codes_prefix"],
skel["individual_codes_amount"] - counter)
Expand Down Expand Up @@ -185,7 +185,7 @@ def get_discounts_from_cart(self, cart_key: db.Key) -> list[db.Key]:
nodes = self.shop.cart.viewSkel("node").all().filter("parentrepo =", cart_key).fetch(100)
discounts = []
for node in nodes:
logger.debug(f"{node = }")
# logger.debug(f"{node = }")
if node["discount"]:
discounts.append(node["discount"]["dest"]["key"])
# TODO: collect used from price and automatically as well
Expand All @@ -198,7 +198,7 @@ def mark_discount_used(order_skel, payment):
logger.info(f"Calling mark_discount_used with {order_skel=} {payment=}")
self = SHOP_INSTANCE.get().discount_condition
discounts = self.get_discounts_from_cart(order_skel["cart"]["dest"]["key"])
logger.debug(f"{discounts = }")
# logger.debug(f"{discounts = }")

for discount in discounts:
d_skel = self.shop.discount.viewSkel()
Expand Down
16 changes: 8 additions & 8 deletions src/viur/shop/modules/shipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ def choose_shipping_skel_for_article(
return None

shipping_config_skel = article_skel["shop_shipping_config"]["dest"]
logger.debug(f"{shipping_config_skel=}")
# logger.debug(f"{shipping_config_skel=}")

applicable_shippings = []
for shipping in shipping_config_skel["shipping"]:
is_applicable, reason = self.shop.shipping_config.is_applicable(
shipping["dest"], shipping["rel"], article_skel=article_skel,
country=country)
logger.debug(f"{shipping=} --> {is_applicable=} | {reason=}")
# logger.debug(f"{shipping=} --> {is_applicable=} | {reason=}")
if is_applicable:
applicable_shippings.append(shipping)

logger.debug(f"<{len(applicable_shippings)}>{applicable_shippings=}")
# logger.debug(f"<{len(applicable_shippings)}>{applicable_shippings=}")
if not applicable_shippings:
logger.error("No suitable shipping found") # TODO: fallback??
return False

cheapest_shipping = min(applicable_shippings, key=lambda shipping: shipping["dest"]["shipping_cost"] or 0)
logger.debug(f"{cheapest_shipping=}")
# logger.debug(f"{cheapest_shipping=}")
return cheapest_shipping

def get_shipping_skels_for_cart(
Expand Down Expand Up @@ -91,10 +91,10 @@ def get_shipping_skels_for_cart(
elif child.article_skel["shop_shipping_config"] is not None:
all_shipping_configs.append(child.article_skel["shop_shipping_config"]["dest"])

logger.debug(f"(before de-duplication) <{len(all_shipping_configs)}>{all_shipping_configs=}")
# logger.debug(f"(before de-duplication) <{len(all_shipping_configs)}>{all_shipping_configs=}")
# eliminate duplicates
all_shipping_configs = list(({sc["key"]: sc for sc in all_shipping_configs}).values())
logger.debug(f"(after de-duplication) <{len(all_shipping_configs)}>{all_shipping_configs=}")
# logger.debug(f"(after de-duplication) <{len(all_shipping_configs)}>{all_shipping_configs=}")

if not all_shipping_configs:
logger.debug(f'{cart_key=!r}\'s articles have no shop_shipping_config set.') # TODO: fallback??
Expand All @@ -110,11 +110,11 @@ def get_shipping_skels_for_cart(
is_applicable, reason = self.shop.shipping_config.is_applicable(
shipping["dest"], shipping["rel"], cart_skel=cart_skel,
country=country)
logger.debug(f"{shipping=} --> {is_applicable=} | {reason=}")
# logger.debug(f"{shipping=} --> {is_applicable=} | {reason=}")
if is_applicable:
applicable_shippings.append(shipping)

logger.debug(f"<{len(applicable_shippings)}>{applicable_shippings=}")
# logger.debug(f"<{len(applicable_shippings)}>{applicable_shippings=}")
if not applicable_shippings:
logger.error("No suitable shipping found") # TODO: fallback??
return []
Expand Down
2 changes: 1 addition & 1 deletion src/viur/shop/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
self._add_translations()

def __call__(self, *args, **kwargs) -> t.Self:
logger.debug(f"Shop.__call__({args=}, {kwargs=})")
# logger.debug(f"Shop.__call__({args=}, {kwargs=})")
self: Shop = super().__call__(*args, **kwargs) # noqa
is_default_renderer = self.modulePath == f"/{self.moduleName}"

Expand Down
2 changes: 1 addition & 1 deletion src/viur/shop/skeletons/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def shop_price_(self) -> Price:

@classmethod
def setSystemInitialized(cls):
logger.debug(f"Call setSystemInitialized({cls=})")
# logger.debug(f"Call setSystemInitialized({cls=})")
# Check if all abstract methods are implemented
for name in dir(cls):
value = getattr(cls, name, None)
Expand Down
2 changes: 1 addition & 1 deletion src/viur/shop/skeletons/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_vat_for_node(skel: "CartNodeSkel", bone: RecordBone) -> list[dict]:
# logger.debug(f"{child=}")
if issubclass(child.skeletonCls, CartNodeSkel):
for entry in child["vat"] or []:
logger.debug(f'{child["shop_vat_rate_category"]} | {entry=}')
# logger.debug(f'{child["shop_vat_rate_category"]} | {entry=}')
cat2value[entry["category"]] += entry["value"]
cat2rate[entry["category"]] = entry["percentage"]
elif issubclass(child.skeletonCls, CartItemSkel):
Expand Down
2 changes: 1 addition & 1 deletion src/viur/shop/types/dc_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,5 @@ def __call__(self) -> bool:
.filter("article.dest.__key__ =", self.condition_skel["scope_article"]["dest"]["key"])
.fetch()
)
logger.debug(f"<{len(leaf_skels)}>{leaf_skels = }")
# logger.debug(f"<{len(leaf_skels)}>{leaf_skels = }")
return len(leaf_skels) > 0
2 changes: 1 addition & 1 deletion src/viur/shop/types/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def shop_current_discount(self, article_skel: SkeletonInstance) -> None | tuple[
applicable, dv = discount_module.can_apply(skel, article_skel=article_skel, as_automatically=True)
# logger.debug(f"{dv=}")
if not applicable:
logger.debug(f"{skel} is NOT applicable")
logger.debug(f'{skel["name"]} is NOT applicable')
continue
price = self.apply_discount(skel, article_price)
if best_discount is None or price < best_discount[0]:
Expand Down

0 comments on commit a61ca57

Please sign in to comment.