1
##############################################################################
3
# Copyright (c) 2004 Zope Corporation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
13
##############################################################################
14
"""Home Folder related views.
18
__docformat__ = "reStructuredText"
20
from zope.schema.vocabulary import SimpleVocabulary
21
from zope.security.proxy import removeSecurityProxy
22
from zope.traversing.interfaces import TraversalError
23
from zope.traversing.api import getPath, getRoot, traverse
24
from zope.dottedname.resolve import resolve
26
from zope.app.form.browser import TextWidget, MultiSelectWidget
27
from zope.app.form.utility import setUpWidget
28
from zope.app.form.interfaces import IInputWidget
29
from zope.app.form.interfaces import ConversionError
30
from zope.app.homefolder.i18n import _
33
from zope.app.security.vocabulary import PrincipalSource
35
class PathWidget(TextWidget):
37
def _toFieldValue(self, input):
38
path = super(PathWidget, self)._toFieldValue(input)
39
root = getRoot(self.context.context)
41
proxy = traverse(root, path)
42
except TraversalError, e:
43
raise ConversionError(_('path is not correct !'), e)
45
return removeSecurityProxy(proxy)
47
def _toFormValue(self, value):
52
class DottedNameWidget(TextWidget):
53
""" Checks if the input is a resolvable class. """
54
def _toFieldValue(self, input):
56
objectToCreate = resolve(input)
57
except ImportError, e:
58
raise ConversionError(_('dotted name is not correct !'), e)
62
class AssignHomeFolder(object):
64
def setupWidgets(self):
65
self.principal_field = zope.schema.Choice(
66
__name__ = 'principal',
67
title=u'Principal Id',
68
source=PrincipalSource(),
71
self.folderName_field = zope.schema.TextLine(
72
__name__ = 'folderName',
76
self.selectedPrincipals_field = zope.schema.List(
77
__name__ = 'selectedPrincipals',
78
title=u'Existing Assignments',
79
value_type=zope.schema.Choice(
80
vocabulary=SimpleVocabulary.fromItems(
81
[('%s (%s)' %(key, value), key)
82
for key, value in self.context.assignments.items()]
86
setUpWidget(self, 'principal', self.principal_field, IInputWidget)
87
setUpWidget(self, 'folderName', self.folderName_field, IInputWidget)
88
self.selectedPrincipals_widget = MultiSelectWidget(
89
self.selectedPrincipals_field.bind(self),
90
self.selectedPrincipals_field.value_type.vocabulary,
92
self.selectedPrincipals_widget.setRenderedValue([])
97
if 'SUBMIT_ASSIGN' in self.request:
98
if not self.principal_widget.hasInput():
101
principal = self.principal_widget.getInputValue()
102
name = self.folderName_widget.getInputValue()
104
self.context.assignHomeFolder(principal, name)
106
return u'Home Folder assignment was successful.'
108
if 'SUBMIT_UNASSIGN' in self.request:
109
if not self.selectedPrincipals_widget.hasInput():
112
for id in self.selectedPrincipals_widget.getInputValue():
113
self.context.unassignHomeFolder(id)
116
return u'Principals were successfully unassigned.'