diff --git a/angular_app/event-edit.html b/angular_app/event-edit.html index 39b138c..344703a 100644 --- a/angular_app/event-edit.html +++ b/angular_app/event-edit.html @@ -25,15 +25,15 @@ -
+
{{'Title' | translate}}
-
+
{{'Tagline' | translate}}
-
+
{{'Short summary' | translate}}
@@ -74,25 +74,35 @@
-
+
{{'Where' | translate}}
-
+
{{'Group ID' | translate}}
+ +
+
+

{{'Ticket limits'}}

+
+
+
+ {{'Number of tickets' | translate}} + +
+
+
+ + +
+ +
- - - - -
- -
diff --git a/angular_app/events-list.html b/angular_app/events-list.html index 8bd246f..d3ce858 100644 --- a/angular_app/events-list.html +++ b/angular_app/events-list.html @@ -32,7 +32,8 @@ {{'Event' | translate}} {{'Attendees / Registered' | translate}} - {{'Actions' | translate}} + {{'Tickets' | translate}} + {{'Actions' | translate}} @@ -53,11 +54,14 @@
-

{{attendeesNr}} / {{((event.tickets || []) | registeredFilter).length}} ({{((attendeesNr / ((event.tickets || []) | registeredFilter).length * 100) || 0).toFixed()}}%)

+

{{attendeesNr}} / {{event.tickets_sold || 0}} ({{((attendeesNr / (event.tickets_sold || 0) * 100) || 0).toFixed()}}%)

+
{{event.number_of_tickets}} {{'tickets' | translate}}, {{event.number_of_tickets - (event.tickets_sold || 0)}} {{'still available' | translate}}
+ +
diff --git a/eventman_server.py b/eventman_server.py index 0c3cd8c..f5689d1 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -590,15 +590,17 @@ class EventsHandler(CollectionHandler): collection = 'events' def filter_get(self, output): - if not self.has_permission('tickets-all|read'): - if 'tickets' in output: + if 'tickets' in output: + output['tickets_sold'] = len([t for t in output['tickets'] if not t.get('cancelled')]) + if not self.has_permission('tickets-all|read'): output['tickets'] = [] return output def filter_get_all(self, output): - if not self.has_permission('tickets-all|read'): - for event in output.get('events') or []: - if 'tickets' in event: + for event in output.get('events') or []: + if 'tickets' in event: + event['tickets_sold'] = len([t for t in event['tickets'] if not t.get('cancelled')]) + if not self.has_permission('tickets-all|read'): event['tickets'] = [] return output @@ -660,6 +662,12 @@ class EventsHandler(CollectionHandler): return {'tickets': tickets} def handle_post_tickets(self, id_, resource_id, data): + event = self.db.query('events', {'_id': id_})[0] + if 'number_of_tickets' in event: + tickets = event.get('tickets') or [] + tickets = [t for t in tickets if not t.get('cancelled')] + if len(tickets) >= event['number_of_tickets']: + raise InputException('no more tickets available') uuid, arguments = self.uuid_arguments self._clean_dict(data) data['seq'] = self.get_next_seq('event_%s_tickets' % id_) @@ -702,8 +710,15 @@ class EventsHandler(CollectionHandler): current_event = current_event[0] else: current_event = {} - old_ticket_data = self._get_ticket_data(ticket_query, - current_event.get('tickets') or []) + tickets = current_event.get('tickets') or [] + old_ticket_data = self._get_ticket_data(ticket_query, tickets) + + # We updating the "cancelled" status of a ticket; check if we still have a ticket available + if 'number_of_tickets' in current_event and old_ticket_data.get('cancelled') and not data.get('cancelled'): + active_tickets = [t for t in tickets if not t.get('cancelled')] + if len(active_tickets) >= current_event['number_of_tickets']: + raise InputException('no more tickets available') + merged, doc = self.db.update('events', query, data, updateList='tickets', create=False) new_ticket_data = self._get_ticket_data(ticket_query,