| | 31 | |
| | 32 | Example of an e-mail event: |
| | 33 | |
| | 34 | {{{ |
| | 35 | #!py |
| | 36 | import pika |
| | 37 | import json |
| | 38 | |
| | 39 | credentials = pika.PlainCredentials(SETTINGS.queueuser, SETTINGS.queuepassword) |
| | 40 | connection = pika.BlockingConnection(pika.ConnectionParameters( |
| | 41 | host=SETTINGS.queuehost,credentials=credentials)) |
| | 42 | channel = connection.channel() |
| | 43 | message = { |
| | 44 | 'from_email': 'sender@my.domain', |
| | 45 | 'recipient_list': [ 'recipient1@gmail.com', 'recipient2@hotmail.com' ], |
| | 46 | 'subject': 'The subject line for this message', |
| | 47 | 'message': 'A multi-line string holding the text version of this message', |
| | 48 | 'html_message': 'A multi-line string holding the html-version of this message', |
| | 49 | } |
| | 50 | channel.basic_publish( |
| | 51 | exchange='extensionschoolevents', |
| | 52 | routing_key='mail.sending', |
| | 53 | body=json.dumps(message), |
| | 54 | properties=pika.BasicProperties(delivery_mode=2), |
| | 55 | ) |
| | 56 | }}} |
| | 57 | |
| | 58 | ### Learner events ### |
| | 59 | |
| | 60 | #### Add #### |
| | 61 | |
| | 62 | This event must be sent when a new learner has registered. At this moment the learner MUST also have provided a password for his registration. |
| | 63 | |
| | 64 | The routing key for this event is '''learner.add''' |
| | 65 | |
| | 66 | The body of a learner.add event consists of a JSON-encoded dictionary of the following object: |
| | 67 | {{{ |
| | 68 | { |
| | 69 | 'learner': { |
| | 70 | 'id': 15, |
| | 71 | 'email': 'a.g.degroot@hotmail.com', |
| | 72 | 'userlevel': 1, |
| | 73 | 'newslettersubscription': false, |
| | 74 | 'surname': 'Groot', |
| | 75 | 'firstname': 'Anne', |
| | 76 | 'nameprefix': 'de', |
| | 77 | 'initials': 'A.G.', |
| | 78 | 'gender': 'Female', |
| | 79 | } |
| | 80 | 'password': 'plaintext password for this learner' |
| | 81 | } |
| | 82 | }}} |
| | 83 | |
| | 84 | The 'learner' key holds an encoding of the django-object from learners.models |
| | 85 | |
| | 86 | Example of a '''learner.add''' event: |
| | 87 | |
| | 88 | |
| | 89 | {{{ |
| | 90 | #!py |
| | 91 | import pika |
| | 92 | import jsonpickle |
| | 93 | |
| | 94 | credentials = pika.PlainCredentials(SETTINGS.queueuser, SETTINGS.queuepassword) |
| | 95 | connection = pika.BlockingConnection(pika.ConnectionParameters( |
| | 96 | host=SETTINGS.queuehost,credentials=credentials)) |
| | 97 | channel = connection.channel() |
| | 98 | learner = learners.models.Learner.objects.get(id=learnerid) |
| | 99 | message = { |
| | 100 | 'learners': learner, |
| | 101 | 'password': learnerpassword, |
| | 102 | } |
| | 103 | channel.basic_publish( |
| | 104 | exchange='extensionschoolevents', |
| | 105 | routing_key='mail.sending', |
| | 106 | body=jsonpickle.encode(message), |
| | 107 | properties=pika.BasicProperties(delivery_mode=2), |
| | 108 | ) |
| | 109 | }}} |