Fixed cache issue, added carpool support to orders

This commit is contained in:
Ed 2023-05-08 22:22:07 +02:00
parent 75fd737baa
commit 4295ff39e0
1 changed files with 8 additions and 4 deletions

12
ext.py
View File

@ -65,6 +65,7 @@ class Order:
self.is_fursuiter = True if self.ans('is_fursuiter') != 'No' else False self.is_fursuiter = True if self.ans('is_fursuiter') != 'No' else False
self.is_allergic = True if self.ans('is_allergic') != 'No' else False self.is_allergic = True if self.ans('is_allergic') != 'No' else False
self.propic_locked = self.ans('propic_locked') self.propic_locked = self.ans('propic_locked')
self.carpooling_message = json.loads(self.ans('carpooling_message')) if self.ans('carpooling_message') else {}
self.birth_date = self.ans('birth_date') self.birth_date = self.ans('birth_date')
self.name = self.ans('fursona_name') self.name = self.ans('fursona_name')
self.room_id = self.ans('room_id') self.room_id = self.ans('room_id')
@ -186,8 +187,10 @@ class OrderManager:
data = res.json() data = res.json()
for o in data['results']: for o in data['results']:
o = Order(o) o = Order(o)
if o.status in ['canceled', 'expired']: continue if o.status in ['canceled', 'expired']:
self.add_cache(Order(o)) self.remove_cache(order)
else:
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
if code and cached and code in self.cache and time()-self.cache[code].time < 3600: if code and cached and code in self.cache and time()-self.cache[code].time < 3600:
@ -214,10 +217,11 @@ class OrderManager:
order = Order(res) order = Order(res)
if order.status in ['canceled', 'expired']: if order.status in ['canceled', 'expired']:
self.remove_cache(order)
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.")
else:
self.add_cache(order) self.add_cache(order)
if request and secret != res['secret']: if request and secret != res['secret']:
raise exceptions.Forbidden("Your session has expired due to a token change. Please check your E-Mail for an updated link!") raise exceptions.Forbidden("Your session has expired due to a token change. Please check your E-Mail for an updated link!")