From 82cdbf67383018bedd824e66fa21726282ab67f7 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sun, 10 Jul 2016 17:25:16 +0200 Subject: [PATCH] fixes #142: trigger for created and deleted tickets --- .gitignore | 1 - data/triggers/attends.d/README.md | 5 +++ .../create_ticket_in_event.d/README.md | 5 +++ .../delete_ticket_in_event.d/README.md | 5 +++ .../update_ticket_in_event.d/README.md | 5 +++ docs/DEVELOPMENT.md | 43 ++++++++++++++++++- eventman_server.py | 24 ++++++++++- 7 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 data/triggers/attends.d/README.md create mode 100644 data/triggers/create_ticket_in_event.d/README.md create mode 100644 data/triggers/delete_ticket_in_event.d/README.md create mode 100644 data/triggers/update_ticket_in_event.d/README.md diff --git a/.gitignore b/.gitignore index f039012..7371de2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -data/triggers/*.d ssl/*.pem angular_app/node_modules/ diff --git a/data/triggers/attends.d/README.md b/data/triggers/attends.d/README.md new file mode 100644 index 0000000..0be3451 --- /dev/null +++ b/data/triggers/attends.d/README.md @@ -0,0 +1,5 @@ +attends.d triggers +================== + +Put here the scripts that you want to run when a person is marked as an attendee. + diff --git a/data/triggers/create_ticket_in_event.d/README.md b/data/triggers/create_ticket_in_event.d/README.md new file mode 100644 index 0000000..cf4f561 --- /dev/null +++ b/data/triggers/create_ticket_in_event.d/README.md @@ -0,0 +1,5 @@ +create_ticket_in_event.d triggers +================================= + +Put here the scripts that you want to run when a ticket is created. + diff --git a/data/triggers/delete_ticket_in_event.d/README.md b/data/triggers/delete_ticket_in_event.d/README.md new file mode 100644 index 0000000..5c43185 --- /dev/null +++ b/data/triggers/delete_ticket_in_event.d/README.md @@ -0,0 +1,5 @@ +delete_ticket_in_event.d triggers +================================= + +Put here the scripts that you want to run when a ticket is deleted. + diff --git a/data/triggers/update_ticket_in_event.d/README.md b/data/triggers/update_ticket_in_event.d/README.md new file mode 100644 index 0000000..0be6998 --- /dev/null +++ b/data/triggers/update_ticket_in_event.d/README.md @@ -0,0 +1,5 @@ +update_ticket_in_event.d triggers +================================= + +Put here the scripts that you want to run when a ticket is updated. + diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 9704845..b3aca6c 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -151,7 +151,6 @@ Main field: Notice that all the fields used to identiy a person (name, surname, email) depends on how you've edited the event's form. - users collection ---------------- @@ -162,6 +161,48 @@ To generate the hash, use: print utils.hash\_password('MyVerySecretPassword') +Code layout +=========== + +The code is so divided: ++- eventman\_server.py - the Tornado Web server ++- backend.py - stuff to interact with MongoDB ++- utils.py - utilities ++- angular\_app/ - the client-side web application +| | +| +- *.html - AngularJS templates +| +- Gruntfile.js - Grunt file to extract i18n strings +| +- js/*.js - AngularJS code +| | +| +- app.js - main application and routing +| +- controllers.js - controllers of the templates +| +- services.js - interaction with the web server +| +- directives.js - stuff to interact with the DOM +| +- filters.js - filtering data +| +- i18n.js - i18n ++- data/ +| | +| +- triggers/ +| | +| +- triggers-available/ - various trigger scripts +| +- triggers/ enabled trigger scripts +| | +| +- attends.d/ - scripts to be executed when a person is marked as an attendee +| +- create\_ticket\_in\_event.d/ - scripts that are run when a ticket is created +| +- update\_ticket\_in\_event.d/ - scripts that are run when a ticket is updated +| +- delete\_ticket\_in\_event.d/ - scripts that are run when a ticket is deleted ++- ssl/ - put here your eventman\_cert.pem and eventman\_key.pem certs ++- static/ +| | +| +- js/ - every third-party libraries (plus eventman.js with some small utils) +| +- css/ - third-party CSS (plus eventman.css) +| +- fonts/ - third-party fonts +| +- images/ - third-party images +| +- i18n/ - i18n files ++- templates/ - Tornado Web templates (not used ++- tests/ - eeeehhhh + + Coding style and conventions ============================ diff --git a/eventman_server.py b/eventman_server.py index 3ba4389..daa0c5c 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -643,7 +643,7 @@ class EventsHandler(CollectionHandler): self._clean_dict(data) data['seq'] = self.get_next_seq('event_%s_tickets' % id_) data['seq_hex'] = '%06X' % data['seq'] - data['_id'] = self.gen_id() + data['_id'] = ticket_id = self.gen_id() ret = {'action': 'add', 'ticket': data, 'uuid': uuid} merged, doc = self.db.update('events', {'_id': id_}, @@ -652,6 +652,16 @@ class EventsHandler(CollectionHandler): create=False) if doc: self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) + ticket = self._get_ticket_data(ticket_id, doc.get('tickets') or []) + env = self._dict2env(ticket) + env.update({'PERSON_ID': ticket_id, 'TICKED_ID': ticket_id, 'EVENT_ID': id_, + 'EVENT_TITLE': doc.get('title', ''), 'WEB_USER': self.current_user, + 'WEB_REMOTE_IP': self.request.remote_ip}) + stdin_data = {'new': ticket, + 'event': doc, + 'merged': merged + } + self.run_triggers('create_ticket_in_event', stdin_data=stdin_data, env=env) return ret def handle_put_tickets(self, id_, ticket_id, data): @@ -705,12 +715,22 @@ class EventsHandler(CollectionHandler): {'_id': id_, 'tickets._id': ticket_id}) ret = {'action': 'delete', '_id': ticket_id, 'uuid': uuid} if doc: - merged, doc = self.db.update('events', + ticket = self._get_ticket_data(ticket_id, doc[0].get('tickets') or []) + merged, rdoc = self.db.update('events', {'_id': id_}, {'tickets': {'_id': ticket_id}}, operation='delete', create=False) self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) + env = self._dict2env(ticket) + env.update({'PERSON_ID': ticket_id, 'TICKED_ID': ticket_id, 'EVENT_ID': id_, + 'EVENT_TITLE': rdoc.get('title', ''), 'WEB_USER': self.current_user, + 'WEB_REMOTE_IP': self.request.remote_ip}) + stdin_data = {'old': ticket, + 'event': rdoc, + 'merged': merged + } + self.run_triggers('delete_ticket_in_event', stdin_data=stdin_data, env=env) return ret