-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#130 - Implement fallback image #138
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the changelog entry is missing also; we will need to wait until #136 is merged.
self.filename = None | ||
self.data = None | ||
|
||
registry = getUtility(IRegistry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the API instead: api.portal.get_registry_record()
with None
as default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
||
def __init__(self, context, request): | ||
super(ImageFallBack, self).__init__(context, request) | ||
self.filename = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can initialize both in one line: self.filename = self.data = None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about:
class ImageFallBack(Download):
filename = None
data = None
def __call__(self):
self.setup()
super(ImageFallBack, self).__call__()
def setup(self):
# add rest of init method here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
sc/social/like/interfaces.py
Outdated
|
||
model.fieldset( | ||
'open_graph', | ||
label=u'Open Graph', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be internationalized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
sc/social/like/interfaces.py
Outdated
label=u'Open Graph', | ||
fields=[ | ||
'image_fallback', | ||
'image_scale' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to put the whole list in one line, but you may add a trailing comma if you like this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too.
sc/social/like/interfaces.py
Outdated
) | ||
|
||
form.widget('image_fallback', NamedImageFieldWidget) | ||
image_fallback = schema.ASCII( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's rename the field to fallback_image
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
sc/social/like/browser/viewlets.py
Outdated
@@ -79,6 +80,7 @@ def update(self): | |||
self.site_name = portal.Title() | |||
self.language = facebook_language(get_language(self.context), 'en_US') | |||
self.image = get_content_image(self.context) | |||
self.image_fallback = get_image_fallback(portal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only need to get the fallback image if the content has no lead image; you have to load this later and only if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
@@ -77,4 +77,11 @@ | |||
permission="cmf.ManagePortal" | |||
/> | |||
|
|||
<browser:page | |||
for="*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
register this view for site root only as the fallback image is the same all over the place; also, add a browser layer here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
sc/social/like/browser/viewlets.py
Outdated
@@ -110,7 +112,7 @@ def image_url(self): | |||
if img: | |||
return img.url | |||
else: | |||
return self.portal_url() + '/logo.png' | |||
return self.image_fallback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use self.portal_url() + get_image_fallback()
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
sc/social/like/utils.py
Outdated
|
||
if getattr(settings, 'image_fallback', False): | ||
filename, data = b64decode_file(settings.image_fallback) | ||
return '{0}/@@sociallike-image-fallback/{1}'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just return the path relative to the site root; also, don't use format()
in this case as is pretty slow; a simple concatenation will make the work faster: return '/@@sociallike-image-fallback/' + filename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hvelarde you forgot about the site_url
variable in your example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, I want to remove that call from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
sc/social/like/utils.py
Outdated
# | ||
# filename, data = b64decode_file(value) | ||
# image = NamedBlobImage(data=data, filename=filename) | ||
# msg = validate_image_social(image) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the validator no longer returns the message: it will rise ValueError
with the error message; you may intercept and raise Invalid(e.message)
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not finish waiting for # 136
sc/social/like/interfaces.py
Outdated
required=True, | ||
default=u'large', | ||
vocabulary='sc.social.likes.ImagesScales', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this field looks like it don't belongs to this issue, should be addressed to the right issue and pull request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this field was requested in redmine.
title="Adds new field to the control panel." | ||
description="This fields will be used to generate 'og:image' when content not image." | ||
handler=".update_registry" | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do this without a handler, take a look at this PR https://github.com/collective/sc.social.like/pull/136/files#diff-8101f2cdf8c9e74b0408e13d6e1eed44R10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
sc/social/like/vocabularies.py
Outdated
mapping={'width': str(width), 'height': str(height)}) | ||
terms.append(SimpleTerm(scale, scale, translated)) | ||
|
||
return SimpleVocabulary(terms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about to filter the result of the default vocabulary?
https://github.com/plone/plone.app.vocabularies/blob/2.1.x/plone/app/vocabularies/images.py#L13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think so.
ScalesVocabulary(context)._terms[0].title
u'imagescale_mini'
ScalesVocabulary(context)._terms[0].value
'mini'
ScalesVocabulary(context)._terms[0].token
'mini'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not? that way we can skip the i18n.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting the PR be ready, and all changes described to read again
super(ImageFallBack, self).__call__() | ||
|
||
def setup(self): | ||
fallback_image = api.portal.get_registry_record('fallback_image', interface=ISocialLikeSettings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot the default value; without it it will fail if the upgrade step has not been run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
sc/social/like/utils.py
Outdated
def get_fallback_image(): | ||
from sc.social.like.interfaces import ISocialLikeSettings | ||
|
||
fallback_image = api.portal.get_registry_record('fallback_image', interface=ISocialLikeSettings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're missing default value here also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
@claytonc please check the rebase; I see a mixture of things that are already in the master branch here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are still missing documentation on the README file and an entry on the changelog.
<browser:page | ||
name="sociallike-fallback-image" | ||
for="Products.CMFPlone.interfaces.IPloneSiteRoot" | ||
class=".imagefallback.ImageFallBack" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.fallbackimage.FallBackImage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
|
||
|
||
class ImageFallBack(Download): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a docstring expaining the purpose of this helper view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
sc/social/like/interfaces.py
Outdated
|
||
form.widget('fallback_image', NamedImageFieldWidget) | ||
fallback_image = schema.ASCII( | ||
title=_(u'Image fallback'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fallback image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
sc/social/like/interfaces.py
Outdated
title=_(u'Image fallback'), | ||
description=_( | ||
u'help_fallback_image', | ||
default=u'Content that does not have an image will be displayed on the share.\n ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this messages makes no sense; please review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -3,8 +3,8 @@ | |||
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"> | |||
|
|||
<genericsetup:upgradeSteps | |||
source="3046" | |||
destination="3047" | |||
source="3047" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong; you need to register a new upgrade step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
c5e88a9
to
b20bdee
Compare
[skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This will be done before the release to make easier the code review.
@@ -198,3 +200,30 @@ def validate_og_lead_image(image): | |||
raise ValueError(MSG_INVALID_OG_LEAD_IMAGE_ASPECT_RATIO) | |||
|
|||
return True | |||
|
|||
|
|||
def validate_og_fallback_image(value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a TODO
comment to move code to share this logic with validate_og_lead_image
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about it, but it's not so easy as the code only looks similar.
sc/social/like/browser/viewlets.py
Outdated
def get_fallback_image(self): | ||
fallback_image = self.settings.fallback_image | ||
if fallback_image is not None: | ||
filename, data = b64decode_file(fallback_image) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filename, _ = b64decode_file(fallback_image)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just added some comments
Sorry we didn't review it, since you're all adding lots of comments we we're waiting for all your suggestions to be merged before doing a full review. |
@idgserpro you can review it now ;) |
closes #130