|  | 
| 20 | 20 | from app.api.helpers.exceptions import ConflictException, MethodNotAllowed, UnprocessableEntity | 
| 21 | 21 | from app.api.helpers.db import get_count | 
| 22 | 22 | 
 | 
|  | 23 | + | 
|  | 24 | +def validate_ticket_price(data): | 
|  | 25 | +    if data.get('type') != 'free' and int(data.get('price')) <= 0: | 
|  | 26 | +        raise UnprocessableEntity( | 
|  | 27 | +            {'price': data.get('price')}, "Price of a paid/donation ticket must be greater than zero") | 
|  | 28 | + | 
|  | 29 | + | 
| 23 | 30 | class TicketListPost(ResourceList): | 
| 24 | 31 |     """ | 
| 25 | 32 |     Create and List Tickets | 
| @@ -59,6 +66,10 @@ def before_create_object(self, data, view_kwargs): | 
| 59 | 66 |             if not event.is_payment_enabled(): | 
| 60 | 67 |                 raise UnprocessableEntity( | 
| 61 | 68 |                     {'event_id': data['event']}, "Event having paid ticket must have a payment method") | 
|  | 69 | +        if data.get('price') and data.get('type'): | 
|  | 70 | +            validate_ticket_price(data) | 
|  | 71 | +        else: | 
|  | 72 | +            raise UnprocessableEntity({}, "Type/price of ticket is missing")  | 
| 62 | 73 | 
 | 
| 63 | 74 |     schema = TicketSchema | 
| 64 | 75 |     methods = ['POST', ] | 
| @@ -182,6 +193,7 @@ def before_update_object(self, ticket, data, view_kwargs): | 
| 182 | 193 |                 raise UnprocessableEntity( | 
| 183 | 194 |                     {'event_id': ticket.event.id}, "Event having paid ticket must have a payment method") | 
| 184 | 195 | 
 | 
|  | 196 | +        validate_ticket_price(data) | 
| 185 | 197 |     decorators = (api.has_permission('is_coorganizer', fetch='event_id', | 
| 186 | 198 |                   fetch_as="event_id", model=Ticket, methods="PATCH,DELETE"),) | 
| 187 | 199 |     schema = TicketSchema | 
|  | 
0 commit comments