-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from bluedynamics/ticket_66
Fixes ticket #66 by implementing a PlonePAS plugin for properties.
- Loading branch information
Showing
13 changed files
with
205 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
from bda.plone.shop import permissions # nopep8 | ||
from bda.plone.shop.user.properties import UserPropertiesPASPlugin | ||
from Products.PluggableAuthService.PluggableAuthService import \ | ||
registerMultiPlugin | ||
from zope.i18nmessageid import MessageFactory | ||
|
||
|
||
message_factory = MessageFactory('bda.plone.shop') | ||
|
||
|
||
def initialize(context): | ||
""" | ||
Initializer called when used as a Zope 2 product. | ||
""" | ||
# Add to PAS menu | ||
registerMultiPlugin(UserPropertiesPASPlugin.meta_type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
from AccessControl.class_init import InitializeClass | ||
from Products.CMFPlone.utils import safe_unicode | ||
from Products.PluggableAuthService.interfaces.plugins import IPropertiesPlugin | ||
from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin | ||
from Products.PluggableAuthService.utils import classImplements | ||
from bda.plone.checkout.vocabularies import get_pycountry_name | ||
from zope.interface import implementer | ||
|
||
|
||
PAS_ID = 'bda.plone.shop' | ||
|
||
|
||
@implementer(IPropertiesPlugin) | ||
class UserPropertiesPASPlugin(BasePlugin): | ||
""" An implementer of IPropertiesPlugin which | ||
provides the method getPropertiesForUser, this method | ||
adds computed properties to PlonePAS which we remove | ||
at another place. | ||
""" | ||
|
||
meta_type = 'bda.plone.shop user properties' | ||
|
||
def __init__(self, id, title=None): | ||
self._setId(id) | ||
self.title = title | ||
|
||
def _getPropertSheetsFromUser(self, user): | ||
""" Get PropertySheets from a IPropertiedUser without | ||
the current sheet, so we dont have recursions. | ||
""" | ||
sheet_ids = user.listPropertysheets() | ||
|
||
result = [] | ||
for sheet_id in sheet_ids: | ||
if sheet_id != PAS_ID: | ||
result.append(user.getPropertysheet(sheet_id)) | ||
|
||
return result | ||
|
||
def getPropertiesForUser(self, user, request=None): | ||
""" This can't use plone.api.user.get(user.getId()) as it would | ||
lead to a recursion. | ||
""" | ||
|
||
sheets = self._getPropertSheetsFromUser(user) | ||
|
||
def getProperty(id, default): | ||
for sheet in sheets: | ||
if sheet.hasProperty(id): | ||
# Return the first one that has the property. | ||
return safe_unicode(sheet.getProperty(id)) | ||
|
||
return safe_unicode(default) | ||
|
||
first = getProperty('firstname', u'') | ||
last = getProperty('lastname', u'') | ||
street = getProperty('street', u'') | ||
zip_code = getProperty('zip', u'') | ||
city = getProperty('city', u'') | ||
country = getProperty('country', u'') | ||
|
||
try: | ||
country = country and get_pycountry_name(country) or '' | ||
except KeyError: | ||
country = '' | ||
|
||
join_list = [street, '{0} {1}'.format(zip_code, city), country] | ||
|
||
return { | ||
'fullname': u'%s%s%s' % ( | ||
first, | ||
first and last and u' ' or u'', | ||
last, | ||
), | ||
|
||
'location': u', '.join([it for it in join_list if it]), | ||
} | ||
|
||
classImplements(UserPropertiesPASPlugin, IPropertiesPlugin) | ||
InitializeClass(UserPropertiesPASPlugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters