Skip to content

Commit

Permalink
more leftovers cleaned up (pep8 et al)
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Mar 11, 2015
1 parent 5283820 commit f214814
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 70 deletions.
32 changes: 17 additions & 15 deletions Products/PlonePAS/browser/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five"
i18n_domain="Five">
<configure
i18n_domain="Five"
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five">

<permission
id="PAS.SearchPrincipals"
title="Search for principals" />
id="PAS.SearchPrincipals"
title="Search for principals"
/>

<browser:page
allowed_interface="Products.PlonePAS.interfaces.browser.IPASInfoView"
class=".info.PASInfoView"
for="*"
name="pas_info"
class=".info.PASInfoView"
permission="zope2.View"
allowed_interface="Products.PlonePAS.interfaces.browser.IPASInfoView"
/>
/>

<browser:page
allowed_interface="Products.PlonePAS.interfaces.browser.IPASMemberView"
class=".member.PASMemberView"
for="*"
name="pas_member"
class=".member.PASMemberView"
permission="zope2.View"
allowed_interface="Products.PlonePAS.interfaces.browser.IPASMemberView"
/>
/>

<browser:page
allowed_interface="Products.PlonePAS.interfaces.browser.IPASSearchView"
class=".search.PASSearchView"
for="*"
name="pas_search"
class=".search.PASSearchView"
permission="zope2.View"
allowed_interface="Products.PlonePAS.interfaces.browser.IPASSearchView"
/>
/>

</configure>
9 changes: 5 additions & 4 deletions Products/PlonePAS/browser/info.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from zope.interface import implements
# -*- coding: utf-8 -*-
from zope.interface import implementer
from plone.memoize.instance import memoize

from Acquisition import aq_inner
from Products.PlonePAS.interfaces.browser import IPASInfoView
from Products.PluggableAuthService.interfaces.plugins import IExtractionPlugin
from Products.PluggableAuthService.interfaces.plugins \
import IExtractionPlugin, ILoginPasswordExtractionPlugin
import ILoginPasswordExtractionPlugin
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView


@implementer(IPASInfoView)
class PASInfoView(BrowserView):
implements(IPASInfoView)

def checkExtractorForInterface(self, interface):
acl = getToolByName(aq_inner(self.context), "acl_users")
Expand Down
23 changes: 14 additions & 9 deletions Products/PlonePAS/browser/member.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
from plone.memoize.instance import memoize
from zope.interface import implements
from zope.publisher.browser import BrowserView

# -*- coding: utf-8 -*-
from Products.CMFCore.utils import getToolByName

from Products.PlonePAS.interfaces.browser import IPASMemberView
from plone.memoize.instance import memoize
from zope.interface import implementer
from zope.publisher.browser import BrowserView


@implementer(IPASMemberView)
class PASMemberView(BrowserView):
implements(IPASMemberView)

@memoize
def info(self, userid=None):
pm = getToolByName(self.context, 'portal_membership')
result = pm.getMemberInfo(memberId=userid)
if result is None:
# No such member: removed? We return something useful anyway.
return {'username': userid, 'description': '', 'language': '',
'home_page': '', 'name_or_id': userid, 'location': '',
'fullname': ''}
return {
'username': userid,
'description': '',
'language': '',
'home_page': '',
'name_or_id': userid,
'location': '',
'fullname': ''
}
result['name_or_id'] = result.get('fullname') or \
result.get('username') or userid
return result
11 changes: 6 additions & 5 deletions Products/PlonePAS/browser/search.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from zope.interface import implements
from zope.component import queryUtility
from Products.Five import BrowserView
# -*- coding: utf-8 -*-
from Products.CMFCore.utils import getToolByName
from plone.i18n.normalizer.interfaces import IIDNormalizer
from Products.Five import BrowserView
from Products.PlonePAS.interfaces.browser import IPASSearchView
from plone.i18n.normalizer.interfaces import IIDNormalizer
from zope.component import queryUtility
from zope.interface import implementer


@implementer(IPASSearchView)
class PASSearchView(BrowserView):
implements(IPASSearchView)

@staticmethod
def extractCriteriaFromRequest(request):
Expand Down
2 changes: 2 additions & 0 deletions Products/PlonePAS/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
}

# Settings for member image resize quality
HAS_PIL = True
try:
from PIL import Image
PIL_SCALING_ALGO = Image.ANTIALIAS
except ImportError:
PIL_SCALING_ALGO = None
HAS_PIL = False

PIL_QUALITY = 88
MEMBER_IMAGE_SCALE = (75, 100)
Expand Down
84 changes: 51 additions & 33 deletions Products/PlonePAS/sheet.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
# -*- coding: utf-8 -*-
"""
Add Mutable Property Sheets and Schema Mutable Property Sheets to PAS
also a property schema type registry which is extensible.
"""

from types import StringTypes, IntType
from types import LongType, FloatType, InstanceType

from zope.component import getUtility
from zope.interface import implements

from DateTime.DateTime import DateTime
from Products.CMFCore.interfaces import ISiteRoot

from Products.PluggableAuthService.UserPropertySheet import _SequenceTypes
from Products.PluggableAuthService.UserPropertySheet import UserPropertySheet
from Products.PlonePAS.interfaces.propertysheets import IMutablePropertySheet
from Products.PluggableAuthService.UserPropertySheet import UserPropertySheet
from Products.PluggableAuthService.UserPropertySheet import _SequenceTypes
from zope.component import getUtility
from zope.interface import implementer


class PropertyValueError(ValueError):
Expand Down Expand Up @@ -48,38 +42,62 @@ def validate(self, property_type, value):
return inspector(value)

PropertySchema = PropertySchemaTypeMap()
PropertySchema.addType('string', lambda x: x is None or type(x) in StringTypes)
PropertySchema.addType('text', lambda x: x is None or type(x) in StringTypes)
PropertySchema.addType('boolean', lambda x: 1) # anything can be boolean
PropertySchema.addType('int', lambda x: x is None or type(x) is IntType)
PropertySchema.addType('long', lambda x: x is None or type(x) is LongType)
PropertySchema.addType('float', lambda x: x is None or type(x) is FloatType)
PropertySchema.addType('lines',
lambda x: x is None or type(x) in _SequenceTypes)
PropertySchema.addType('selection',
lambda x: x is None or type(x) in StringTypes)
PropertySchema.addType('multiple selection',
lambda x: x is None or type(x) in _SequenceTypes)
PropertySchema.addType('date',
lambda x: 1 or x is None \
or type(x) is InstanceType \
and isinstance(x, DateTime))
PropertySchema.addType(
'string',
lambda x: x is None or isinstance(x, basestring)
)
PropertySchema.addType(
'text',
lambda x: x is None or isinstance(x, basestring)
)
PropertySchema.addType(
'boolean',
lambda x: 1 # anything can be boolean
)
PropertySchema.addType(
'int',
lambda x: x is None or isinstance(x, int)
)
PropertySchema.addType(
'long',
lambda x: x is None or isinstance(x, long)
)
PropertySchema.addType(
'float',
lambda x: x is None or isinstance(x, float)
)
PropertySchema.addType(
'lines',
lambda x: x is None or isinstance(x, _SequenceTypes)
)
PropertySchema.addType(
'selection',
lambda x: x is None or isinstance(x, basestring)
)
PropertySchema.addType(
'multiple selection',
lambda x: x is None or isinstance(x, _SequenceTypes)
)
PropertySchema.addType(
'date',
lambda x: 1
)
validateValue = PropertySchema.validate


@implementer(IMutablePropertySheet)
class MutablePropertySheet(UserPropertySheet):

implements(IMutablePropertySheet)

def validateProperty(self, id, value):
if not id in self._properties:
if id not in self._properties:
raise PropertyValueError('No such property found on this schema')

proptype = self.getPropertyType(id)
if not validateValue(proptype, value):
raise PropertyValueError("Invalid value (%s) for "
"property '%s' of type %s"
% (value, id, proptype))
raise PropertyValueError(
"Invalid value (%s) for property '%s' of type %s" %
(value, id, proptype)
)

def setProperty(self, user, id, value):
self.validateProperty(id, value)
Expand Down
8 changes: 4 additions & 4 deletions Products/PlonePAS/tools/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from Products.CMFCore.permissions import View
from Products.CMFCore.utils import _checkPermission
from Products.CMFCore.utils import getToolByName
from Products.PlonePAS.config import HAS_PIL
from Products.PlonePAS.events import UserInitialLoginInEvent
from Products.PlonePAS.events import UserLoggedInEvent
from Products.PlonePAS.events import UserLoggedOutEvent
Expand Down Expand Up @@ -736,14 +737,13 @@ def getBadMembers(self):
portrait_data = str(portrait.data)
if portrait_data == '':
continue
try:
import PIL
except ImportError:
if not HAS_PIL:
raise RuntimeError(
'No Python Imaging Libraries (PIL) found. '
'Unable to validate profile image.'
'Unable to validate profile image. '
)
try:
import PIL
PIL.Image.open(StringIO(portrait_data))
except ConflictError:
pass
Expand Down

0 comments on commit f214814

Please sign in to comment.