Skip to content

Commit

Permalink
Merge 5001a7f into 9f0cf9d
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Jun 8, 2016
2 parents 9f0cf9d + 5001a7f commit 7a8a06d
Show file tree
Hide file tree
Showing 55 changed files with 730 additions and 879 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ There's a frood who really knows where his towel is.
2.4.2 (unreleased)
^^^^^^^^^^^^^^^^^^

- Nothing changed yet.
- Use Plone's registry instead of the ``portal_properties`` tool to store package configuration (closes `#1`_).
[hvelarde]


2.4.1 (2015-12-10)
Expand Down Expand Up @@ -276,6 +277,7 @@ There's a frood who really knows where his towel is.

* Initial release [cleberjsantos]

.. _`#1`: https://github.com/collective/sc.social.like/issues/1
.. _`#15`: https://github.com/collective/sc.social.like/pull/15
.. _`#36`: https://github.com/collective/sc.social.like/issues/36
.. _`#38`: https://github.com/collective/sc.social.like/issues/38
Expand Down
9 changes: 0 additions & 9 deletions sc/social/like/Extensions/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@
from plone import api


def remove_properties(portal):
portal_properties = api.portal.get_tool(name='portal_properties')
try:
portal_properties.manage_delObjects(ids='sc_social_likes_properties')
except KeyError:
pass


def uninstall(portal, reinstall=False):
if not reinstall:
remove_properties(portal)
profile = 'profile-%s:uninstall' % PROJECTNAME
setup_tool = api.portal.get_tool(name='portal_setup')
setup_tool.runAllImportStepsFromProfile(profile)
Expand Down
7 changes: 7 additions & 0 deletions sc/social/like/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@
permission="zope.Public"
/>

<browser:page
name="sociallike-settings"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class="sc.social.like.controlpanel.SocialLikeSettingsControlPanel"
permission="cmf.ManagePortal"
/>

</configure>
12 changes: 7 additions & 5 deletions sc/social/like/browser/helper.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-

from Acquisition import aq_inner
from Products.Five import BrowserView
from plone.app.layout.globals.interfaces import IViewView
from plone.memoize.view import memoize
from plone.memoize.view import memoize_contextless
from sc.social.like.controlpanel.likes import LikeControlPanelAdapter
from plone.registry.interfaces import IRegistry
from Products.Five import BrowserView
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
from zope.component import getUtilitiesFor
from zope.component import getUtility
from zope.interface import implements


Expand All @@ -30,8 +31,9 @@ def __init__(self, context, request, *args, **kwargs):

@memoize_contextless
def configs(self):
adapter = LikeControlPanelAdapter(self.portal)
return adapter
registry = getUtility(IRegistry)
settings = registry.forInterface(ISocialLikeSettings)
return settings

@memoize_contextless
def enabled_portal_types(self):
Expand Down
41 changes: 15 additions & 26 deletions sc/social/like/browser/socialikes.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from plone import api
from plone.api.exc import InvalidParameterError
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName

from zope.interface import implements
from zope.i18nmessageid import MessageFactory

from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.interfaces import ISocialLikes

_ = MessageFactory('sc.social.like')
from zope.interface import implements


class SocialLikes(BrowserView):
"""
"""
implements(ISocialLikes)

enabled_portal_types = []
implements(ISocialLikes)

def __init__(self, context, request, *args, **kwargs):
super(SocialLikes, self).__init__(context, request, *args, **kwargs)
context = aq_inner(context)
def __init__(self, context, request):
self.context = context
pp = getToolByName(context, 'portal_properties')
self.sheet = getattr(pp, 'sc_social_likes_properties', None)
if self.sheet:
self.enabled_portal_types = self.sheet.getProperty(
'enabled_portal_types'
)
self.request = request

@property
def enabled(self):
"""Validates if social bookmarks should be enabled
for this context"""
context = self.context
enabled_portal_types = self.enabled_portal_types
return context.portal_type in enabled_portal_types
"""Validates if social bookmarks should be enabled in this context."""
record = ISocialLikeSettings.__identifier__ + '.enabled_portal_types'
try:
enabled_portal_types = api.portal.get_registry_record(record)
except InvalidParameterError:
enabled_portal_types = []

return self.context.portal_type in enabled_portal_types
21 changes: 13 additions & 8 deletions sc/social/like/browser/viewlets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# -*- coding:utf-8 -*-
from plone import api
from plone.api.exc import InvalidParameterError
from plone.app.layout.viewlets import ViewletBase
from plone.memoize.view import memoize
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from sc.social.like.interfaces import ISocialLikeSettings
from zope.component import getMultiAdapter
from plone.memoize.view import memoize


class BaseLikeViewlet(ViewletBase):
Expand Down Expand Up @@ -74,17 +77,19 @@ class SocialLikesViewlet(BaseLikeViewlet):

@property
def render_method(self):
tools = getMultiAdapter((self.context, self.request),
name=u'plone_tools')
site_properties = tools.properties()
# global cookie settings for privacy level
if self.request.cookies.get('social-optout', None) == 'true' or \
self.request.get_header('HTTP_DNT') == '1':
return 'link'

# site specific privacy level check
if getattr(site_properties, 'sc_social_likes_properties', None) \
and getattr(site_properties.sc_social_likes_properties,
'do_not_track', None) and \
site_properties.sc_social_likes_properties.do_not_track:
record = ISocialLikeSettings.__identifier__ + '.do_not_track'
try:
do_not_track = api.portal.get_registry_record(record)
except InvalidParameterError:
do_not_track = False

if do_not_track:
return 'link'

return 'plugin'
3 changes: 3 additions & 0 deletions sc/social/like/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
__docformat__ = 'plaintext'

PROJECTNAME = 'sc.social.like'

DEFAULT_ENABLED_CONTENT_TYPES = ('Document', 'Event', 'News Item')
DEFAULT_PLUGINS_ENABLED = ('Facebook', 'Twitter')
3 changes: 1 addition & 2 deletions sc/social/like/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

<five:registerPackage package="." />

<include zcml:condition="have plone-4" package="Products.CMFCore" file="permissions.zcml" />
<include package="Products.CMFCore" file="permissions.zcml" />

<include file="profiles.zcml" />
<include package=".browser" />
<include package=".controlpanel" />
<include package=".plugins" />

<i18n:registerTranslations directory="locales" />
Expand Down
20 changes: 20 additions & 0 deletions sc/social/like/controlpanel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding:utf-8 -*-
from plone.app.registry.browser import controlpanel
from sc.social.like import LikeMessageFactory as _
from sc.social.like.interfaces import ISocialLikeSettings


class SocialLikeSettingsEditForm(controlpanel.RegistryEditForm):

"""Control panel edit form."""

schema = ISocialLikeSettings
label = _(u'Social Like')
description = _(u'Settings for the sc.social.like package')


class SocialLikeSettingsControlPanel(controlpanel.ControlPanelFormWrapper):

"""Control panel form wrapper."""

form = SocialLikeSettingsEditForm
1 change: 0 additions & 1 deletion sc/social/like/controlpanel/__init__.py

This file was deleted.

14 changes: 0 additions & 14 deletions sc/social/like/controlpanel/configure.zcml

This file was deleted.

Loading

0 comments on commit 7a8a06d

Please sign in to comment.