diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-04-18 14:43:47 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-04-18 14:43:47 +0200 |
commit | b96025389e5b977d6a6d525676eaaf5f598fc426 (patch) | |
tree | 05d188290306692154eacf79e3deb9a7c48ea08e /ishtar_common/views.py | |
parent | d3c605187aedabbbe498f72e32f9166202f72c0e (diff) | |
download | Ishtar-b96025389e5b977d6a6d525676eaaf5f598fc426.tar.bz2 Ishtar-b96025389e5b977d6a6d525676eaaf5f598fc426.zip |
get_item: fix many2many columns get
Diffstat (limited to 'ishtar_common/views.py')
-rw-r--r-- | ishtar_common/views.py | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 009b7e3de..64107f159 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -581,6 +581,23 @@ HIERARCHIC_FIELDS = ['periods', 'period', 'unit', 'material_types', 'material_type', 'conservatory_state'] +def _get_values(val): + if hasattr(val, 'all'): # manage related objects + vals = list(val.all()) + else: + vals = [val] + new_vals = [] + for v in vals: + if callable(v): + v = v() + if hasattr(v, 'url'): + v = request.is_secure() and \ + 'https' or 'http' + '://' + \ + request.get_host() + v.url + new_vals.append(v) + return new_vals + + def get_item(model, func_name, default_name, extra_request_keys=[], base_request=None, bool_fields=[], reversed_bool_fields=[], dated_fields=[], associated_models=[], relative_session_names=[], @@ -1003,23 +1020,11 @@ def get_item(model, func_name, default_name, extra_request_keys=[], val = list(val.all()) for v in val: v = getattr(v, ky) - if callable(v): - v = v() - if hasattr(v, 'url'): - v = request.is_secure() and \ - 'https' or 'http' + '://' + \ - request.get_host() + v.url - new_vals.append(v) + new_vals += _get_values(v) elif val: try: val = getattr(val, ky) - if callable(val): - val = val() - if hasattr(val, 'url'): - val = request.is_secure() and \ - 'https' or 'http' + '://' + \ - request.get_host() + val.url - new_vals.append(val) + new_vals += _get_values(val) except AttributeError: # must be a query key such as "contains" pass |