From e109aebe1908e1fb1e1f27d610f6eaec82eef8b7 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 19 Jun 2024 18:36:45 -0400 Subject: [PATCH 1/3] black modified: lib/currency.py modified: models/invoice.py modified: models/market.py modified: models/shop_location.py modified: models/stripe_user_shop.py modified: models/user_address.py modified: models/user_product.py modified: models/user_shop.py modified: views/invoice.py --- make_post_sell/lib/currency.py | 1 + make_post_sell/models/invoice.py | 6 +++++- make_post_sell/models/market.py | 1 + make_post_sell/models/shop_location.py | 19 ++++++++++++++++--- make_post_sell/models/stripe_user_shop.py | 8 ++++---- make_post_sell/models/user_address.py | 4 ++-- make_post_sell/models/user_product.py | 3 ++- make_post_sell/models/user_shop.py | 5 +++-- make_post_sell/views/invoice.py | 6 ++++-- 9 files changed, 38 insertions(+), 15 deletions(-) diff --git a/make_post_sell/lib/currency.py b/make_post_sell/lib/currency.py index cf40aeb..2237237 100644 --- a/make_post_sell/lib/currency.py +++ b/make_post_sell/lib/currency.py @@ -1,5 +1,6 @@ def dollars_to_cents(dollars): return int(float(dollars) * 100) + def cents_to_dollars(cents): return int(cents) / 100.0 diff --git a/make_post_sell/models/invoice.py b/make_post_sell/models/invoice.py index 53e1407..b5fd661 100644 --- a/make_post_sell/models/invoice.py +++ b/make_post_sell/models/invoice.py @@ -225,7 +225,11 @@ class Invoice(RBase, Base): def human_created_timestamp(self): """Return the created timestamp in a human-readable format.""" from datetime import datetime - return datetime.fromtimestamp(self.created_timestamp / 1000).strftime('%Y-%m-%d %H:%M:%S') + + return datetime.fromtimestamp(self.created_timestamp / 1000).strftime( + "%Y-%m-%d %H:%M:%S" + ) + def get_invoice_by_id(dbsession, invoice_id): """Try to get Invoice object by id or return None.""" diff --git a/make_post_sell/models/market.py b/make_post_sell/models/market.py index 03278cd..72f6df7 100644 --- a/make_post_sell/models/market.py +++ b/make_post_sell/models/market.py @@ -7,5 +7,6 @@ from .meta import Base, RBase, UUIDType class Market(RBase, Base): """This class represents a Market place.""" + id = Column(UUIDType, primary_key=True, index=True) name = Column(Unicode(64), unique=True, nullable=False) diff --git a/make_post_sell/models/shop_location.py b/make_post_sell/models/shop_location.py index 2f4f209..67e1250 100644 --- a/make_post_sell/models/shop_location.py +++ b/make_post_sell/models/shop_location.py @@ -4,6 +4,7 @@ from .meta import Base, RBase, UUIDType, now_timestamp, foreign_key, get_object_ from sqlalchemy.orm import relationship from ..lib.currency import cents_to_dollars, dollars_to_cents + class ShopLocation(RBase, Base): """This class represents a physical location of a shop.""" @@ -47,7 +48,11 @@ class ShopLocation(RBase, Base): @property def local_delivery_rate(self): - return cents_to_dollars(self.local_delivery_rate_in_cents) if self.local_delivery_rate_in_cents else None + return ( + cents_to_dollars(self.local_delivery_rate_in_cents) + if self.local_delivery_rate_in_cents + else None + ) @local_delivery_rate.setter def local_delivery_rate(self, value): @@ -55,7 +60,11 @@ class ShopLocation(RBase, Base): @property def local_shipping_rate(self): - return cents_to_dollars(self.local_shipping_rate_in_cents) if self.local_shipping_rate_in_cents else None + return ( + cents_to_dollars(self.local_shipping_rate_in_cents) + if self.local_shipping_rate_in_cents + else None + ) @local_shipping_rate.setter def local_shipping_rate(self, value): @@ -63,7 +72,11 @@ class ShopLocation(RBase, Base): @property def international_shipping_rate(self): - return cents_to_dollars(self.international_shipping_rate_in_cents) if self.international_shipping_rate_in_cents else None + return ( + cents_to_dollars(self.international_shipping_rate_in_cents) + if self.international_shipping_rate_in_cents + else None + ) @international_shipping_rate.setter def international_shipping_rate(self, value): diff --git a/make_post_sell/models/stripe_user_shop.py b/make_post_sell/models/stripe_user_shop.py index b8fadbd..f9214ef 100644 --- a/make_post_sell/models/stripe_user_shop.py +++ b/make_post_sell/models/stripe_user_shop.py @@ -49,7 +49,9 @@ class StripeUserShop(RBase, Base): @property def stripe_cards(self): - return self.shop.stripe.Customer.list_payment_methods(self.stripe_customer, type="card")["data"] + return self.shop.stripe.Customer.list_payment_methods( + self.stripe_customer, type="card" + )["data"] @property def stripe_card_ids(self): @@ -75,6 +77,4 @@ def get_all_stripe_customer_objects(dbsession): Return all Stripe customer objects. created timestamp (newest first). """ - return [ - i.stripe_customer for i in dbsession.query(StripeUserShop).all() - ] + return [i.stripe_customer for i in dbsession.query(StripeUserShop).all()] diff --git a/make_post_sell/models/user_address.py b/make_post_sell/models/user_address.py index 7a21ce0..6456706 100644 --- a/make_post_sell/models/user_address.py +++ b/make_post_sell/models/user_address.py @@ -12,13 +12,13 @@ class UserAddress(RBase, Base): id = Column(UUIDType, primary_key=True, index=True) user_id = Column(UUIDType, foreign_key("User", "id"), nullable=True) - #shop_id = Column(UUIDType, foreign_key("Shop", "id"), nullable=True) + # shop_id = Column(UUIDType, foreign_key("Shop", "id"), nullable=True) data = Column(UnicodeText) created_timestamp = Column(BigInteger, nullable=False) user = relationship(argument="User", uselist=False, lazy="joined") - #shop = relationship(argument="Shop", uselist=False, lazy="joined") + # shop = relationship(argument="Shop", uselist=False, lazy="joined") def __init__(self, data): self.created_timestamp = now_timestamp() diff --git a/make_post_sell/models/user_product.py b/make_post_sell/models/user_product.py index 3389fde..8b40903 100644 --- a/make_post_sell/models/user_product.py +++ b/make_post_sell/models/user_product.py @@ -19,7 +19,8 @@ class UserProduct(RBase, Base): created_timestamp = Column(BigInteger, nullable=False) user = relationship( - argument="User", backref=backref("user_products", cascade="all, delete-orphan"), + argument="User", + backref=backref("user_products", cascade="all, delete-orphan"), ) product = relationship( diff --git a/make_post_sell/models/user_shop.py b/make_post_sell/models/user_shop.py index 9df1f67..75aca5c 100644 --- a/make_post_sell/models/user_shop.py +++ b/make_post_sell/models/user_shop.py @@ -8,10 +8,11 @@ from sqlalchemy.orm import relationship, backref role_id_to_name = { 0: "owner", # root. - 1: "editor", # virtual assistant. - 2: "member", # viewer. + 1: "editor", # virtual assistant. + 2: "member", # viewer. } + class UserShop(RBase, Base): """ Many shops to many users. diff --git a/make_post_sell/views/invoice.py b/make_post_sell/views/invoice.py index 7b5f41c..d061838 100644 --- a/make_post_sell/views/invoice.py +++ b/make_post_sell/views/invoice.py @@ -7,6 +7,7 @@ from . import ( get_referer_or_home, ) + @view_config(route_name="view_invoice", renderer="invoice.j2") @user_required() def view_invoice(request): @@ -19,11 +20,12 @@ def view_invoice(request): # Check if the user is the owner of the invoice or a shop editor if request.user != invoice.user and not request.user.can_edit_shop(invoice.shop): - request.session.flash(("You do not have permission to view this invoice.", "error")) + request.session.flash( + ("You do not have permission to view this invoice.", "error") + ) return HTTPFound(get_referer_or_home(request)) return { "invoice": invoice, "line_items": invoice.line_items.all(), } - From ce7d23104c931da9f517f2a96b2c8fdc0cef47b1 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 19 Jun 2024 19:05:01 -0400 Subject: [PATCH 2/3] changes per @coderabbit modified: models/invoice.py modified: models/market.py modified: models/stripe_user_shop.py modified: models/user_product.py --- make_post_sell/models/invoice.py | 2 +- make_post_sell/models/market.py | 2 -- make_post_sell/models/stripe_user_shop.py | 9 ++++----- make_post_sell/models/user_product.py | 2 +- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/make_post_sell/models/invoice.py b/make_post_sell/models/invoice.py index b5fd661..46b5957 100644 --- a/make_post_sell/models/invoice.py +++ b/make_post_sell/models/invoice.py @@ -4,7 +4,7 @@ from sqlalchemy import Column, BigInteger, Boolean, Integer, UnicodeText, Unicod from .meta import Base, RBase, UUIDType, foreign_key, now_timestamp, get_object_by_id -from sqlalchemy.orm import relationship, backref +from sqlalchemy.orm import relationship from .coupon_redemption import CouponRedemption diff --git a/make_post_sell/models/market.py b/make_post_sell/models/market.py index 72f6df7..785b22d 100644 --- a/make_post_sell/models/market.py +++ b/make_post_sell/models/market.py @@ -1,5 +1,3 @@ -import uuid - from sqlalchemy import Column, Unicode from .meta import Base, RBase, UUIDType diff --git a/make_post_sell/models/stripe_user_shop.py b/make_post_sell/models/stripe_user_shop.py index f9214ef..094f208 100644 --- a/make_post_sell/models/stripe_user_shop.py +++ b/make_post_sell/models/stripe_user_shop.py @@ -40,11 +40,10 @@ class StripeUserShop(RBase, Base): @property def stripe_customer_default_source(self): - if self.stripe_customer: - if self.stripe_customer.default_source: - return self.stripe_customer.sources.retrieve( - self.stripe_customer.default_source - ) + if self.stripe_customer and self.stripe_customer.default_source: + return self.stripe_customer.sources.retrieve( + self.stripe_customer.default_source + ) return None @property diff --git a/make_post_sell/models/user_product.py b/make_post_sell/models/user_product.py index 8b40903..d4dbdc5 100644 --- a/make_post_sell/models/user_product.py +++ b/make_post_sell/models/user_product.py @@ -1,6 +1,6 @@ import uuid -from sqlalchemy import Column, Boolean, BigInteger +from sqlalchemy import Column, BigInteger from .meta import Base, RBase, UUIDType, foreign_key, now_timestamp From 573552f5cab7a20f60536a7d1378c3231f376949 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 19 Jun 2024 19:13:01 -0400 Subject: [PATCH 3/3] modified: models/user_address.py --- make_post_sell/models/user_address.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/make_post_sell/models/user_address.py b/make_post_sell/models/user_address.py index 6456706..ca94a73 100644 --- a/make_post_sell/models/user_address.py +++ b/make_post_sell/models/user_address.py @@ -12,13 +12,11 @@ class UserAddress(RBase, Base): id = Column(UUIDType, primary_key=True, index=True) user_id = Column(UUIDType, foreign_key("User", "id"), nullable=True) - # shop_id = Column(UUIDType, foreign_key("Shop", "id"), nullable=True) data = Column(UnicodeText) created_timestamp = Column(BigInteger, nullable=False) user = relationship(argument="User", uselist=False, lazy="joined") - # shop = relationship(argument="Shop", uselist=False, lazy="joined") def __init__(self, data): self.created_timestamp = now_timestamp()