diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-05-28 12:33:16 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-06-17 13:21:28 +0200 |
commit | c18ce7cf3939f7b9faaf8c4e2eb68df6b5fcabdf (patch) | |
tree | 41dd98718789fc6e1989729c85574925f972c4b7 | |
parent | ceae0f344ac4b2d494c58ba3aefd50825c374290 (diff) | |
download | Ishtar-c18ce7cf3939f7b9faaf8c4e2eb68df6b5fcabdf.tar.bz2 Ishtar-c18ce7cf3939f7b9faaf8c4e2eb68df6b5fcabdf.zip |
Data: provide MEDIA URL path for images
-rw-r--r-- | ishtar_common/views_item.py | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 032d3e2c2..65695f067 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -1843,27 +1843,31 @@ def get_item(model, func_name, default_name, extra_request_keys=None, lnk = '' res["link"] = lnk for idx, value in enumerate(data[1:]): - if value: - table_col = table_cols[idx] - if type(table_col) not in (list, tuple): - table_col = [table_col] - tab_cols = [] - # foreign key may be divided by "." or "__" - for tc in table_col: - if '.' in tc: - tab_cols += tc.split('.') - elif '__' in tc: - tab_cols += tc.split('__') - else: - tab_cols.append(tc) - k = "__".join(tab_cols) - if hasattr(model, 'COL_LINK') and k in model.COL_LINK: - value = link_ext_template.format(value, value) - if isinstance(value, datetime.date): - value = value.strftime('%Y-%m-%d') - if isinstance(value, datetime.datetime): - value = value.strftime('%Y-%m-%d %H:%M:%S') - res[k] = value + if not value: + continue + table_col = table_cols[idx] + if type(table_col) not in (list, tuple): + table_col = [table_col] + tab_cols = [] + # foreign key may be divided by "." or "__" + for tc in table_col: + if '.' in tc: + tab_cols += tc.split('.') + elif '__' in tc: + tab_cols += tc.split('__') + else: + tab_cols.append(tc) + k = "__".join(tab_cols) + if k.endswith("__image") or k.endswith("__thumbnail"): + if not value.startswith(settings.MEDIA_ROOT): + value = settings.MEDIA_URL + value + if hasattr(model, 'COL_LINK') and k in model.COL_LINK: + value = link_ext_template.format(value, value) + if isinstance(value, datetime.date): + value = value.strftime('%Y-%m-%d') + if isinstance(value, datetime.datetime): + value = value.strftime('%Y-%m-%d %H:%M:%S') + res[k] = value if full == 'shortcut': if 'cached_label' in res: res['value'] = res.pop('cached_label') |