2014-08-31 43 views
2

我想創建一個使用collective.z3cform.datagridfield的內容類型。我一直在嘗試遵循本演示中提到的示例: http://glicksoftware.com/presentations/dexterity-in-the-wildPlone:敏捷模型驅動的內容類型與collective.z3cform.datagridfield - 在xml模型中嵌套xml模型

該示例演示了從主模式引用第二個模式。這是我的嘗試。

<?xml version="1.0" ?> 
<model xmlns="http://namespaces.plone.org/supermodel/schema" 
     xmlns:form="http://namespaces.plone.org/supermodel/form"> 
<field name="telephone" type="zope.schema.List" 
    form:widget="collective.z3cform.datagridfield.DataGridFieldFactory"> 

     <title>Telephone</title> 
     <description>Enter telephone numbers here</description> 
     <max_length>10</max_length> 
     <min_length>2</min_length> 
     <missing_value/> 
     <readonly>False</readonly> 
     <required>False</required> 

     <value_type type="collective.z3cform.datagridfield.DictRow"> 
     <title>Number</title> 
     <schema>mypackage.mytype.IPhoneSchema</schema> 
     </value_type> 
    </field> 
</schema> 
</model> 

我定義我的第二個架構中mypackage中/ mytype.py看起來像這樣:

from plone.supermodel import model 

class IPhoneSchema(model.Schema): 
    """Schema for dict rows used in DataGridFields 
    name is the 'real' name 
    token is the token used in the vocabularies 
    """ 
# 
    model.load("models/phone.xml") 

然後在型號/ phone.xml我有以下幾點:

<?xml version="1.0" ?> 
<model xmlns="http://namespaces.plone.org/supermodel/schema" 
     xmlns:form="http://namespaces.plone.org/supermodel/form"> 

    <schema> 
     <field name="number" type="zope.schema.TextLine"> 
      <description/> 
      <required>False</required> 
      <title>Number</title> 
     </field> 
    </schema> 
</model> 

當我啓動Plone時,出現以下錯誤:

SupermodelParseError: 'module' object has no attribute 'mytype' 
     <schema>mypackage.mytype.IPhoneSchema</schema> 

回答

2

實際上,兩個模型xml文件都是在mytype.py文件中定義的。這導致了mytype.py無法調用的運行時問題... mytype.IPhoneSchema。

的解決方案是用下面的內容創建phoneschema.py文件獨立mytype.py的:

from plone.supermodel import model

class IPhoneSchema(model.Schema):

"""Schema for dict rows used in DataGridFields 
    they are used for individual phone numbers 
    """ 

    model.load("models/phone.xml") 

與其說mytype.IPhoneSchema的,我們現在可以稱之爲phoneschema.IPhoneSchema。我可以在模型/ mytype.xml中包含電話架構(請參閱下面的示例)。關係的圖

...

<title>Telephone</title> 
    <description>Enter telephone numbers here</description> 
    <max_length>10</max_length> 
    <min_length>2</min_length> 
    <missing_value/> 
    <readonly>False</readonly> 
    <required>False</required> 

    <value_type type="collective.z3cform.datagridfield.DictRow"> 
    <title>Number</title> 
    <schema>mypackage.mytype.IPhoneSchema</schema> 
    </value_type> 
</field> 

...

這裏,phoneschema.py「負荷」 phone.xml:

phoneschema.py loads phone.xml

出於參考起見,現在我的產品的文件樹看起來是這樣的這(我已經把旁邊的星密鑰文件在這種情況下phoneschema.py它引用的第二個模型文件):

... 
├── __init__.py 
├── configure.zcml 
├── mytype.py 
├── mytype_templates 
│   └── view.pt 
├── models 
│   ├── mytype.xml 
│   └── phone.xml 
├── *phoneschema.py 
...