From 3a32b990ce3a31c683f0b85f72c9cb245f6bdd81 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Tue, 4 Nov 2014 15:22:19 +0100 Subject: [PATCH 1/5] add exception handling for TypeError and if a field named image isn't an ImageField, do not break the viewlet --- sc/social/like/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sc/social/like/utils.py b/sc/social/like/utils.py index f04aeb76..9b8a56d3 100644 --- a/sc/social/like/utils.py +++ b/sc/social/like/utils.py @@ -20,6 +20,8 @@ def get_images_view(context): field = [f for f in schema.keys() if f in fields] if field: field = field[0] + if schema[field].type not in ["image", "blob"]: + field = "" value = (view, field) if (view and field) else (None, None) cache[key] = value return value @@ -55,6 +57,8 @@ def get_content_image(context, img = view.scale(fieldname=field, **kwargs) except AttributeError: img = None + except TypeError: + img = None cache[key] = img return img From b54b754cfcd13d6a986e2fb805ceea38386d52b2 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Tue, 4 Nov 2014 15:22:32 +0100 Subject: [PATCH 2/5] updated changes --- CHANGES.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index c3c83689..0f2a1555 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,11 @@ Changelog 2.0rc2 (unreleased) ^^^^^^^^^^^^^^^^^^^ -- Nothing changed yet. +- If a field named "image" isn't an ImageField, do not break the viewlet + [cekk] + +- Add exception handling also for TypeError in get_content_image method + [cekk] 2.0rc1 (2014-10-14) From 915139f5dc35cb5f185ade0a5ed5ac0437910f9a Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Tue, 4 Nov 2014 15:22:19 +0100 Subject: [PATCH 3/5] add exception handling for TypeError and if a field named image isn't an ImageField, do not break the viewlet --- sc/social/like/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sc/social/like/utils.py b/sc/social/like/utils.py index f04aeb76..9b8a56d3 100644 --- a/sc/social/like/utils.py +++ b/sc/social/like/utils.py @@ -20,6 +20,8 @@ def get_images_view(context): field = [f for f in schema.keys() if f in fields] if field: field = field[0] + if schema[field].type not in ["image", "blob"]: + field = "" value = (view, field) if (view and field) else (None, None) cache[key] = value return value @@ -55,6 +57,8 @@ def get_content_image(context, img = view.scale(fieldname=field, **kwargs) except AttributeError: img = None + except TypeError: + img = None cache[key] = img return img From 2be3a4390c0a3bf47af9fbd129ae6b741f9beb34 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Tue, 4 Nov 2014 15:22:32 +0100 Subject: [PATCH 4/5] updated changes --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 839a407b..b93a33a8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,12 @@ Changelog - Fixed metadata og:type, used value 'article' for internal page [fdelia] +- If a field named "image" isn't an ImageField, do not break the viewlet + [cekk] + +- Add exception handling also for TypeError in get_content_image method + [cekk] + 2.0rc1 (2014-10-14) ^^^^^^^^^^^^^^^^^^ From 2cff7952c6ce5fc84ad0d43a4cc5ea5284179853 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Tue, 4 Nov 2014 16:26:10 +0100 Subject: [PATCH 5/5] add comment to get_images_view and merged exception handlings --- sc/social/like/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sc/social/like/utils.py b/sc/social/like/utils.py index 9b8a56d3..ee0898a3 100644 --- a/sc/social/like/utils.py +++ b/sc/social/like/utils.py @@ -20,6 +20,8 @@ def get_images_view(context): field = [f for f in schema.keys() if f in fields] if field: field = field[0] + # if a content has an image field that isn't an ImageField + # (for example a relation field), set field="" to avoid errors if schema[field].type not in ["image", "blob"]: field = "" value = (view, field) if (view and field) else (None, None) @@ -55,9 +57,7 @@ def get_content_image(context, kwargs['direction'] = 'down' try: img = view.scale(fieldname=field, **kwargs) - except AttributeError: - img = None - except TypeError: + except (AttributeError, TypeError): img = None cache[key] = img return img