[Zope3-checkins] CVS: Zope3/src/zope/app/browser/security - __init__.py:1.1.2.1 configure.zcml:1.1.2.1 permissionwidget.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:11 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/security
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/browser/security

Added Files:
      Tag: NameGeddon-branch
	__init__.py configure.zcml permissionwidget.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/browser/security/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/browser/security/configure.zcml ===

<zopeConfigure
   xmlns="http://namespaces.zope.org/zope"
   xmlns:browser="http://namespaces.zope.org/browser"
>

<browser:view 
	factory = ".PermissionWidget.SinglePermissionWidget"
	for = "Zope.App.Security.PermissionField.IPermissionField"
	name = "edit"
        />

<browser:view 
	factory = ".PermissionWidget.DisplayWidget"
	for = "Zope.App.Security.PermissionField.IPermissionField"
	name = "display"
        />

</zopeConfigure>


=== Added File Zope3/src/zope/app/browser/security/permissionwidget.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""Widget for selecting permissions.

$Id: permissionwidget.py,v 1.1.2.1 2002/12/23 19:31:10 jim Exp $
"""

from zope.app.interfaces.browser.form import IBrowserWidget
from Zope.App.Forms.Views.Browser import Widget
from zope.component import getService

class BaseWidget:

    def _convert(self, permission_id):
        if not permission_id:
            return None
        service = getService(self.context.context, "Permissions")
        return service.getPermission(permission_id)

    def _unconvert(self, permission):
        if permission is None:
            return None
        return permission.getId()

class SinglePermissionWidget(BaseWidget, Widget.BrowserWidget):    

    def __call__(self):
        search_name = self.name + ".search"
        search_string = self.request.form.get(search_name, '')

        service = getService(self.context.context, "Permissions")
        permissions = list(service.getPermissions())
        permissions.sort(lambda x,y: cmp(x.getId(), y.getId()))
        permissions = map(self._unconvert, permissions)
        if search_string:
            permissions = [permission
                           for permission in permissions
                           if permission.find(search_string)!=-1]
        permissions.sort()

        select_name = self.name
        selected = self._showData()
        
        options = ['<option value=\"\">---select permission---</option>']
        for permission in permissions:
            options.append('<option value="%s"%s>%s</option>'
                           % (permission,
                              permission == selected and ' selected' or '',
                              permission)
                           )
            

        search_field = '<input type="text" name="%s" value=\"%s\">' % (
            search_name, search_string)
        select_field = '<select name="%s">%s</select>'  % (
            select_name, ''.join(options))
        
        HTML = search_field + select_field
        return HTML

class DisplayWidget(BaseWidget, Widget.DisplayWidget):
    pass