I'm converting from formlib to z3c.form. What should my configure.zcml look like?

For formlib it is:

 <browser:page
   for="zope.app.container.interfaces.IAdding"
   name=".Person"
   class=".browser.PersonAddForm"
   permission="zope.ManageContent"
   />

I assume the 'for=' value should change, but to what? Complete code is attached (with non-Person classes still using formlib).

Thanks,
John

from interfaces import IPerson, IDriver, ICar, ILimosvc, ILimosvcContained
from classes import Person, Driver, Car
from zope.formlib import form
from z3c.form import form as z3cform, field as z3cfield


class PersonEdit(z3cform.EditForm):
        form_fields = z3cfield.Fields(IPerson)
class PersonAddForm(z3cform.AddForm):
        form_fields = z3cfield.Fields(IPerson)
        def create(self,data):
                return Person(**data)
        def add(self,object):
			self.context[object.id]=object
        def nextURL(self):
                return 'index.html'
        

class CarEdit(form.EditForm):
        form_fields = form.Fields(ICar)
class CarAddForm(form.AddForm):
        form_fields = form.Fields(ICar)
        def create(self,data):
                obj=Car()
                form.applyChanges(obj, self.form_fields, data)
                return obj
        

class DriverEdit(form.EditForm):
        form_fields = form.Fields(IDriver)
class DriverAddForm(form.AddForm):
        form_fields = form.Fields(IDriver)
        def create(self,data):
                obj=Driver()
                form.applyChanges(obj, self.form_fields, data)
                return obj
        
from zope.interface import implements
from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained
from zope.security.proxy import removeSecurityProxy

from limosvc.interfaces import IPerson, IDriver, ICar, ILimosvc, ILimosvcContained

'''
class Person(Contained):
	implements(IPerson,ILimosvcContained)
	name = u''
	email = u''
	phoneNum = u''
'''
from zope.schema.fieldproperty import FieldProperty
class Person(object):
    implements(IPerson)
    name = FieldProperty(IPerson['name'])
    email = FieldProperty(IPerson['email'])
    phoneNum = FieldProperty(IPerson['phoneNum'])
    def __init__(self, name=None, email=None, phoneNum=None):
        if name:
            self.name = name
        if email:
            self.email = email
        if phoneNum:
            self.phoneNum = phoneNum
    def __repr__(self):
        return '<%s %r>' % (self.__class__.__name__, self.name)


class Car(Contained):
	implements(ICar,ILimosvcContained)

	name = u''
	model = u''
	nPassengers = u'0'

class Driver(Contained):
	implements(IDriver,ILimosvcContained)

	person_=None
	def getPerson_(self):
		return self.person_
	def setPerson_(self, value):
		self.person_=removeSecurityProxy(value)
	person=property(getPerson_,setPerson_)
	car_=None
	def getCar_(self):
		return self.car_
	def setCar_(self, value):
		self.car_=removeSecurityProxy(value)
	car=property(getCar_,setCar_)

class Limosvc(BTreeContainer):
        implements(ILimosvc)
        name = "u''"
<configure
    xmlns="http://namespaces.zope.org/zope";
    xmlns:browser="http://namespaces.zope.org/browser";
        i18n_domain="limosvc"
        >
        
  <include package="zope.security" file="meta.zcml" />
  <include package="zope.app.zcmlfiles" file="meta.zcml" />

  <include package="zope.publisher" />
  <include package="zope.traversing" />
  <include package="zope.traversing.browser" />
  <include package="zope.app.zcmlfiles" />

  <!-- The following packages aren't needed from the beginning, but
       end up being used in most applications -->
  <include package="zope.i18n" file="meta.zcml" />
  <include package="zope.annotation" />
  <include package="zope.copypastemove" />
  <include package="zope.formlib" />
  <include package="zope.i18n.locales" />
  <include package="zope.app.authentication" />
  <include package="zope.app.session" />
  <include package="zope.app.intid" />
  <include package="zope.app.keyreference" />
  <include package="zope.app.catalog" />

  <!-- Add your own component registrations here -->

  <interface
      interface=".interfaces.IPerson"
      type="zope.app.content.interfaces.IContentType"
      />

  <class class=".classes.Person">
    <!--implements
        interface="zope.annotation.interfaces.IAttributeAnnotatable"
        /-->
    <factory
        id="limosvc.classes.Person"
        description="a person" 
        />
    <require
        permission="zope.ManageContent"
        interface=".interfaces.IPerson"
        />
    <require
        permission="zope.ManageContent"
        set_schema=".interfaces.IPerson"
        />
  </class>
  
  <browser:addMenuItem
    class=".classes.Person"
    title="a person"
    permission="zope.ManageContent"
    description='add Person'
    view='.Person'
    />
  <browser:page
    for="zope.app.container.interfaces.IAdding"
    name=".Person"
    class=".browser.PersonAddForm"
    permission="zope.ManageContent"
    />
  <browser:page
    for=".interfaces.IPerson"
    name="edit.html"
    class=".browser.PersonEdit"
    permission="zope.ManageContent"
    template="edit.pt"
        menu="zmi_views" title="edit"
    />
  <utility
      provides="zope.schema.interfaces.IVocabularyFactory"
      component=".vocabulary.personsInParent"
      name="allPersons"
      />
  
  <interface
      interface=".interfaces.ICar"
      type="zope.app.content.interfaces.IContentType"
      />

  <class class=".classes.Car">
    <!--implements
        interface="zope.annotation.interfaces.IAttributeAnnotatable"
        /-->
    <factory
        id="limosvc.classes.Car"
        description="a car" 
        />
    <require
        permission="zope.ManageContent"
        interface=".interfaces.ICar"
        />
    <require
        permission="zope.ManageContent"
        set_schema=".interfaces.ICar"
        />
  </class>
  
  <browser:addMenuItem
      class=".classes.Car"
      title="a car"
      permission="zope.ManageContent"
      description='add Car'
      view='.Car'
  />
  <browser:page
    for="zope.app.container.interfaces.IAdding"
    name=".Car"
    class=".browser.CarAddForm"
    permission="zope.ManageContent"
    />
  <browser:page
      for=".interfaces.ICar"
      name="edit.html"
      class=".browser.CarEdit"
      permission="zope.ManageContent"
      template="edit.pt"
          menu="zmi_views" title="edit"
      />
  <utility
      provides="zope.schema.interfaces.IVocabularyFactory"
      component=".vocabulary.carsInParent"
      name="allCars"
      />
  
  <interface
      interface=".interfaces.IDriver"
      type="zope.app.content.interfaces.IContentType"
      />

  <class class=".classes.Driver">
    <!--implements
        interface="zope.annotation.interfaces.IAttributeAnnotatable"
        /-->
    <factory
        id="limosvc.classes.Driver"
        description="a driver" 
        />
    <require
        permission="zope.ManageContent"
        interface=".interfaces.IDriver"
        />
    <require
        permission="zope.ManageContent"
        set_schema=".interfaces.IDriver"
        />
  </class>
  
  <browser:addMenuItem
      class=".classes.Driver"
      title="a driver"
      permission="zope.ManageContent"
      description='add Driver'
      view='.Driver'
  />
  <browser:page
    for="zope.app.container.interfaces.IAdding"
    name=".Driver"
    class=".browser.DriverAddForm"
    permission="zope.ManageContent"
    />
  <browser:page
      for=".interfaces.IDriver"
      name="edit.html"
      class=".browser.DriverEdit"
      permission="zope.ManageContent"
      template="edit.pt"
          menu="zmi_views" title="edit"
      />
  <utility
      provides="zope.schema.interfaces.IVocabularyFactory"
      component=".vocabulary.driversInParent"
      name="allDrivers"
      />
  
  <interface
      interface=".interfaces.ILimosvc"
      type="zope.app.content.interfaces.IContentType"
      />
  
  <class class=".classes.Limosvc">
    <!--implements
        interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
        /-->
    <implements
        interface="zope.app.container.interfaces.IContentContainer" 
        />
    <factory
        id="limosvc.classes.Limosvc"
        description="Limosvc" 
        />
    <require
        permission="zope.ManageContent"
        interface=".interfaces.ILimosvc"
        />
    <require
        permission="zope.ManageContent"
        set_schema=".interfaces.ILimosvc"
        />
  </class>
  
  <browser:addMenuItem
      class=".classes.Limosvc"
      title="Limosvc"
      permission="zope.ManageContent"
  />

  <browser:containerViews
      for="limosvc.interfaces.ILimosvc"
      index="zope.View"
      contents="zope.View"
      add="zope.ManageContent"
      />

  </configure>
from zope.interface import Interface
from zope.schema import Field, Text, TextLine, Choice, Int, Bool, Date, Datetime, Object

from zope.app.container.constraints import ContainerTypesConstraint
from zope.app.container.constraints import ItemTypePrecondition
from zope.app.container.interfaces import IContained, IContainer


class IPerson(Interface):

	name = TextLine(
		title = u'name',
		description = u'name',
		default = u'',
		required = False)
	email = TextLine(
		title = u'email',
		description = u'email',
		default = u'',
		required = False)
	phoneNum = TextLine(
		title = u'phone#',
		description = u'phone#',
		default = u'',
		required = False)

class ICar(Interface):

	name = TextLine(
		title = u'name',
		description = u'name',
		default = u'',
		required = False)
	model = TextLine(
		title = u'model',
		description = u'model',
		default = u'',
		required = False)
	nPassengers = Int(
		title = u'nPassengers',
		description = u'nPassengers',
		default = 0,
		required = False)

class IDriver(Interface):

	person = Choice(
		title = u'person',
		description = u'person',
		default = None,
		source='allPersons',
		required = False)
	car = Choice(
		title = u'car',
		description = u'car',
		default = None,
		source='allCars',
		required = False)

class ILimosvc(IContainer):
        '''container for items of type IPerson, IDriver, ICar'''
        name = TextLine(
                title=u'Limosvc',
                description=u'a Limosvc container',
                default=u'',
                required=True)
        def __setitem__(name, obj): pass 
        __setitem__.precondition = ItemTypePrecondition(IPerson, IDriver, ICar)
class ILimosvcContained(IContained):
        '''for types that can only be contained in a Limosvc'''
        __parent__ = Field(constraint = ContainerTypesConstraint(ILimosvc))
from zope.schema.vocabulary import SimpleVocabulary
from interfaces import IPerson, IDriver, ICar, ILimosvc, ILimosvcContained


def personsInParent(context):
        '''returns person subobjects of parent as a vocabulary'''
        return SimpleVocabulary.fromItems(
                [(v.name, v) for k, v in context.__parent__.items() if IPerson.providedBy(v)])
        

def carsInParent(context):
        '''returns car subobjects of parent as a vocabulary'''
        return SimpleVocabulary.fromItems(
                [(v.name, v) for k, v in context.__parent__.items() if ICar.providedBy(v)])
        

def driversInParent(context):
        '''returns driver subobjects of parent as a vocabulary'''
        return SimpleVocabulary.fromItems(
                [(v.name, v) for k, v in context.__parent__.items() if IDriver.providedBy(v)])
        
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to