[Zope3-checkins] CVS: Zope3/src/zope/app/utilities -
instance.zcml:1.1.2.1 configure.zcml:1.1.2.6 instance.py:1.1.2.2
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Aug 13 15:31:14 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/utilities
In directory cvs.zope.org:/tmp/cvs-serv13216/utilities
Modified Files:
Tag: dreamcatcher-ttwschema-branch
configure.zcml instance.py
Added Files:
Tag: dreamcatcher-ttwschema-branch
instance.zcml
Log Message:
This is the start of on-the-fly object types.
=== Added File Zope3/src/zope/app/utilities/instance.zcml ===
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<content class=".instance.DocumentInstance">
<implements
interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
</content>
<browser:page
name="edit.html"
menu="zmi_views" title="Edit"
for=".instance.IDocumentInstance"
permission="zope.ManageContent"
class=".instance.EditDocumentView"
attribute="generated_form" />
<!-- Directives to test the Document Instance -->
<browser:addform
label="New Document"
name="AddDocument"
schema=".instance.IDocumentInstance"
permission="zope.ManageContent"
content_factory=".instance.DocumentInstance"
arguments="__name__ __schema__"
fields="__name__ __schema__"
menu="add_content" title="Schema Document"/>
</configure>
=== Zope3/src/zope/app/utilities/configure.zcml 1.1.2.5 => 1.1.2.6 ===
--- Zope3/src/zope/app/utilities/configure.zcml:1.1.2.5 Wed Aug 13 11:44:05 2003
+++ Zope3/src/zope/app/utilities/configure.zcml Wed Aug 13 14:31:08 2003
@@ -164,4 +164,6 @@
class=".traversal.SchemaFieldTraverser"
permission="zope.Public" />
+ <include file="instance.zcml" />
+
</configure>
=== Zope3/src/zope/app/utilities/instance.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/utilities/instance.py:1.1.2.1 Wed Aug 13 13:27:46 2003
+++ Zope3/src/zope/app/utilities/instance.py Wed Aug 13 14:31:08 2003
@@ -19,15 +19,39 @@
from persistence import Persistent
from persistence.dict import PersistentDict
+from zope.app.component.interfacefield import InterfaceField
from zope.context import ContextMethod
-from zope.interface import directlyProvides, implements
-from zope.schema import getFields
+from zope.interface import directlyProvides, implements, Interface
+from zope.schema import getFields, TextLine
from zope.security.checker import CheckerPublic, Checker, defineChecker
-class ContentObjectInstance(Persistent):
- def __init__(self, schema=None, schemaPermissions=None):
- super(ContentObjectInstance, self).__init__()
+class IDocumentInstance(Interface):
+ """Interface describing a Conten Object Instance"""
+
+ __name__ = TextLine(
+ title=u"Name of Document Type",
+ description=u"""This is the name of the document type.""",
+ required=True)
+
+ __schema__ = InterfaceField(
+ title=u"Schema",
+ description=u"Specifies the schema that characterizes the document.",
+ required=True)
+
+
+class DocumentInstance(Persistent):
+
+ implements(IDocumentInstance)
+
+ def __init__(self, name, schema, schemaPermissions=None):
+ super(DocumentInstance, self).__init__()
+
+ # Save the name of the object
+ self.__name__ = name
+
+ # XXX: We really should make a copy of the schema first, so that it
+ # cannot be changed.
self.__schema = schema
# Add the new attributes, if there was a schema passed in
if schema is not None:
@@ -36,6 +60,8 @@
directlyProvides(self, schema)
# Build up a Checker rules and store it for later
+ if schemaPermissions is None:
+ schemaPermissions = {}
self.__checker_getattr = PersistentDict()
self.__checker_setattr = PersistentDict()
for name in getFields(schema):
@@ -48,18 +74,17 @@
def __setattr__(self, key, value):
- if key in ('_ContentObjectInstance__schema',
- '_ContentObjectInstance__checker_getattr',
- '_ContentObjectInstance__checker_setattr',
- 'getChecker', 'getSchema') or \
- key.startswith('_p_'):
- return super(ContentObjectInstance, self).__setattr__(key, value)
+ if (key in ('getSchema',) or
+ key.startswith('_p_') or
+ key.startswith('__') or
+ key.startswith('_DocumentInstance__')):
+ return super(DocumentInstance, self).__setattr__(key, value)
is_schema_field = self.__schema is not None and \
key in getFields(self.__schema).keys()
if is_schema_field:
- super(ContentObjectInstance, self).__setattr__(key, value)
+ super(DocumentInstance, self).__setattr__(key, value)
else:
raise AttributeError, 'Attribute not available'
@@ -69,15 +94,25 @@
def getSchema(self):
return self.__schema
+ def __repr__(self):
+ return '<DocumentInstance called %s>' %self.__name__
+
-def ContentObjectInstanceChecker(instance):
+def DocumentInstanceChecker(instance):
"""A function that can be registered as a Checker in defineChecker()"""
return Checker(instance.__checker_getattr.get,
instance.__checker_setattr.get)
-defineChecker(ContentObjectInstance, ContentObjectInstanceChecker)
+defineChecker(DocumentInstance, DocumentInstanceChecker)
+
+
+from zope.app.browser.form.editview import EditView
+
+class EditDocumentView(EditView):
+
+ def __init__(self, context, request):
+ self.schema = context.getSchema()
+ self.label = 'Edit %s' %context.__name__
+ super(EditDocumentView, self).__init__(context, request)
-class EditContentObject:
- pass
-
More information about the Zope3-Checkins
mailing list