[Zope3-checkins] CVS: Zope3/src/zope/app/browser/security - __init__.py:1.2 configure.zcml:1.2 permissionwidget.py:1.2
Jim Fulton
jim@zope.com
Wed, 25 Dec 2002 09:14:05 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/security
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/browser/security
Added Files:
__init__.py configure.zcml permissionwidget.py
Log Message:
Grand renaming:
- Renamed most files (especially python modules) to lower case.
- Moved views and interfaces into separate hierarchies within each
project, where each top-level directory under the zope package
is a separate project.
- Moved everything to src from lib/python.
lib/python will eventually go away. I need access to the cvs
repository to make this happen, however.
There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.
=== Zope3/src/zope/app/browser/security/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:14:05 2002
+++ Zope3/src/zope/app/browser/security/__init__.py Wed Dec 25 09:12:34 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
=== Zope3/src/zope/app/browser/security/configure.zcml 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:14:05 2002
+++ Zope3/src/zope/app/browser/security/configure.zcml Wed Dec 25 09:12:34 2002
@@ -0,0 +1,20 @@
+<zopeConfigure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ >
+
+ <browser:view
+ factory = ".permissionwidget.SinglePermissionWidget"
+ for = "zope.app.interfaces.security.IPermissionField"
+ name = "edit"
+ />
+
+ <browser:view
+ factory = ".permissionwidget.DisplayWidget"
+ for = "zope.app.interfaces.security.IPermissionField"
+ name = "display"
+ />
+
+ <include package=".grants" />
+
+</zopeConfigure>
=== Zope3/src/zope/app/browser/security/permissionwidget.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:14:05 2002
+++ Zope3/src/zope/app/browser/security/permissionwidget.py Wed Dec 25 09:12:34 2002
@@ -0,0 +1,73 @@
+##############################################################################
+#
+# 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$
+"""
+
+from zope.app.interfaces.browser.form import IBrowserWidget
+from zope.app.browser.form 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