Skip to content

Commit 9f47412

Browse files
kushthedudeiamareebjamal
authored andcommitted
fix: Move order_expiry_time into settings model (#6083)
1 parent 3ed0142 commit 9f47412

File tree

10 files changed

+55
-42
lines changed

10 files changed

+55
-42
lines changed

app/api/helpers/order.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from flask import render_template
55

6+
from app.settings import get_settings
67
from app.api.helpers import ticketing
78
from app.api.helpers.db import save_to_db, safe_query_without_soft_deleted_entries, get_count
89
from app.api.helpers.exceptions import UnprocessableEntity, ConflictException
@@ -37,9 +38,10 @@ def set_expiry_for_order(order, override=False):
3738
:param override: flag to force expiry.
3839
:return:
3940
"""
41+
order_expiry_time = get_settings()['order_expiry_time']
4042
if order and not order.paid_via and (override or (order.status == 'initializing' and (
4143
order.created_at +
42-
timedelta(minutes=order.event.order_expiry_time)) < datetime.now(timezone.utc))):
44+
timedelta(minutes=order_expiry_time)) < datetime.now(timezone.utc))):
4345
order.status = 'expired'
4446
delete_related_attendees_for_order(order)
4547
save_to_db(order)

app/api/schema/events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def validate_timezone(self, data, original_data):
125125
ical_url = fields.Url(dump_only=True)
126126
xcal_url = fields.Url(dump_only=True)
127127
average_rating = fields.Float(dump_only=True)
128-
order_expiry_time = fields.Integer(allow_none=True, default=10, validate=lambda n: 1 <= n <= 60)
129128
refund_policy = fields.String(dump_only=True,
130129
default='All sales are final. No refunds shall be issued in any case.')
131130
is_stripe_linked = fields.Boolean(dump_only=True, allow_none=True, default=False)

app/api/schema/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class Meta:
2727
# Tagline for the application. (Eg. Event Management and Ticketing, Home)
2828
tagline = fields.Str(allow_none=True)
2929

30+
# Order Expiry Time
31+
order_expiry_time = fields.Integer(allow_none=False, default=15, validate=lambda n: 1 <= n <= 60)
32+
3033
# Google Analytics
3134
analytics_key = fields.Str(allow_none=True)
3235

app/factories/event.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,5 @@ class Meta:
5050
event_topic_id = None
5151
event_sub_topic_id = None
5252
discount_code_id = None
53-
order_expiry_time = 10
5453
refund_policy = 'All sales are final. No refunds shall be issued in any case.'
5554
is_stripe_linked = False

app/factories/setting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Meta:
1919
secret = common.secret_
2020
# Static domain
2121
static_domain = common.url_
22+
# Order Expiry Time
23+
order_expiry_time = 15 #min
2224

2325
#
2426
# STORAGE

app/models/event.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class Event(SoftDeletionModel):
114114
xcal_url = db.Column(db.String)
115115
is_sponsors_enabled = db.Column(db.Boolean, default=False)
116116
refund_policy = db.Column(db.String, default='All sales are final. No refunds shall be issued in any case.')
117-
order_expiry_time = db.Column(db.Integer, default=10)
118117
is_stripe_linked = db.Column(db.Boolean, default=False)
119118
discount_code_id = db.Column(db.Integer, db.ForeignKey(
120119
'discount_codes.id', ondelete='CASCADE'))
@@ -231,7 +230,6 @@ def __init__(self,
231230
is_sponsors_enabled=None,
232231
stripe_authorization=None,
233232
tax=None,
234-
order_expiry_time=None,
235233
refund_policy='All sales are final. No refunds shall be issued in any case.',
236234
is_stripe_linked=False):
237235

@@ -298,7 +296,6 @@ def __init__(self,
298296
self.is_sponsors_enabled = is_sponsors_enabled
299297
self.stripe_authorization = stripe_authorization
300298
self.tax = tax
301-
self.order_expiry_time = order_expiry_time
302299
self.refund_policy = refund_policy
303300
self.is_stripe_linked = is_stripe_linked
304301

app/models/setting.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Setting(db.Model):
3030
secret = db.Column(db.String)
3131
# Static domain
3232
static_domain = db.Column(db.String)
33+
# Order Expiry Time in Minutes
34+
order_expiry_time = db.Column(db.Integer, default=15, nullable=False)
3335

3436
#
3537
# STORAGE
@@ -220,7 +222,8 @@ def __init__(self,
220222
admin_billing_address=None,
221223
admin_billing_city=None,
222224
admin_billing_zip=None,
223-
admin_billing_additional_info=None):
225+
admin_billing_additional_info=None,
226+
order_expiry_time=None):
224227
self.app_environment = app_environment
225228
self.aws_key = aws_key
226229
self.aws_secret = aws_secret
@@ -302,6 +305,9 @@ def __init__(self,
302305
self.admin_billing_zip = admin_billing_zip
303306
self.admin_billing_additional_info = admin_billing_additional_info
304307

308+
# Order Expiry Time in Minutes
309+
self.order_expiry_time = order_expiry_time
310+
305311
@hybrid_property
306312
def is_paypal_activated(self):
307313
if self.paypal_mode == 'sandbox' and self.paypal_sandbox_client and self.paypal_sandbox_secret:

0 commit comments

Comments
 (0)