coupons max date ten years in future.
This commit is contained in:
parent
09dd9afa12
commit
49571ffb66
2 changed files with 19 additions and 2 deletions
|
|
@ -136,7 +136,7 @@ class AuthenticatedFunctionalTests(FunctionalTests):
|
|||
"max_redemptions": "100",
|
||||
"cart_qualifier": "10",
|
||||
"max_redemptions_per_user": "1",
|
||||
"expiration_date": "2040-10-31",
|
||||
"expiration_date": "2030-10-31",
|
||||
}
|
||||
|
||||
# create test user1 and user2.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@ from ..models.cart import get_cart_by_id
|
|||
|
||||
from pyramid.httpexceptions import HTTPFound
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
# Define the maximum expiration date (10 years from now)
|
||||
MAX_EXPIRATION_DATE = datetime.now() + timedelta(days=365 * 10)
|
||||
|
||||
|
||||
def get_coupon_from_matchdict(request):
|
||||
"""
|
||||
|
|
@ -50,7 +56,7 @@ def coupon_new(request):
|
|||
cart_qualifier = request.params.get("cart_qualifier")
|
||||
|
||||
if request.params:
|
||||
# Convert numeric fields to integers for validation
|
||||
# Convert numeric fields to float or integers for validation.
|
||||
try:
|
||||
action_value = float(action_value) if action_value else None
|
||||
max_redemptions = int(max_redemptions) if max_redemptions else None
|
||||
|
|
@ -62,6 +68,17 @@ def coupon_new(request):
|
|||
request.session.flash(("Invalid input for numeric fields.", "error"))
|
||||
return request.params
|
||||
|
||||
if expiration_date:
|
||||
expiration_datetime = datetime.strptime(expiration_date, "%Y-%m-%d")
|
||||
if expiration_datetime > MAX_EXPIRATION_DATE:
|
||||
request.session.flash(
|
||||
(
|
||||
f"Expiration date is too far in the future. The maximum allowed date is {{ MAX_EXPIRATION_DATE.strftime('%Y-%m-%d') }}.",
|
||||
"error",
|
||||
)
|
||||
)
|
||||
return request.params
|
||||
|
||||
# check for required fields.
|
||||
if not code or not description or not action_type or not action_value:
|
||||
request.session.flash(("Please submit all required fields.", "error"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue