Skip to content
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

Merged
merged 26 commits into from
Sep 28, 2017
Merged

#130 - Implement fallback image #138

merged 26 commits into from
Sep 28, 2017

Conversation

claytonc
Copy link
Contributor

@claytonc claytonc commented Sep 14, 2017

closes #130

Copy link
Member

@hvelarde hvelarde left a 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)
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


model.fieldset(
'open_graph',
label=u'Open Graph',
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

label=u'Open Graph',
fields=[
'image_fallback',
'image_scale'
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too.

)

form.widget('image_fallback', NamedImageFieldWidget)
image_fallback = schema.ASCII(
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

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="*"
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@@ -110,7 +112,7 @@ def image_url(self):
if img:
return img.url
else:
return self.portal_url() + '/logo.png'
return self.image_fallback
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


if getattr(settings, 'image_fallback', False):
filename, data = b64decode_file(settings.image_fallback)
return '{0}/@@sociallike-image-fallback/{1}'.format(
Copy link
Member

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

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

#
# filename, data = b64decode_file(value)
# image = NamedBlobImage(data=data, filename=filename)
# msg = validate_image_social(image)
Copy link
Member

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.

Copy link
Contributor Author

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

required=True,
default=u'large',
vocabulary='sc.social.likes.ImagesScales',
)
Copy link
Member

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

Copy link
Contributor Author

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"
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

mapping={'width': str(width), 'height': str(height)})
terms.append(SimpleTerm(scale, scale, translated))

return SimpleVocabulary(terms)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@claytonc claytonc Sep 15, 2017

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'

Copy link
Member

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.

Copy link
Member

@rodfersou rodfersou left a 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)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

def get_fallback_image():
from sc.social.like.interfaces import ISocialLikeSettings

fallback_image = api.portal.get_registry_record('fallback_image', interface=ISocialLikeSettings)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@hvelarde
Copy link
Member

@claytonc please check the rebase; I see a mixture of things that are already in the master branch here.

Copy link
Member

@hvelarde hvelarde left a 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.fallbackimage.FallBackImage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok



class ImageFallBack(Download):

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


form.widget('fallback_image', NamedImageFieldWidget)
fallback_image = schema.ASCII(
title=_(u'Image fallback'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallback image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

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 '
Copy link
Member

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.

Copy link
Contributor Author

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"
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@hvelarde hvelarde force-pushed the issue_130 branch 2 times, most recently from c5e88a9 to b20bdee Compare September 27, 2017 21:47
Copy link
Member

@hvelarde hvelarde left a 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):
Copy link
Member

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

Copy link
Member

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.

def get_fallback_image(self):
fallback_image = self.settings.fallback_image
if fallback_image is not None:
filename, data = b64decode_file(fallback_image)
Copy link
Member

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)

Copy link
Member

@rodfersou rodfersou left a 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

@hvelarde hvelarde merged commit 2e67159 into master Sep 28, 2017
@hvelarde hvelarde deleted the issue_130 branch September 28, 2017 02:54
@idgserpro
Copy link
Member

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.

@hvelarde
Copy link
Member

@idgserpro you can review it now ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement fallback image
4 participants