[Zope3-checkins] CVS: Zope3/src/zope/app/utilities - add.pt:1.1.2.1
edit.pt:1.1.2.1 interfaces.py:1.1.2.1
mutableschemafield.py:1.1.2.1 configure.zcml:1.1.2.1
schema.py:1.1.2.1
Sidnei da Silva
sidnei at x3ng.com.br
Tue Aug 12 10:20:04 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/utilities
In directory cvs.zope.org:/tmp/cvs-serv22953/src/zope/app/utilities
Modified Files:
Tag: dreamcatcher-ttwschema-branch
configure.zcml schema.py
Added Files:
Tag: dreamcatcher-ttwschema-branch
add.pt edit.pt interfaces.py mutableschemafield.py
Log Message:
TTWSchema: Work in progress. Made a branch so I can work without disturbing everyone else
=== Added File Zope3/src/zope/app/utilities/add.pt ===
<html metal:use-macro="views/standard_macros/dialog">
<body>
<div metal:fill-slot="body">
<form action="action.html" method="post">
<table class="TypeListing" cellpadding="3">
<caption i18n:translate="">Add Content</caption>
<tbody tal:define="infos view/addingInfo">
<tr tal:repeat="info infos">
<td class="Selector">
<input type="radio" name="type_name"
tal:attributes="value info/action;
id info/action;
checked python:len(infos)==1" />
</td>
<td class="TypeName">
<label style="font-weight: bold;"
tal:attributes="for info/action">
<span tal:replace="info/title" >Folder</span>
</label>
<div class="TypeDescription" tal:content="info/description">
Folders are generic containers for content, including other
folders.
</div>
</td>
</tr>
<tr>
<td><br /></td>
<td>
<input type="text" name="id"
tal:condition="view/namesAccepted"
tal:attributes="value request/id | nothing" />
<input type="submit" value=" Add "
i18n:attributes="value add-button" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
</body>
</html>
=== Added File Zope3/src/zope/app/utilities/edit.pt ===
<html metal:use-macro="views/standard_macros/page">
<body>
<div metal:fill-slot="body">
<div metal:define-macro="body">
<form action="." tal:attributes="action request/URL" method="POST"
enctype="multipart/form-data">
<p tal:define="status view/update"
tal:condition="status"
tal:content="status" />
<p tal:condition="view/errors" i18n:translate="">
There are <strong tal:content="python:len(view.errors)"
i18n:name="num_errors">6</strong> input errors.
</p>
<tal:block repeat="error view/errors">
<div class="error" tal:content="error">error</div>
</tal:block>
<div metal:define-macro="formbody">
<table id="sortable" class="listing" summary="Content listing"
i18n:attributes="summary">
<thead>
<tr>
<th> </th>
<th i18n:translate="">Name</th>
<th i18n:translate="">Type</th>
<th i18n:translate="">Title</th>
<th i18n:translate="">Required</th>
<th i18n:translate="">Read-Only</th>
</tr>
</thead>
<tbody>
<tr tal:repeat="row view/fields">
<td><input type="checkbox" name="ids:list"
value=""
tal:attributes="value row/name" /></td>
<td><a href="#"
tal:attributes="href string:${request/URL/-1}/${row/name}"
tal:content="row/name">Name</a></td>
<td tal:content="row/type">Type</td>
<tal:block define="field row/field">
<td tal:content="field/title">Title</td>
<td tal:content="field/required">Required</td>
<td tal:content="field/readonly">Read-Only</td>
</tal:block>
</tr>
</tbody>
</table>
</div>
<div class="row">
<div class="controls">
<input type="submit" name="DELETE" value="Delete"
i18n:attributes="value delete-field-button" />
</div>
</div>
</form>
</div>
</div>
</body>
</html>
=== Added File Zope3/src/zope/app/utilities/interfaces.py ===
from zope.interface import Interface
from zope.app.utilities.mutableschemafield \
import MutableSchemaField, MutableSchemasField
class IMutableSchemaContent(Interface):
"""An interface for content that can choose a mutable schema
to be used for it"""
mutableschema = MutableSchemaField(title=u"Mutable Schema to use",
description=u"""Mutable Schema to use
as additional fields for this content
type"""
)
class IMutableSchemasContent(Interface):
"""An interface for content that can choose a mutable schema
to be used for it"""
mutableschemas = MutableSchemasField(title=u"Mutable Schemas to use",
description=u"""Mutable Schemas to use
as additional fields for this content
type"""
)
=== Added File Zope3/src/zope/app/utilities/mutableschemafield.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.
#
##############################################################################
"""
$Id: mutableschemafield.py,v 1.1.2.1 2003/08/12 13:19:27 sidnei Exp $
"""
from zope.schema import Enumerated, Field, Tuple
from zope.interface import Interface, implements
from zope.interface.interfaces import IInterface
from zope.interface import providedBy
from zope.schema.interfaces import ValidationError
from zope.app.interfaces.utilities import IMutableSchemaField, \
IMutableSchemasField
from zope.app.component.interfacefield import InterfaceField, InterfacesField
from zope.app.interfaces.utilities import IMutableSchema
class MutableSchemaField(InterfaceField):
__doc__ = IMutableSchemaField.__doc__
implements(IMutableSchemaField)
basetype = None
def __init__(self, basetype=IMutableSchema, *args, **kw):
# XXX Workaround for None indicating a missing value
if basetype is None:
kw['required'] = False
super(MutableSchemaField, self).__init__(basetype=basetype, *args, **kw)
def _validate(self, value):
basetype = self.basetype
if value is None and basetype is None:
return
if basetype is None:
basetype = IMutableSchema
if not IInterface.isImplementedBy(value):
raise ValidationError("Not an interface", value)
if basetype in providedBy(value):
return
if not value.extends(basetype, 0):
raise ValidationError("Does not extend", value, basetype)
class MutableSchemasField(InterfacesField):
__doc__ = IMutableSchemasField.__doc__
implements(IMutableSchemasField)
basetype = None
def __init__(self, basetype=IMutableSchema, default=(), *args, **kw):
# XXX Workaround for None indicating a missing value
if basetype is None:
kw['required'] = False
super(MutableSchemasField, self).__init__(basetype=basetype,
default=default, *args, **kw)
def _validate(self, value):
basetype = self.basetype
if value is () and basetype is None:
return
if basetype is None:
basetype = IMutableSchema
for v in value:
if not IInterface.isImplementedBy(v):
raise ValidationError("Not an interface", v)
for v in value:
if basetype in providedBy(v):
return
for v in value:
if not v.extends(basetype, 0):
raise ValidationError("Does not extend", v, basetype)
=== Zope3/src/zope/app/utilities/configure.zcml 1.1 => 1.1.2.1 ===
--- Zope3/src/zope/app/utilities/configure.zcml:1.1 Thu Aug 7 16:41:57 2003
+++ Zope3/src/zope/app/utilities/configure.zcml Tue Aug 12 09:19:27 2003
@@ -2,6 +2,24 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
+ <browser:menu
+ id="add_schema_field"
+ title="Menu of Fields to be added to a schema."/>
+
+ <browser:view
+ name="+"
+ for="zope.app.interfaces.utilities.IMutableSchema"
+ class="zope.app.utilities.schema.SchemaAdding"
+ permission="zope.ManageContent"
+ allowed_attributes="addingInfo"
+ menu="zmi_actions"
+ title="Add"
+ >
+ <browser:page name="index.html" template="add.pt" />
+ <browser:page name="action.html" attribute="action" />
+ </browser:view>
+
+
<content
class=".schema.SchemaUtility">
@@ -11,8 +29,6 @@
description="A Persistent Schema that can be edited through the web"
/>
- <allow attributes="__name__" />
-
<implements
interface="zope.app.interfaces.services.utility.ILocalUtility" />
@@ -21,7 +37,12 @@
<require
permission="zope.ManageServices"
- interface="zope.app.interfaces.schemagen.ISchemaSpec"
+ interface="zope.app.interfaces.utilities.IMutableSchema"
+ />
+
+ <require
+ permission="zope.ManageServices"
+ set_schema="zope.app.interfaces.utilities.ISchemaUtility"
/>
</content>
@@ -46,5 +67,51 @@
description="A Persistent Schema that can be edited through the web"
permission="zope.ManageServices"
/>
+
+ <browser:page
+ name="editschema.html"
+ menu="zmi_views" title="Edit Schema"
+ for="zope.app.interfaces.utilities.IMutableSchema"
+ permission="zope.ManageServices"
+ class="zope.app.utilities.schema.EditSchema"
+ attribute="edit"
+ />
+
+
+ <!-- Widgets for the MutableSchemaField -->
+
+ <browser:page
+ class="zope.app.browser.component.interfacewidget.InterfaceWidget"
+ for="zope.app.interfaces.utilities.IMutableSchemaField"
+ name="edit"
+ permission="zope.Public" />
+
+ <browser:page
+ class="zope.app.browser.component.interfacewidget.InterfaceDisplayWidget"
+ for="zope.app.interfaces.utilities.IMutableSchemaField"
+ name="display"
+ permission="zope.Public" />
+
+ <browser:page
+ class="zope.app.browser.component.interfacewidget.MultiInterfaceWidget"
+ for="zope.app.interfaces.utilities.IMutableSchemasField"
+ name="edit"
+ permission="zope.Public" />
+
+ <browser:page
+ class="
+ zope.app.browser.component.interfacewidget.MultiInterfaceDisplayWidget"
+ for="zope.app.interfaces.utilities.IMutableSchemasField"
+ name="display"
+ permission="zope.Public" />
+
+ <browser:editform
+ schema="zope.app.utilities.interfaces.IMutableSchemaContent"
+ name="setschema.html"
+ menu="zmi_views"
+ label="Set Schema"
+ title="Set Schema"
+ permission="zope.ManageContent"
+ />
</configure>
=== Zope3/src/zope/app/utilities/schema.py 1.1 => 1.1.2.1 ===
--- Zope3/src/zope/app/utilities/schema.py:1.1 Thu Aug 7 16:41:57 2003
+++ Zope3/src/zope/app/utilities/schema.py Tue Aug 12 09:19:27 2003
@@ -1,11 +1,21 @@
+from zope.app import zapi
from zope.interface import implements
from zope.app.services.interface import PersistentInterfaceClass
-from zope.app.interfaces.utilities import IMutableSchema
+from zope.app.services.interface import PersistentInterface
+from zope.app.interfaces.utilities import IMutableSchema, ISchemaUtility
from zope.schema import getFieldsInOrder, getFieldNamesInOrder
+from zope.publisher.browser import BrowserView
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.app.browser.container.adding import Adding
+from zope.app.interfaces.utilities import ISchemaAdding
+from zope.app.browser.form.editview import EditView
class SchemaUtility(PersistentInterfaceClass):
- implements(IMutableSchema)
+ implements(IMutableSchema, ISchemaUtility)
+
+ def __init__(self, name='SchemaUtility'):
+ super(SchemaUtility, self).__init__(name, (PersistentInterface,))
def addField(self, name, field):
"""Add a field to schema.
@@ -78,7 +88,65 @@
return self._InterfaceClass__attrs[name]
def _setField(self, name, field):
+ if not field.__name__:
+ field.__name__ = name
self._InterfaceClass__attrs[name] = field
def _delField(self, name):
del self._InterfaceClass__attrs[name]
+
+
+class EditSchema(BrowserView):
+
+ edit = ViewPageTemplateFile('edit.pt')
+ errors = ()
+ update_status = None
+
+ def fieldNames(self):
+ return getFieldNamesInOrder(self.context)
+
+ def fields(self):
+ return [{'name':name,
+ 'field':zapi.ContextWrapper(field, self.context),
+ 'type':field.__class__.__name__}
+ for name, field in getFieldsInOrder(self.context)]
+
+ def update(self):
+
+ status = ''
+
+ container = zapi.getAdapter(self.context, IMutableSchema)
+
+ if 'DELETE' in self.request:
+ if not 'ids' in self.request:
+ self.errors = ("Must select a field to delete",)
+ status = "An error occured"
+ for id in self.request.get('ids', []):
+ container.removeField(id)
+
+ self.update_status = status
+ return status
+
+class EditMutableSchema(EditView):
+
+ def _get_schema(self):
+ return self.context.mutableschema
+
+ schema = property(_get_schema)
+
+class SchemaAdding(Adding):
+
+ implements(ISchemaAdding)
+
+ menu_id = "add_schema_field"
+
+ def add(self, content):
+ name = self.contentName
+ container = zapi.getAdapter(self.context, IMutableSchema)
+ container.addField(name, content)
+ return zapi.ContextWrapper(content, container, name=name)
+
+ def nextURL(self):
+ """See zope.app.interfaces.container.IAdding"""
+ return (str(zapi.getView(self.context, "absolute_url", self.request))
+ + '/@@editschema.html')
More information about the Zope3-Checkins
mailing list