Revision 84fd22a0
Added by Benjamin Dauvergne about 12 years ago
extra/modules/abelium_domino_vars.py | ||
---|---|---|
1 | 1 |
from decimal import Decimal |
2 | 2 |
import logging |
3 | 3 |
|
4 |
from quixote.publish import get_publisher |
|
5 |
|
|
4 | 6 |
from qommon.substitution import Substitutions |
5 | 7 |
from publisher import WcsPublisher |
6 | 8 |
|
7 |
from abelium_domino_ui import (is_activated, abelium_domino_ws, get_client) |
|
9 |
from abelium_domino_ui import (is_activated, abelium_domino_ws, get_client, get_family)
|
|
8 | 10 |
|
9 | 11 |
SESSION_CACHE = 'abelium_domino_variable_cache' |
10 | 12 |
|
... | ... | |
31 | 33 |
return cache |
32 | 34 |
# call the web service |
33 | 35 |
try: |
34 |
client = get_client()
|
|
35 |
family = client.get_family_by_mail(self.request.user.email)
|
|
36 |
charset = get_publisher().site_charset
|
|
37 |
family = get_family(self.request.user)
|
|
36 | 38 |
if family: |
37 | 39 |
family.complete() |
38 | 40 |
for i, child in enumerate(family.children): |
... | ... | |
40 | 42 |
v = getattr(child, name, None) |
41 | 43 |
if v is None: |
42 | 44 |
continue |
45 |
if hasattr(v, 'encode'): |
|
46 |
v = v.encode(charset) |
|
43 | 47 |
vars[self.CHILD_VARIABLE_TEMPLATE % (name, i+1)] = v |
48 |
vars[self.VARIABLE_TEMPLATE % 'nombre_enfants'] = len(family.children) |
|
44 | 49 |
for remote_name, name, converted, desc in self.FAMILY_COLUMNS: |
45 | 50 |
if hasattr(family, name): |
46 | 51 |
v = getattr(family, name) |
52 |
if v is None: |
|
53 |
continue |
|
54 |
if hasattr(v, 'encode'): |
|
55 |
v = v.encode(charset) |
|
47 | 56 |
vars[self.VARIABLE_TEMPLATE % name] = v |
48 | 57 |
amount = Decimal(0) |
49 | 58 |
for invoice in family.invoices: |
... | ... | |
52 | 61 |
vars['user_famille_reste_du'] = str(amount) |
53 | 62 |
except abelium_domino_ws.DominoException: |
54 | 63 |
logging.exception('unable to call the domino ws for user %s', self.request.user.id) |
55 |
setattr(self.request.session, SESSION_CACHE, vars)
|
|
56 |
self.request.session.store()
|
|
64 |
setattr(self.request.session, SESSION_CACHE, vars)
|
|
65 |
self.request.session.store()
|
|
57 | 66 |
return vars |
58 | 67 |
|
59 | 68 |
def get_substitution_variables_list(cls): |
60 | 69 |
if not is_activated(): |
61 | 70 |
return () |
62 | 71 |
vars = [] |
63 |
for remote_name, name, converted, desc in self.FAMILY_COLUMNS:
|
|
72 |
for remote_name, name, converted, desc in cls.FAMILY_COLUMNS:
|
|
64 | 73 |
vars.append((_('Domino'), cls.VARIABLE_TEMPLATE % name, desc)) |
65 |
for remote_name, name, converted, desc in self.CHILD_COLUMNS:
|
|
74 |
for remote_name, name, converted, desc in cls.CHILD_COLUMNS:
|
|
66 | 75 |
vars.append((_('Domino'), cls.CHILD_VARIABLE_TEMPLATE % (name, '{0,1,2,..}'), desc)) |
67 | 76 |
return vars |
68 | 77 |
get_substitution_variables_list = classmethod(get_substitution_variables_list) |
Also available in: Unified diff
[domino] finish family update workflow
- when creating or updating a family, store the family.code_interne value into
the user object for later retrieval,
- add web service API to retrieve person to contact for children