| 110 | |
| 111 | #### Update #### |
| 112 | |
| 113 | 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. |
| 114 | |
| 115 | The routing key for this event is '''learner.update''' |
| 116 | |
| 117 | The body of a learner.add event consists of a JSON-encoded dictionary of the following object: |
| 118 | {{{ |
| 119 | { |
| 120 | 'learner': { |
| 121 | 'id': 15, |
| 122 | 'email': 'a.g.degroot@hotmail.com', |
| 123 | 'userlevel': 1, |
| 124 | 'newslettersubscription': false, |
| 125 | 'surname': 'Groot', |
| 126 | 'firstname': 'Anne', |
| 127 | 'nameprefix': 'de', |
| 128 | 'initials': 'A.G.', |
| 129 | 'gender': 'Female', |
| 130 | } |
| 131 | 'password': 'plaintext password for this learner' |
| 132 | } |
| 133 | }}} |
| 134 | |
| 135 | The 'learner' key holds an encoding of the django-object from learners.models |
| 136 | |
| 137 | The 'password' key is optional and should only be filled in case of a password change. |
| 138 | |
| 139 | Example of a '''learner.update''' event: |
| 140 | |
| 141 | |
| 142 | {{{ |
| 143 | #!py |
| 144 | import pika |
| 145 | import jsonpickle |
| 146 | |
| 147 | credentials = pika.PlainCredentials(SETTINGS.queueuser, SETTINGS.queuepassword) |
| 148 | connection = pika.BlockingConnection(pika.ConnectionParameters( |
| 149 | host=SETTINGS.queuehost,credentials=credentials)) |
| 150 | channel = connection.channel() |
| 151 | learner = learners.models.Learner.objects.get(id=learnerid) |
| 152 | message = { |
| 153 | 'learners': learner, |
| 154 | 'password': learnerpassword, |
| 155 | } |
| 156 | channel.basic_publish( |
| 157 | exchange='extensionschoolevents', |
| 158 | routing_key='learner.update', |
| 159 | body=jsonpickle.encode(message), |
| 160 | properties=pika.BasicProperties(delivery_mode=2), |
| 161 | ) |
| 162 | }}} |