Skip to content

Commit

Permalink
Additional fixes for SQLAlchemy 2.0 (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
jace authored Feb 8, 2023
1 parent 82c2ca0 commit def3797
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 76 deletions.
2 changes: 1 addition & 1 deletion boxoffice/forms/discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def set_queries(self):
self.item.query = (
Item.query.join(ItemCollection)
.filter(ItemCollection.organization == self.edit_parent.organization)
.options(db.load_only('id', 'title'))
.options(db.load_only(ItemCollection.id, ItemCollection.title))
)


Expand Down
2 changes: 1 addition & 1 deletion boxoffice/forms/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def set_queries(self):
self.category.query = (
Category.query.join(ItemCollection)
.filter(Category.item_collection == self.edit_parent)
.options(db.load_only('id', 'title'))
.options(db.load_only(Category.id, Category.title))
)

def validate_place_supply_state_code(self, field):
Expand Down
2 changes: 1 addition & 1 deletion boxoffice/models/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Category(BaseScopedNameMixin, db.Model):
}

def roles_for(self, actor=None, anchors=()):
roles = super(Category, self).roles_for(actor, anchors)
roles = super().roles_for(actor, anchors)
if self.item_collection.organization.userid in actor.organizations_owned_ids():
roles.add('category_owner')
return roles
6 changes: 3 additions & 3 deletions boxoffice/models/discount_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ class DiscountPolicy(BaseScopedNameMixin, db.Model):
}

def roles_for(self, actor=None, anchors=()):
roles = super(DiscountPolicy, self).roles_for(actor, anchors)
roles = super().roles_for(actor, anchors)
if self.organization.userid in actor.organizations_owned_ids():
roles.add('dp_owner')
return roles

def __init__(self, *args, **kwargs):
self.secret = kwargs.get('secret') if kwargs.get('secret') else buid()
super(DiscountPolicy, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

@cached_property
def is_automatic(self):
Expand Down Expand Up @@ -283,7 +283,7 @@ class DiscountCoupon(IdMixin, db.Model):

def __init__(self, *args, **kwargs):
self.id = uuid1mc()
super(DiscountCoupon, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

code = db.Column(db.Unicode(100), nullable=False, default=generate_coupon_code)
usage_limit = db.Column(db.Integer, nullable=False, default=1)
Expand Down
44 changes: 21 additions & 23 deletions boxoffice/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Invoice(UuidMixin, BaseMixin, db.Model):
}

def roles_for(self, actor=None, anchors=()):
roles = super(Invoice, self).roles_for(actor, anchors)
roles = super().roles_for(actor, anchors)
if self.organization.userid in actor.organizations_owned_ids():
roles.add('invoicer')
return roles
Expand All @@ -113,7 +113,7 @@ def __init__(self, *args, **kwargs):
country_code, self.invoiced_at
)
self.invoice_no = gen_invoice_no(organization, country_code, self.invoiced_at)
super(Invoice, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

@property
def is_final(self):
Expand Down Expand Up @@ -166,31 +166,29 @@ def fetch_invoices(self):
"postcode",
"invoiced_at",
]
invoices_join = db.join(Invoice).join(Order)
invoices_query = (
db.select(
[
Order.id,
Order.invoice_no,
Invoice.invoice_no,
Invoice.status,
Invoice.buyer_taxid,
Invoice.seller_taxid,
Invoice.invoicee_name,
Invoice.invoicee_company,
Invoice.invoicee_email,
Invoice.street_address_1,
Invoice.street_address_2,
Invoice.city,
Invoice.state,
Invoice.state_code,
Invoice.country_code,
Invoice.postcode,
Invoice.invoiced_at,
]
Order.id,
Order.invoice_no,
Invoice.invoice_no,
Invoice.status,
Invoice.buyer_taxid,
Invoice.seller_taxid,
Invoice.invoicee_name,
Invoice.invoicee_company,
Invoice.invoicee_email,
Invoice.street_address_1,
Invoice.street_address_2,
Invoice.city,
Invoice.state,
Invoice.state_code,
Invoice.country_code,
Invoice.postcode,
Invoice.invoiced_at,
)
.where(Invoice.organization == self)
.select_from(invoices_join)
.select_from(Invoice)
.join(Order)
.order_by(Invoice.invoice_no)
)
return HeadersAndDataTuple(headers, db.session.execute(invoices_query).fetchall())
Expand Down
2 changes: 1 addition & 1 deletion boxoffice/models/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Item(BaseScopedNameMixin, db.Model):
}

def roles_for(self, actor=None, anchors=()):
roles = super(Item, self).roles_for(actor, anchors)
roles = super().roles_for(actor, anchors)
if self.item_collection.organization.userid in actor.organizations_owned_ids():
roles.add('item_owner')
return roles
Expand Down
76 changes: 36 additions & 40 deletions boxoffice/models/item_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ItemCollection(BaseScopedNameMixin, db.Model):
__roles__ = {'ic_owner': {'read': {'id', 'name', 'title', 'description'}}}

def roles_for(self, actor=None, anchors=()):
roles = super(ItemCollection, self).roles_for(actor, anchors)
roles = super().roles_for(actor, anchors)
if self.organization.userid in actor.organizations_owned_ids():
roles.add('ic_owner')
return roles
Expand Down Expand Up @@ -61,35 +61,33 @@ def fetch_all_details(self):

line_item_query = (
db.select(
[
LineItem.id,
LineItem.customer_order_id,
Order.invoice_no,
Item.title,
LineItem.base_amount,
LineItem.discounted_amount,
LineItem.final_amount,
DiscountPolicy.title,
DiscountCoupon.code,
Order.buyer_fullname,
Order.buyer_email,
Order.buyer_phone,
Assignee.fullname,
Assignee.email,
Assignee.phone,
Order.access_token,
Assignee.details,
OrderSession.utm_campaign,
OrderSession.utm_source,
OrderSession.utm_medium,
OrderSession.utm_term,
OrderSession.utm_content,
OrderSession.utm_id,
OrderSession.gclid,
OrderSession.referrer,
OrderSession.host,
Order.paid_at,
]
LineItem.id,
LineItem.customer_order_id,
Order.invoice_no,
Item.title,
LineItem.base_amount,
LineItem.discounted_amount,
LineItem.final_amount,
DiscountPolicy.title,
DiscountCoupon.code,
Order.buyer_fullname,
Order.buyer_email,
Order.buyer_phone,
Assignee.fullname,
Assignee.email,
Assignee.phone,
Order.access_token,
Assignee.details,
OrderSession.utm_campaign,
OrderSession.utm_source,
OrderSession.utm_medium,
OrderSession.utm_term,
OrderSession.utm_content,
OrderSession.utm_id,
OrderSession.gclid,
OrderSession.referrer,
OrderSession.host,
Order.paid_at,
)
.select_from(line_item_join)
.where(LineItem.status == LINE_ITEM_STATUS.CONFIRMED)
Expand Down Expand Up @@ -151,16 +149,14 @@ def fetch_assignee_details(self):
)
line_item_query = (
db.select(
[
Order.invoice_no,
LineItem.line_item_seq,
LineItem.id,
Item.title,
Assignee.fullname,
Assignee.email,
Assignee.phone,
Assignee.details,
]
Order.invoice_no,
LineItem.line_item_seq,
LineItem.id,
Item.title,
Assignee.fullname,
Assignee.email,
Assignee.phone,
Assignee.details,
)
.select_from(line_item_join)
.where(LineItem.status == LINE_ITEM_STATUS.CONFIRMED)
Expand Down
2 changes: 1 addition & 1 deletion boxoffice/models/line_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class LineItem(BaseMixin, db.Model):
cancelled_at = db.Column(db.TIMESTAMP(timezone=True), nullable=True)

def permissions(self, user, inherited=None):
perms = super(LineItem, self).permissions(user, inherited)
perms = super().permissions(user, inherited)
if self.order.organization.userid in user.organizations_owned_ids():
perms.add('org_admin')
return perms
Expand Down
2 changes: 1 addition & 1 deletion boxoffice/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Order(BaseMixin, db.Model):
# confirmed_line_items, initial_line_items, confirmed_and_cancelled_line_items

def permissions(self, user, inherited=None):
perms = super(Order, self).permissions(user, inherited)
perms = super().permissions(user, inherited)
if self.organization.userid in user.organizations_owned_ids():
perms.add('org_admin')
return perms
Expand Down
2 changes: 1 addition & 1 deletion boxoffice/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Organization(ProfileBase, db.Model):
)

def permissions(self, user, inherited=None):
perms = super(Organization, self).permissions(user, inherited)
perms = super().permissions(user, inherited)
if self.userid in user.organizations_owned_ids():
perms.add('org_admin')
return perms
Expand Down
2 changes: 1 addition & 1 deletion boxoffice/views/custom_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PaymentGatewayError(Exception):
def __init__(self, message, status_code, response_message):
super(PaymentGatewayError, self).__init__()
super().__init__()
self.message = message
self.status_code = status_code
self.response_message = response_message
Expand Down
2 changes: 1 addition & 1 deletion boxoffice/views/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def get_coupon_codes_from_line_items(line_items):
if coupon_ids:
coupons = (
DiscountCoupon.query.filter(DiscountCoupon.id.in_(coupon_ids))
.options(db.load_only('code'))
.options(db.load_only(DiscountCoupon.code))
.all()
)
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore = I100, I201, E501, E124, E128, E203, E402, W503, D100, D101, D102, D103, D104, D107, S101
ignore = I100, I201, E501, E124, E128, E203, E402, W503, D100, D101, D102, D103, D104, D107, D202, S101
max-line-length = 88
exclude = boxoffice/assets/node_modules
enable-extensions = G
Expand Down

0 comments on commit def3797

Please sign in to comment.