|
3 | 3 | from sqlalchemy.orm.exc import NoResultFound
|
4 | 4 |
|
5 | 5 | from app.api.helpers.db import safe_query
|
6 |
| -from app.api.helpers.exceptions import ConflictException, ForbiddenException, UnprocessableEntity |
| 6 | +from app.api.helpers.exceptions import ConflictException, ForbiddenException, UnprocessableEntity, MethodNotAllowed |
7 | 7 | from app.api.helpers.permission_manager import has_access
|
8 | 8 | from app.api.helpers.permissions import jwt_required, current_identity
|
9 | 9 | from app.api.helpers.utilities import require_relationship
|
|
15 | 15 | from app.models.ticket import Ticket
|
16 | 16 | from app.models.user import User
|
17 | 17 |
|
| 18 | +from datetime import datetime |
| 19 | + |
18 | 20 | class DiscountCodeListPost(ResourceList):
|
19 | 21 | """
|
20 | 22 | Create Event and Ticket Discount code and Get Event Discount Codes
|
@@ -208,6 +210,13 @@ def before_get(self, args, kwargs):
|
208 | 210 | discount = db.session.query(DiscountCode).filter_by(code=kwargs.get('code'), deleted_at=None).first()
|
209 | 211 | if discount:
|
210 | 212 | kwargs['id'] = discount.id
|
| 213 | + discount_tz = discount.valid_from.tzinfo |
| 214 | + current_time = datetime.now().replace(tzinfo=discount_tz) |
| 215 | + if not discount.is_active: |
| 216 | + raise MethodNotAllowed({'parameter': '{code}'}, "Discount Code is not active") |
| 217 | + elif current_time < discount.valid_from or current_time > discount.valid_till: |
| 218 | + raise MethodNotAllowed({'parameter': '{code}'}, |
| 219 | + "Discount Code is not active in current time frame") |
211 | 220 | else:
|
212 | 221 | raise ObjectNotFound({'parameter': '{code}'}, "DiscountCode: not found")
|
213 | 222 |
|
|
0 commit comments