[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/homefolder/ Make the
HomeFolderManager more configurable. You can know specify the
class that is being created as a homefolder.
Florian Lindner
Florian.Lindner at xgm.de
Tue Jan 24 17:36:18 EST 2006
Log message for revision 41424:
Make the HomeFolderManager more configurable. You can know specify the class that is being created as a homefolder.
Changed:
U Zope3/trunk/src/zope/app/homefolder/README.txt
U Zope3/trunk/src/zope/app/homefolder/browser.py
U Zope3/trunk/src/zope/app/homefolder/configure.zcml
U Zope3/trunk/src/zope/app/homefolder/homefolder.py
U Zope3/trunk/src/zope/app/homefolder/interfaces.py
-=-
Modified: Zope3/trunk/src/zope/app/homefolder/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/homefolder/README.txt 2006-01-24 16:35:19 UTC (rev 41423)
+++ Zope3/trunk/src/zope/app/homefolder/README.txt 2006-01-24 22:36:17 UTC (rev 41424)
@@ -137,7 +137,7 @@
>>> homeFolder = manager.getHomeFolder('dreamcatcher')
>>> homeFolder is None
True
-
+
However, if autoCreateAssignment is True and you try to get a home folder
of a principal which has no assignment, the assignment and the folder
will be automatically created. The folder will always be created, regardless
@@ -151,6 +151,22 @@
>>> 'florian' in baseFolder
True
+Sometimes you want to create a homefolder which is not a zope.app.Folder.
+You can change the object type that is being created by changing the
+containerObject property. It defaults to 'zope.app.folder.Folder'.
+Let's create a homefile.
+
+ >>> manager.containerObject = 'zope.app.file.File'
+ >>> manager.assignHomeFolder('fileuser', create=True)
+ >>> homeFolder = manager.getHomeFolder('fileuser')
+ >>> print homeFolder #doctest: +ELLIPSIS
+ <zope.app.file.file.File object at ...>
+
+ You see that now a File object has been created. We reset containerObject
+ to zope,folder.Folder to not confuse the follow tests.
+
+ >>> manager.containerObject = 'zope.folder.Folder'
+
Accessing the Home Folder
-------------------------
Modified: Zope3/trunk/src/zope/app/homefolder/browser.py
===================================================================
--- Zope3/trunk/src/zope/app/homefolder/browser.py 2006-01-24 16:35:19 UTC (rev 41423)
+++ Zope3/trunk/src/zope/app/homefolder/browser.py 2006-01-24 22:36:17 UTC (rev 41424)
@@ -29,6 +29,8 @@
from zope.app.security.vocabulary import PrincipalSource
from zope.app.traversing.interfaces import TraversalError
+from zope.dottedname.resolve import resolve
+
class PathWidget(TextWidget):
def _toFieldValue(self, input):
@@ -45,8 +47,17 @@
if value is None:
return ''
return zapi.getPath(value)
-
-
+
+class DottedNameWidget(TextWidget):
+ """ Checks if the input is a resolvable class. """
+ def _toFieldValue(self, input):
+ try:
+ objectToCreate = resolve(input)
+ except ImportError, e:
+ raise ConversionError(_('dotted name is not is not correct !'), e)
+ else:
+ return input
+
class AssignHomeFolder(object):
def setupWidgets(self):
Modified: Zope3/trunk/src/zope/app/homefolder/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/homefolder/configure.zcml 2006-01-24 16:35:19 UTC (rev 41423)
+++ Zope3/trunk/src/zope/app/homefolder/configure.zcml 2006-01-24 22:36:17 UTC (rev 41424)
@@ -40,6 +40,10 @@
field="homeFolderBase"
class=".browser.PathWidget" />
+ <browser:widget
+ field="containerObject"
+ class=".browser.DottedNameWidget" />
+
</browser:addform>
<browser:addMenuItem
@@ -60,6 +64,11 @@
field="homeFolderBase"
class=".browser.PathWidget" />
+ <browser:widget
+ field="containerObject"
+ class=".browser.DottedNameWidget" />
+
+
</browser:editform>
<browser:page
Modified: Zope3/trunk/src/zope/app/homefolder/homefolder.py
===================================================================
--- Zope3/trunk/src/zope/app/homefolder/homefolder.py 2006-01-24 16:35:19 UTC (rev 41423)
+++ Zope3/trunk/src/zope/app/homefolder/homefolder.py 2006-01-24 22:36:17 UTC (rev 41424)
@@ -23,8 +23,8 @@
from zope.app import zapi
from zope.app.container.contained import Contained
-from zope.app.folder import Folder
from zope.app.securitypolicy.interfaces import IPrincipalRoleManager
+from zope.dottedname.resolve import resolve
from zope.app.homefolder.interfaces import IHomeFolder, IHomeFolderManager
@@ -37,6 +37,7 @@
createHomeFolder = True
autoCreateAssignment = False
homeFolderRole = u'zope.Manager'
+ containerObject = u'zope.app.folder.Folder'
def __init__(self):
self.assignments = OOBTree()
@@ -52,7 +53,8 @@
# Create a home folder instance, if the correct flags are set.
if (create is True) or (create is None and self.createHomeFolder):
if name not in self.homeFolderBase:
- self.homeFolderBase[name] = Folder()
+ objectToCreate = resolve(self.containerObject)
+ self.homeFolderBase[name] = objectToCreate()
principal_roles = IPrincipalRoleManager(self.homeFolderBase[name])
principal_roles.assignRoleToPrincipal(
self.homeFolderRole, principalId)
Modified: Zope3/trunk/src/zope/app/homefolder/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/homefolder/interfaces.py 2006-01-24 16:35:19 UTC (rev 41423)
+++ Zope3/trunk/src/zope/app/homefolder/interfaces.py 2006-01-24 22:36:17 UTC (rev 41424)
@@ -63,6 +63,15 @@
vocabulary="Role Ids",
default=u'zope.Manager'
)
+
+ containerObject = Field(
+ title=_("Container Type to create"),
+ description=_("The container type that will be created upon first "
+ "call of getHomeFolder (if autoCreate is on)"),
+ required=True,
+ default=u'zope.app.folder.Folder'
+ )
+
def assignHomeFolder(principalId, folderName=None, create=None):
"""Assigns a particular folder as the home folder of a principal.
More information about the Zope3-Checkins
mailing list