Revision 59f598f1 snf-astakos-app/astakos/im/models.py
b/snf-astakos-app/astakos/im/models.py | ||
---|---|---|
42 | 42 |
from django.contrib.auth.models import User, UserManager |
43 | 43 |
|
44 | 44 |
from astakos.im.settings import DEFAULT_USER_LEVEL, INVITATIONS_PER_LEVEL, AUTH_TOKEN_DURATION, BILLING_FIELDS, QUEUE_CONNECTION |
45 |
from astakos.im.queue.userevent import UserEvent |
|
45 | 46 |
from synnefo.lib.queue import exchange_connect, exchange_send, exchange_close, Receipt |
46 | 47 |
|
47 | 48 |
QUEUE_CLIENT_ID = 3 # Astakos. |
... | ... | |
74 | 75 |
|
75 | 76 |
email_verified = models.BooleanField('Email verified?', default=False) |
76 | 77 |
|
78 |
has_credits = models.BooleanField('Has credits?', default=False) |
|
79 |
|
|
77 | 80 |
@property |
78 | 81 |
def realname(self): |
79 | 82 |
return '%s %s' %(self.first_name, self.last_name) |
... | ... | |
165 | 168 |
return False |
166 | 169 |
|
167 | 170 |
if QUEUE_CONNECTION and should_send(user): |
168 |
l = [[elem, str(user.__getattribute__(elem))] for elem in BILLING_FIELDS] |
|
169 |
details = dict(l) |
|
170 |
details['eventType'] = 'create' if not user.id else 'modify' |
|
171 |
body = Receipt(QUEUE_CLIENT_ID, user.email, '', 0, details).format() |
|
171 |
eventType = 'create' if not user.id else 'modify' |
|
172 |
body = UserEvent(QUEUE_CLIENT_ID, user, eventType, {}).format() |
|
172 | 173 |
conn = exchange_connect(QUEUE_CONNECTION) |
173 |
routing_key = QUEUE_CONNECTION.replace('#', body['id'])
|
|
174 |
routing_key = QUEUE_CONNECTION.replace('*', 'user')
|
|
174 | 175 |
exchange_send(conn, routing_key, body) |
175 |
exchange_close(conn) |
|
176 |
exchange_close(conn) |
Also available in: Unified diff