Skip to content

Commit 3cbb7de

Browse files
Update helpers.py
1 parent ebd9143 commit 3cbb7de

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ckanext/showcase/logic/helpers.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,26 @@ def get_site_statistics():
3434

3535
def showcase_get_wysiwyg_editor():
3636
return tk.config.get('ckanext.showcase.editor', '')
37+
38+
39+
def get_value_from_showcase_extras(extras, key):
40+
value = ''
41+
for item in extras:
42+
if item.get('key') == key:
43+
value = item.get('value')
44+
return value
45+
46+
# look for a thumbnail image for image found at path image_url and returns the thumbnail url if it exists
47+
# if no thumbnail exists, the original image_fp is returned
48+
def get_thumbnail( image_name ):
49+
50+
# convert image url to file path
51+
#image_fp = tk.config.get("ckan.storage_path") + '/storage' + image_name
52+
53+
# convert image_fp to thumb_fp by adding -thumbnail before the file extension
54+
thumb_name = "{0}-{2}.{1}".format(*image_name.rsplit('.', 1) + ['thumbnail'])
55+
56+
if exists( tk.config.get("ckan.storage_path") + '/storage/uploads/showcase/' + thumb_name ):
57+
return thumb_name
58+
else:
59+
return image_name

0 commit comments

Comments
 (0)