Changes between Version 1 and Version 2 of Events


Ignore:
Timestamp:
12/09/14 11:13:13 (11 years ago)
Author:
mschenk
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Events

    v1 v2  
    1717The body of a mail event consists of a JSON-encoded dictionary of the following form:
    1818
    19 {{{#!python
    20 
     19{{{
     20#!py
    2121{
    2222  'from_email': 'sender@my.domain',
     
    2929
    3030The '''html_message''' field is optional.
     31
     32Example of an e-mail event:
     33
     34{{{
     35#!py
     36import pika
     37import json
     38
     39credentials = pika.PlainCredentials(SETTINGS.queueuser, SETTINGS.queuepassword)
     40connection = pika.BlockingConnection(pika.ConnectionParameters(
     41    host=SETTINGS.queuehost,credentials=credentials))
     42channel = connection.channel()
     43message = {
     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}
     50channel.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
     62This 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
     64The routing key for this event is '''learner.add'''
     65
     66The 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
     84The 'learner' key holds an encoding of the django-object from learners.models
     85
     86Example of a '''learner.add''' event:
     87
     88
     89{{{
     90#!py
     91import pika
     92import jsonpickle
     93
     94credentials = pika.PlainCredentials(SETTINGS.queueuser, SETTINGS.queuepassword)
     95connection = pika.BlockingConnection(pika.ConnectionParameters(
     96    host=SETTINGS.queuehost,credentials=credentials))
     97channel = connection.channel()
     98learner = learners.models.Learner.objects.get(id=learnerid)
     99message = {
     100  'learners': learner,
     101  'password': learnerpassword,
     102}
     103channel.basic_publish(
     104  exchange='extensionschoolevents',
     105  routing_key='mail.sending',
     106  body=jsonpickle.encode(message),
     107  properties=pika.BasicProperties(delivery_mode=2),
     108)
     109}}}