Fixed crash when loading a canceled order
This commit is contained in:
parent
5d00cdd7f4
commit
e67fd8ea1f
|
@ -22,9 +22,9 @@ async def export_csv(request, order: Order):
|
||||||
if r.status_code == 404: break
|
if r.status_code == 404: break
|
||||||
|
|
||||||
for r in r.json()['results']:
|
for r in r.json()['results']:
|
||||||
if r['status'] not in ['n', 'p']: continue
|
|
||||||
|
|
||||||
o = Order(r)
|
o = Order(r)
|
||||||
|
if o.status not in ['pending', 'paid']: continue
|
||||||
orders[o.code] = o
|
orders[o.code] = o
|
||||||
|
|
||||||
ret += (';'.join(map(lambda x: str(x),
|
ret += (';'.join(map(lambda x: str(x),
|
||||||
|
|
11
ext.py
11
ext.py
|
@ -14,6 +14,10 @@ class Order:
|
||||||
self.time = time()
|
self.time = time()
|
||||||
self.data = data
|
self.data = data
|
||||||
self.status = {'n': 'pending', 'p': 'paid', 'e': 'expired', 'c': 'canceled'}[self.data['status']]
|
self.status = {'n': 'pending', 'p': 'paid', 'e': 'expired', 'c': 'canceled'}[self.data['status']]
|
||||||
|
|
||||||
|
if not len(self.data['positions']):
|
||||||
|
self.status = 'canceled'
|
||||||
|
|
||||||
self.code = data['code']
|
self.code = data['code']
|
||||||
self.pending_update = False
|
self.pending_update = False
|
||||||
|
|
||||||
|
@ -181,7 +185,8 @@ class OrderManager:
|
||||||
|
|
||||||
data = res.json()
|
data = res.json()
|
||||||
for o in data['results']:
|
for o in data['results']:
|
||||||
if o['status'] in ['c', 'e']: continue
|
o = Order(o)
|
||||||
|
if o.status in ['canceled', 'expired']: continue
|
||||||
self.add_cache(Order(o))
|
self.add_cache(Order(o))
|
||||||
|
|
||||||
# If a cached order is needed, just get it if available
|
# If a cached order is needed, just get it if available
|
||||||
|
@ -207,11 +212,11 @@ class OrderManager:
|
||||||
|
|
||||||
res = res.json()
|
res = res.json()
|
||||||
|
|
||||||
if res['status'] in ['c', 'e']:
|
order = Order(res)
|
||||||
|
if order.status in ['canceled', 'expired']:
|
||||||
if request:
|
if request:
|
||||||
raise exceptions.Forbidden(f"Your order has been deleted. Contact support with your order identifier ({res['code']}) for further info.")
|
raise exceptions.Forbidden(f"Your order has been deleted. Contact support with your order identifier ({res['code']}) for further info.")
|
||||||
|
|
||||||
order = Order(res)
|
|
||||||
self.add_cache(order)
|
self.add_cache(order)
|
||||||
|
|
||||||
if request and secret != res['secret']:
|
if request and secret != res['secret']:
|
||||||
|
|
Loading…
Reference in New Issue