fixes #142: trigger for created and deleted tickets

This commit is contained in:
Davide Alberani 2016-07-10 17:25:16 +02:00
parent 5b0923afec
commit 82cdbf6738
7 changed files with 84 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
data/triggers/*.d
ssl/*.pem
angular_app/node_modules/

View file

@ -0,0 +1,5 @@
attends.d triggers
==================
Put here the scripts that you want to run when a person is marked as an attendee.

View file

@ -0,0 +1,5 @@
create_ticket_in_event.d triggers
=================================
Put here the scripts that you want to run when a ticket is created.

View file

@ -0,0 +1,5 @@
delete_ticket_in_event.d triggers
=================================
Put here the scripts that you want to run when a ticket is deleted.

View file

@ -0,0 +1,5 @@
update_ticket_in_event.d triggers
=================================
Put here the scripts that you want to run when a ticket is updated.

View file

@ -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
============================

View file

@ -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