[Zope3-checkins] CVS: Zope3/src/zope/app/schemacontent/browser -
__init__.py:1.1 configure.zcml:1.1 permission_edit.pt:1.1
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Mar 9 19:58:02 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/schemacontent/browser
In directory cvs.zope.org:/tmp/cvs-serv28963/src/zope/app/schemacontent/browser
Added Files:
__init__.py configure.zcml permission_edit.pt
Log Message:
Moved mutable schemas out of zope.app.utilities to zope.app.schema. Also,
seperated it from the mutable schema content definition/instance code, which
now lives in zope.app.schemacontent.
=== Added File Zope3/src/zope/app/schemacontent/browser/__init__.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Content Component Views
$Id: __init__.py,v 1.1 2004/03/10 00:58:00 srichter Exp $
"""
import copy
from zope.app import zapi
from zope.app.browser.form.add import AddView
from zope.app.browser.form.editview import EditView
from zope.app.browser.form.submit import Update
from zope.app.form.utility import setUpWidget
from zope.app.interfaces.form import IInputWidget
from zope.app.schemacontent.interfaces import IContentComponentDefinition
from zope.app.security.permission import PermissionField
from zope.app.services.servicenames import Utilities
from zope.app.schemacontent.content import ContentComponentInstance
from zope.component.exceptions import ComponentLookupError
from zope.interface import implements
from zope.publisher.interfaces import IPublishTraverse
from zope.schema import getFieldsInOrder
from zope.security.checker import CheckerPublic
from zope.security.proxy import trustedRemoveSecurityProxy
class ContentComponentPermissionEdit(EditView):
def __init__(self, context, request):
super(ContentComponentPermissionEdit, self).__init__(context, request)
self.buildPermissionWidgets()
def buildPermissionWidgets(self):
schema = self.context.schema
for name, field in getFieldsInOrder(schema):
# Try to get current settings
if self.context.permissions.has_key(name):
get_perm, set_perm = self.context.permissions[name]
else:
get_perm, set_perm = None, None
# Create the Accessor Permission Widget for this field
permField = PermissionField(
__name__=name+'_get_perm',
title=u"Accessor Permission",
default=CheckerPublic,
required=False)
setUpWidget(self, name+'_get_perm', permField, IInputWidget,
value=get_perm)
# Create the Mutator Permission Widget for this field
permField = PermissionField(
__name__=name+'_set_perm',
title=u"Mutator Permission",
default=CheckerPublic,
required=False)
setUpWidget(self, name+'_set_perm', permField, IInputWidget,
value=set_perm)
def update(self):
status = ''
if Update in self.request:
status = super(ContentComponentPermissionEdit, self).update()
self.buildPermissionWidgets()
elif 'CHANGE' in self.request:
schema = self.context.schema
perms = trustedRemoveSecurityProxy(self.context.permissions)
for name, field in getFieldsInOrder(schema):
getPerm = getattr(self, name+'_get_perm_widget').getData()
setPerm = getattr(self, name+'_set_perm_widget').getData()
perms[name] = (getPerm, setPerm)
status = 'Fields permissions mapping updated.'
return status
def getPermissionWidgets(self):
schema = self.context.schema
info = []
for name, field in getFieldsInOrder(schema):
field = trustedRemoveSecurityProxy(field)
info.append(
{'fieldName': name,
'fieldTitle': field.title,
'getter': getattr(self, name+'_get_perm_widget'),
'setter': getattr(self, name+'_set_perm_widget')} )
return info
class AddContentComponentInstanceView(AddView):
implements(IPublishTraverse)
def __init__(self, context, request):
self.context = context
self.request = request
def publishTraverse(self, request, name):
"""See zope.app.container.interfaces.IAdding"""
if '=' in name:
type_name, content_name = name.split("=", 1)
self.context.contentName = content_name
utilities = zapi.getService(self.context, Utilities)
matching = utilities.getRegisteredMatching(IContentComponentDefinition)
# We do the filtering by name separately, since the
# getRegisteredMatching() only does a string find, not an exact match,
# which we desire here.
print matching
matching = filter(lambda m: m[1] == type_name, matching)
if not (matching and matching[0][2].active()):
raise ComponentLookupError, \
"No Content Component Definition named '%s' found" %type_name
self.definition = matching[0][2].active().getComponent()
self.schema = self.definition.schema
self.label = 'Add %s' %self.definition.name
super(AddContentComponentInstanceView, self).__init__(self.context,
request)
return self.generated_form
def createAndAdd(self, data):
"""Create a Content Component Instance and add it to the container."""
schema = self.definition.schema
if self.definition.copySchema:
schema = copy.deepcopy(schema)
content = ContentComponentInstance(self.definition.name,
schema,
self.definition.permissions)
errors = []
for name, value in data.items():
field = self.schema[name]
try:
field.set(content, data[name])
except ValidationError:
errors.append(sys.exc_info()[1])
content = self.add(content)
if errors:
raise WidgetsError(*errors)
return content
class EditContentComponentInstanceView(EditView):
def __init__(self, context, request):
self.schema = context.getSchema()
self.label = 'Edit %s' %context.__name__
super(EditContentComponentInstanceView, self).__init__(context,
request)
=== Added File Zope3/src/zope/app/schemacontent/browser/configure.zcml ===
<zope:configure
xmlns:zope="http://namespaces.zope.org/zope"
xmlns="http://namespaces.zope.org/browser">
<!-- Content Component Definition -->
<addform
label="Content Component Definition Registration"
for= "zope.app.schemacontent.interfaces.IContentComponentDefinition"
name="addRegistration.html"
schema="zope.app.interfaces.services.utility.IUtilityRegistration"
class="zope.app.browser.services.utility.AddRegistration"
permission="zope.ManageServices"
content_factory="
zope.app.schemacontent.content.ContentComponentDefinitionRegistration"
arguments="name interface componentPath"
set_after_add="status"
fields="name interface componentPath permission status" />
<!-- Menu entry for "add component" menu -->
<menuItem
for="zope.app.container.interfaces.IAdding"
menu="add_component"
action="utility.ContentComponentDefinition"
title="Content Component Definition"
description="A Persistent Content Component Definition"
permission="zope.ManageServices"
/>
<!-- Menu entry for "Add Utility" menu -->
<addMenuItem
class="zope.app.schemacontent.content.ContentComponentDefinition"
title="Content Component Definition"
description="A Persistent Content Component Definition"
permission="zope.ManageServices"
/>
<editform
for="zope.app.schemacontent.interfaces.IContentComponentDefinition"
schema=
"zope.app.schemacontent.interfaces.IContentComponentDefinition"
name="edit.html"
fields="schema copySchema"
menu="zmi_views" title="Edit"
permission="zope.ManageContent"/>
<editform
for="zope.app.schemacontent.interfaces.IContentComponentDefinition"
schema=
"zope.app.schemacontent.interfaces.IContentComponentDefinition"
name="editpermissions.html"
template="permission_edit.pt"
class=".ContentComponentPermissionEdit"
menu="zmi_views" title="Define Permissions"
permission="zope.ManageContent"/>
<editform
for="zope.app.schemacontent.interfaces.IContentComponentDefinition"
schema="zope.app.schemacontent.interfaces.IContentComponentMenuItem"
name="menuItem.html"
menu="zmi_views" title="Menu Item"
fields="menuId interface create title description permission
filter_string"
permission="zope.ManageContent"/>
<defaultView
for="zope.app.schemacontent.interfaces.IContentComponentDefinition"
name="edit.html" />
<!-- Content Component Instance -->
<page
name="AddContentComponent"
for="zope.app.container.interfaces.IAdding"
permission="zope.ManageContent"
class=".AddContentComponentInstanceView"
attribute="generated_form" />
<page
name="edit.html"
menu="zmi_views" title="Edit"
for="zope.app.schemacontent.interfaces.IContentComponentInstance"
permission="zope.ManageContent"
class=".EditContentComponentInstanceView"
attribute="generated_form" />
<!-- Directives to test the Content Component Instance -->
<addform
label="New Content Component Instance"
name="AddContentComponentInstance.html"
schema="zope.app.schemacontent.interfaces.IContentComponentInstance"
permission="zope.ManageContent"
content_factory="zope.app.schemacontent.content.ContentComponentInstance"
arguments="__name__ __schema__"
fields="__name__ __schema__" />
<addMenuItem
class="zope.app.schemacontent.content.ContentComponentInstance"
title="Schema-based Content"
description="Schema-based Content Component Instance"
permission="zope.ManageContent"
view="AddContentComponentInstance.html"
/>
</zope:configure>
=== Added File Zope3/src/zope/app/schemacontent/browser/permission_edit.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body">
<p tal:define="status view/update"
tal:condition="status"
tal:content="status" />
<form action="./@@edit.html"
tal:attributes="action request/URL" method="POST">
<tal:block define="widgets view/getPermissionWidgets"
condition="widgets">
<h4 i18n:translate="">Map permissions to Schema fields</h4>
<tal:block repeat="widget widgets">
<h5 tal:content="string:${widget/fieldTitle} (${widget/fieldName})">
FieldName (Field Title)
</h5>
<div class="row" tal:replace="structure widget/getter/row">
<div class="label" i18n:translate="">Get Permission</div>
<div class="field">
</div>
</div>
<div class="row" tal:replace="structure widget/setter/row">
<div class="label" i18n:translate="">Set Permission</div>
<div class="field">
</div>
</div>
<br />
</tal:block>
<div class="row">
<div class="controls" style="width: 100%">
<input type="submit" value="Refresh"
i18n:attributes="value refresh-button" />
<input type="submit" value="Change" name="CHANGE"
i18n:attributes="value change-button" />
</div>
</div>
</tal:block>
</form>
</div>
</body>
</html>
More information about the Zope3-Checkins
mailing list