Revision 73fbaec4 snf-astakos-app/astakos/im/endpoints/qh.py
b/snf-astakos-app/astakos/im/endpoints/qh.py | ||
---|---|---|
52 | 52 |
|
53 | 53 |
inf = float('inf') |
54 | 54 |
|
55 |
_client = None |
|
56 |
def get_client(): |
|
57 |
global _client |
|
58 |
if _client: |
|
59 |
return _client |
|
60 |
if not QUOTAHOLDER_URL: |
|
61 |
return |
|
62 |
_client = QuotaholderClient(QUOTAHOLDER_URL, token=QUOTAHOLDER_TOKEN) |
|
63 |
|
|
55 | 64 |
def call(func_name): |
56 | 65 |
"""Decorator function for Quotaholder client calls.""" |
57 | 66 |
def decorator(payload_func): |
58 | 67 |
@wraps(payload_func) |
59 |
def wrapper(entities=(), client=None, **kwargs):
|
|
68 |
def wrapper(entities=(), **kwargs): |
|
60 | 69 |
if not entities: |
61 |
return client, ()
|
|
70 |
return () |
|
62 | 71 |
|
63 | 72 |
if not QUOTAHOLDER_URL: |
64 |
return client, ()
|
|
73 |
return () |
|
65 | 74 |
|
66 |
c = client or QuotaholderClient(QUOTAHOLDER_URL, token=QUOTAHOLDER_TOKEN)
|
|
75 |
c = get_client()
|
|
67 | 76 |
func = c.__dict__.get(func_name) |
68 | 77 |
if not func: |
69 |
return c, ()
|
|
78 |
return () |
|
70 | 79 |
|
71 | 80 |
data = payload_func(entities, client, **kwargs) |
72 | 81 |
if not data: |
73 |
return c, data
|
|
82 |
return data |
|
74 | 83 |
|
75 | 84 |
funcname = func.__name__ |
76 | 85 |
kwargs = {'context': {}, funcname: data} |
77 | 86 |
rejected = func(**kwargs) |
78 | 87 |
msg = _('%s: %s - Rejected: %s' % (funcname, data, rejected,)) |
79 | 88 |
logger.log(LOGGING_LEVEL, msg) |
80 |
return c, rejected
|
|
89 |
return rejected |
|
81 | 90 |
return wrapper |
82 | 91 |
return decorator |
83 | 92 |
|
... | ... | |
153 | 162 |
|
154 | 163 |
def register_users(users, client=None): |
155 | 164 |
users, copy = itertools.tee(users) |
156 |
client, rejected = create_entities(entities=users,
|
|
165 |
rejected = create_entities(entities=users, |
|
157 | 166 |
client=client, |
158 | 167 |
field='email') |
159 | 168 |
created = (e for e in copy if unicode(e) not in rejected) |
160 |
return send_quota(created, client)
|
|
169 |
return send_quota(created) |
|
161 | 170 |
|
162 | 171 |
|
163 | 172 |
def register_resources(resources, client=None): |
164 | 173 |
resources, copy = itertools.tee(resources) |
165 |
client, rejected = create_entities(entities=resources,
|
|
174 |
rejected = create_entities(entities=resources, |
|
166 | 175 |
client=client, |
167 | 176 |
field='service') |
168 | 177 |
created = (e for e in copy if unicode(e) not in rejected) |
169 |
return send_resource_quantities(created, client)
|
|
178 |
return send_resource_quantities(created) |
|
170 | 179 |
|
171 | 180 |
|
172 | 181 |
from datetime import datetime |
Also available in: Unified diff