|  | 
| 21 | 21 | from app.api.helpers.db import get_count | 
| 22 | 22 | 
 | 
| 23 | 23 | 
 | 
| 24 |  | -def validate_ticket_price(ticket_type, price): | 
| 25 |  | -    if ticket_type != 'free' and int(price) <= 0: | 
|  | 24 | +def validate_ticket_price(data): | 
|  | 25 | +    if not data.get('price') and data.get('type'): | 
|  | 26 | +        raise UnprocessableEntity({}, "Type/price of ticket is missing") | 
|  | 27 | +    if data.get('type') != 'free' and int(data.get('price')) <= 0: | 
| 26 | 28 |         raise UnprocessableEntity( | 
| 27 |  | -            {'price': price}, "Price of a paid/donation ticket must be greater than zero") | 
|  | 29 | +            {'price': data.get('price')}, "Price of a paid/donation ticket must be greater than zero") | 
| 28 | 30 | 
 | 
| 29 | 31 | 
 | 
| 30 | 32 | class TicketListPost(ResourceList): | 
| @@ -66,7 +68,7 @@ def before_create_object(self, data, view_kwargs): | 
| 66 | 68 |             if not event.is_payment_enabled(): | 
| 67 | 69 |                 raise UnprocessableEntity( | 
| 68 | 70 |                     {'event_id': data['event']}, "Event having paid ticket must have a payment method") | 
| 69 |  | -        validate_ticket_price(data.get('type'), data.get('price')) | 
|  | 71 | +        validate_ticket_price(data) | 
| 70 | 72 | 
 | 
| 71 | 73 |     schema = TicketSchema | 
| 72 | 74 |     methods = ['POST', ] | 
| @@ -189,8 +191,7 @@ def before_update_object(self, ticket, data, view_kwargs): | 
| 189 | 191 |             if not event.is_payment_enabled(): | 
| 190 | 192 |                 raise UnprocessableEntity( | 
| 191 | 193 |                     {'event_id': ticket.event.id}, "Event having paid ticket must have a payment method") | 
| 192 |  | -        if data.get('price') and data.get('type'): | 
| 193 |  | -            validate_ticket_price(data.get('type'), data.get('price')) | 
|  | 194 | +        validate_ticket_price(data) | 
| 194 | 195 | 
 | 
| 195 | 196 |     decorators = (api.has_permission('is_coorganizer', fetch='event_id', | 
| 196 | 197 |                   fetch_as="event_id", model=Ticket, methods="PATCH,DELETE"),) | 
|  | 
0 commit comments