Skip to content

Commit

Permalink
Consolidate registry records and implement migration of Facebook and …
Browse files Browse the repository at this point in the history
…Twitter properties
  • Loading branch information
hvelarde committed Jun 8, 2016
1 parent 22bb8ae commit a9207fa
Show file tree
Hide file tree
Showing 30 changed files with 236 additions and 280 deletions.
2 changes: 1 addition & 1 deletion sc/social/like/browser/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from plone.memoize.view import memoize_contextless
from plone.registry.interfaces import IRegistry
from Products.Five import BrowserView
from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.interfaces import IHelperView
from sc.social.like.plugins import IPlugin
from zope.component import getMultiAdapter
Expand Down
2 changes: 1 addition & 1 deletion sc/social/like/browser/socialikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from plone import api
from plone.api.exc import InvalidParameterError
from Products.Five import BrowserView
from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikes
from zope.interface import implements

Expand Down
2 changes: 1 addition & 1 deletion sc/social/like/browser/viewlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from plone.app.layout.viewlets import ViewletBase
from plone.memoize.view import memoize
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikeSettings
from zope.component import getMultiAdapter


Expand Down
67 changes: 1 addition & 66 deletions sc/social/like/controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,7 @@
# -*- coding:utf-8 -*-
from plone.app.registry.browser import controlpanel
from sc.social.like import LikeMessageFactory as _
from sc.social.like.config import DEFAULT_ENABLED_CONTENT_TYPES
from sc.social.like.config import DEFAULT_PLUGINS_ENABLED
from zope import schema
from zope.interface import Interface
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


CONTENT_TYPES = 'plone.app.vocabularies.ReallyUserFriendlyTypes'

styles = SimpleVocabulary([
SimpleTerm(value=u'horizontal', title=_(u'horizontal')),
SimpleTerm(value=u'vertical', title=_(u'vertical')),
])


class ISocialLikeSettings(Interface):

"""Schema for the control panel form."""

enabled_portal_types = schema.Tuple(
title=_(u'Content types'),
description=_(
u'help_portal_types',
default=u'Please select content types in which the '
u'viewlet will be applied.',
),
required=True,
default=DEFAULT_ENABLED_CONTENT_TYPES,
value_type=schema.Choice(vocabulary=CONTENT_TYPES)
)

plugins_enabled = schema.Tuple(
title=_(u'Plugins'),
description=_(
u'help_enabled_plugins',
default=u'Please select which plugins will be used',
),
required=False,
default=DEFAULT_PLUGINS_ENABLED,
value_type=schema.Choice(vocabulary='sc.social.likes.plugins')
)

typebutton = schema.Choice(
title=_(u'Button style'),
description=_(
u'help_selected_buttons',
default=u'Choose your button style.',
),
required=True,
default=_(u'horizontal'),
vocabulary=styles,
)

do_not_track = schema.Bool(
title=_(u'Do not track users'),
description=_(
u'help_do_not_track',
default=u'If enabled, the site will not provide advanced sharing '
u'widgets , instead simple links will be used.\n'
u'This will limits user experience and features '
u'(like the share count) but will enhance users privacy: '
u'no 3rd party cookies will be sent to users.'
),
default=False,
)
from sc.social.like.interfaces import ISocialLikeSettings


class SocialLikeSettingsEditForm(controlpanel.RegistryEditForm):
Expand Down
128 changes: 126 additions & 2 deletions sc/social/like/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# -*- coding:utf-8 -*-
from plone.supermodel import model
from sc.social.like import LikeMessageFactory as _
from sc.social.like.config import DEFAULT_ENABLED_CONTENT_TYPES
from sc.social.like.config import DEFAULT_PLUGINS_ENABLED
from sc.social.like.vocabularies import FacebookButtonsVocabulary
from sc.social.like.vocabularies import FacebookVerbsVocabulary
from sc.social.like.vocabularies import TypeButtonVocabulary
from zope import schema
from zope.interface import Interface
from zope.i18nmessageid import MessageFactory
_ = MessageFactory('sc.social.like')


class ISocialLikeLayer(Interface):
Expand Down Expand Up @@ -43,3 +49,121 @@ def plugins():

def view_template_id():
""" View or template id for this context """


class ISocialLikeSettings(model.Schema):

"""Schema for the control panel form."""

enabled_portal_types = schema.Tuple(
title=_(u'Content types'),
description=_(
u'help_portal_types',
default=u'Please select content types in which the '
u'viewlet will be applied.',
),
required=True,
default=DEFAULT_ENABLED_CONTENT_TYPES,
value_type=schema.Choice(
vocabulary='plone.app.vocabularies.ReallyUserFriendlyTypes')
)

plugins_enabled = schema.Tuple(
title=_(u'Plugins'),
description=_(
u'help_enabled_plugins',
default=u'Please select which plugins will be used',
),
required=False,
default=DEFAULT_PLUGINS_ENABLED,
value_type=schema.Choice(vocabulary='sc.social.likes.plugins')
)

typebutton = schema.Choice(
title=_(u'Button style'),
description=_(
u'help_selected_buttons',
default=u'Choose your button style.',
),
required=True,
default=u'horizontal',
vocabulary=TypeButtonVocabulary,
)

do_not_track = schema.Bool(
title=_(u'Do not track users'),
description=_(
u'help_do_not_track',
default=u'If enabled, the site will not provide advanced sharing '
u'widgets , instead simple links will be used.\n'
u'This will limits user experience and features '
u'(like the share count) but will enhance users privacy: '
u'no 3rd party cookies will be sent to users.'
),
default=False,
)

model.fieldset(
'facebook',
label=u'Facebook',
fields=['fbaction', 'facebook_username', 'facebook_app_id', 'fbbuttons'],
)

fbaction = schema.Choice(
title=_(u'Verb to display'),
description=_(
u'help_verb_display',
default=u'The verb to display in the facebook button. '
u'Currently only "like" and "recommend" are '
u'supported.',
),
required=True,
default=u'like',
vocabulary=FacebookVerbsVocabulary,
)

facebook_username = schema.ASCIILine(
title=_(u'Admins'),
description=_(
u'help_admins',
default=u'A comma-separated list of either the '
u'Facebook IDs of page administrators.',
),
required=False,
default='',
)

facebook_app_id = schema.ASCIILine(
title=_(u'Application ID'),
description=_(
u'help_appid',
default=u'A Facebook Platform application ID.\n'
u'This is required when \"Do not track users\" option is enabled.',
),
required=False,
default='',
)

fbbuttons = schema.Tuple(
title=_(u'Facebook buttons'),
description=_(
u'help_fbbuttons',
default=u'Select buttons to be shown',
),
value_type=schema.Choice(vocabulary=FacebookButtonsVocabulary),
required=True,
default=(u'Like', ),
)

model.fieldset(
'twitter', label=u'Twitter', fields=['twitter_username'])

twitter_username = schema.ASCIILine(
title=_(u'Twitter nick'),
description=_(
u'help_your_twitter_nick',
default=u'Enter your twitter nick. eg. simplesconsultoria',
),
required=False,
default='',
)
19 changes: 9 additions & 10 deletions sc/social/like/plugins/facebook/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from sc.social.like.controlpanel import ISocialLikeSettings
from sc.social.like.plugins.facebook.controlpanel import ISocialLikeFacebookSettings
from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.plugins.facebook.utils import facebook_language
from sc.social.like.utils import get_content_image
from sc.social.like.utils import get_language
Expand Down Expand Up @@ -106,39 +105,39 @@ def typebutton(self):

@property
def fbaction(self):
record = ISocialLikeFacebookSettings.__identifier__ + '.fbaction'
record = ISocialLikeSettings.__identifier__ + '.fbaction'
try:
return api.portal.get_registry_record(record)
except InvalidParameterError:
return ''

@property
def fbapp_id(self):
record = ISocialLikeFacebookSettings.__identifier__ + '.fbapp_id'
def app_id(self):
record = ISocialLikeSettings.__identifier__ + '.facebook_app_id'
try:
return api.portal.get_registry_record(record)
except InvalidParameterError:
return ''

@property
def fbadmins(self):
record = ISocialLikeFacebookSettings.__identifier__ + '.fbadmins'
def admins(self):
record = ISocialLikeSettings.__identifier__ + '.facebook_username'
try:
return api.portal.get_registry_record(record)
except InvalidParameterError:
return ''

@property
def fbshow_like(self):
record = ISocialLikeFacebookSettings.__identifier__ + '.fbbuttons'
record = ISocialLikeSettings.__identifier__ + '.fbbuttons'
try:
return 'Like' in api.portal.get_registry_record(record)
except InvalidParameterError:
return False

@property
def fbshow_share(self):
record = ISocialLikeFacebookSettings.__identifier__ + '.fbbuttons'
record = ISocialLikeSettings.__identifier__ + '.fbbuttons'
try:
return 'Share' in api.portal.get_registry_record(record)
except InvalidParameterError:
Expand All @@ -165,7 +164,7 @@ def type(self):
def share_link(self):
absolute_url = self.context.absolute_url()
params = dict(
app_id=self.fbapp_id,
app_id=self.app_id,
display='popup',
href=absolute_url,
redirect_uri=absolute_url,
Expand Down
7 changes: 0 additions & 7 deletions sc/social/like/plugins/facebook/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
factory="sc.social.like.plugins.facebook.Facebook"
name="Facebook" />

<browser:page
name="facebook-config"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class="sc.social.like.plugins.facebook.controlpanel.SocialLikeFacebookSettingsControlPanel"
permission="cmf.ManagePortal"
/>

<!-- Metadata -->
<browser:page
name="facebook-plugin"
Expand Down
Loading

0 comments on commit a9207fa

Please sign in to comment.