Hello,
I've been assigned to present Zope in a local upcoming Python user group
meeting. As part of the assignment, I'm supposed to solve the PyWebOff
challenge using Zope:
http://pyre.third-bit.com/pyweb/challenge.html
I'd like to do this using Zope 3. However, I'm really struggling. I
feel like I must be using Zope 3 in a really dumb way, because the code
so far is highly repetitive, completely dependent on Zope, and more XML
than Python. This is not going to go over well in the presentation.
Can anyone tell me how to do this better with Zope 3? Maybe my Zope 2
experience is preventing me from seeing something obvious. I've
attached the __init__.py and configure.zcml that I created in a package
called "challenge".
Shane
from zope.interface import Interface, implements
from zope.schema import Field, TextLine, Int, Date
from zope.app.container.interfaces import IContained, IContainer
from zope.app.container.constraints import ItemTypePrecondition
from zope.app.container.constraints import ContainerTypesConstraint
from zope.app.container.btree import BTreeContainer
class IBook(Interface):
title = TextLine(title=u'title')
year = Int(title=u'year')
authors = TextLine(title=u'authors')
class ILoan(Interface):
username = TextLine(title=u'username')
day = Date(title=u'day')
class ILibrary(IContainer):
def __setitem__(name, object):
pass
__setitem__.precondition = ItemTypePrecondition(IBook, ILoan)
class IBookContained(IContained):
__parent__ = Field(
constraint = ContainerTypesConstraint(ILibrary))
class ILoanContained(IContained):
__parent__ = Field(
constraint = ContainerTypesConstraint(ILibrary))
class Book(object):
implements(IBook, IBookContained)
class Loan(object):
implements(ILoan, ILoanContained)
class Library(BTreeContainer):
implements(ILibrary)
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<content class=".Book">
<require
permission="zope.View"
interface=".IBook"
/>
<require
permission="zope.ManageContent"
set_schema=".IBook"
/>
</content>
<content class=".Loan">
<require
permission="zope.ManageContent"
interface=".ILoan"
/>
<require
permission="zope.ManageContent"
set_schema=".ILoan"
/>
</content>
<content class=".Library">
<require
permission="zope.ManageContent"
interface=".ILibrary"
/>
<require
permission="zope.ManageContent"
set_schema=".ILibrary"
/>
</content>
<browser:addform
name="addlibrary"
schema=".ILibrary"
content_factory=".Library"
permission="zope.ManageContent"
/>
<browser:addMenuItem
class=".Library"
permission="zope.ManageContent"
view="addlibrary"
title="Library"
/>
<browser:containerViews
for=".ILibrary"
index="zope.View"
contents="zope.View"
add="zope.ManageContent"
/>
<browser:addform
name="addbook"
schema=".IBook"
content_factory=".Book"
permission="zope.ManageContent"
/>
<browser:addMenuItem
class=".Book"
permission="zope.ManageContent"
view="addbook"
title="Book"
/>
<browser:editform
schema=".IBook"
permission="zope.ManageContent"
menu="zmi_views"
title="Edit"
name="edit"
/>
<browser:addform
name="addloan"
schema=".ILoan"
content_factory=".Loan"
permission="zope.ManageContent"
/>
<browser:addMenuItem
class=".Loan"
permission="zope.ManageContent"
view="addloan"
title="Loan"
/>
<browser:editform
schema=".ILoan"
permission="zope.ManageContent"
menu="zmi_views"
title="Edit"
name="edit"
/>
</configure>
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users