ATCTContent 使用错误的 ID 和标题创建

发布于 2024-10-26 10:19:46 字数 5760 浏览 5 评论 0原文

我用几个 ATCTContent 制作了一个附加组件,所有这些都是用 paster addcontent contenttype 创建的。除了一个之外,GearContent 均按预期工作。仅当我创建 GearContent 实例时,它们才会收到 gear、gear-1 等名称,而忽略标题。在默认视图中,H1 标签始终为“Gear”,但其下面的标题是正确的。

尝试更改文件夹内容视图上的 ID 和标题不会执行任何操作。没有错误消息。

目录也是如此。对于所有实例,GearContent 的 Title 元数据都是“Gear”。它适用于所有其他类型。

GearContent 只能在 GearFolder 内添加。其他内容也有类似的限制并且工作正常。我正在使用克隆4.0.4。

我该怎么做才能使新实例获得正确的标题?

以下内容/gearcontent.py:

 """Definition of the Gear Content content type
 """

 from zope.interface import implements

 from Products.Archetypes import atapi
 from Products.ATContentTypes.content import base
 from Products.ATContentTypes.content import schemata

 # -*- Message Factory Imported Here -*-
 from levity7.gears import gearsMessageFactory as _

 from levity7.gears.interfaces import IGearContent
 from levity7.gears.config import PROJECTNAME

 GearContentSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((

     # -*- Your Archetypes field definitions here ... -*-

     atapi.StringField(
         'title',
         storage=atapi.AnnotationStorage(),
         widget=atapi.StringWidget(
             label=_(u"Title"),
             description=_(u"Name for this content."),
         ),
         required=True,
     ),


     atapi.ReferenceField(
         'activities',
         storage=atapi.AnnotationStorage(),
         widget=atapi.ReferenceWidget(
             label=_(u"Adventure Activities"),
             description=_(u"Select all activities that apply to this content."),
         ),
         required=True,
         relationship='gearcontent_activities',
         allowed_types=('Gear Activity'), # specify portal type names here ('Example Type',)
         multiValued=True,
     ),


     atapi.ReferenceField(
         'category',
         storage=atapi.AnnotationStorage(),
         widget=atapi.ReferenceWidget(
             label=_(u"Category"),
             description=_(u"Select a category for this content."),
         ),
         required=True,
         relationship='gearcontent_category',
         allowed_types=('Gear Category'), # specify portal type names here ('Example Type',)
         multiValued=False,
     ),


     atapi.ImageField(
         'image',
         storage=atapi.AnnotationStorage(),
         widget=atapi.ImageWidget(
             label=_(u"Image"),
             description=_(u"A picture of this content."),
         ),
         validators=('isNonEmptyFile'),
     ),


     atapi.StringField(
         'imageLink',
         storage=atapi.AnnotationStorage(),
         widget=atapi.StringWidget(
             label=_(u"Image Link"),
             description=_(u"An URL to the image of this content."),
         ),
         validators=('isURL'),
     ),


     atapi.TextField(
         'description',
         storage=atapi.AnnotationStorage(),
         widget=atapi.RichWidget(
             label=_(u"Description"),
             description=_(u"Description for the content."),
         ),
         required=True,
     ),


     atapi.StringField(
         'reviewLink',
         storage=atapi.AnnotationStorage(),
         widget=atapi.StringWidget(
             label=_(u"Review Link"),
             description=_(u"Link to Review page."),
         ),
         validators=('isURL'),
     ),


     atapi.StringField(
         'diyLink',
         storage=atapi.AnnotationStorage(),
         widget=atapi.StringWidget(
             label=_(u"DIY Link"),
             description=_(u"Link to DIY page."),
         ),
         validators=('isURL'),
     ),


     atapi.TextField(
         'commentary',
         storage=atapi.AnnotationStorage(),
         widget=atapi.TextAreaWidget(
             label=_(u"commentary"),
             description=_(u"commentarys for the content. These will not be displayed."),
         ),
     ),


     atapi.TextField(
         'purchaseHtml',
         storage=atapi.AnnotationStorage(),
         widget=atapi.TextAreaWidget(
             label=_(u"Purchase HTML Code"),
             description=_(u"HTML used to display or add this item to the Cart."),
         ),
     ),


     atapi.IntegerField(
         'score',
         storage=atapi.AnnotationStorage(),
         widget=atapi.IntegerWidget(
             label=_(u"Life This Value"),
             description=_(u"Initial value of 'Life This'"),
         ),
         default=_(u"0"),
         validators=('isInt'),
     ),


 ))

 # Set storage on fields copied from ATContentTypeSchema, making sure
 # they work well with the python bridge properties.

 GearContentSchema['title'].storage = atapi.AnnotationStorage()
 GearContentSchema['description'].storage = atapi.AnnotationStorage()

 schemata.finalizeATCTSchema(GearContentSchema, moveDiscussion=False)


 class GearContent(base.ATCTContent):
     """Gear Content"""
     implements(IGearContent)

     meta_type = "GearContent"
     schema = GearContentSchema

     title = atapi.ATFieldProperty('title')
     description = atapi.ATFieldProperty('description')

     # -*- Your ATSchema to Python Property Bridges Here ... -*-
     title = atapi.ATFieldProperty('title')

     activities = atapi.ATReferenceFieldProperty('activities')

     category = atapi.ATReferenceFieldProperty('category')

     image = atapi.ATFieldProperty('image')

     imageLink = atapi.ATFieldProperty('imageLink')

     description = atapi.ATFieldProperty('description')

     reviewLink = atapi.ATFieldProperty('reviewLink')

     diyLink = atapi.ATFieldProperty('diyLink')

     commentary = atapi.ATFieldProperty('commentary')

     purchaseHtml = atapi.ATFieldProperty('purchaseHtml')

     score = atapi.ATFieldProperty('score')


 atapi.registerType(GearContent, PROJECTNAME)

谢谢。

I've made an add-on with several ATCTContent, all created with paster addcontent contenttype. All but one, GearContent work as expected. Only when I create instances of GearContent they receive names like gear, gear-1, etc. ignoring the title. In default view, the H1 tag is always 'Gear' but the title bellow it is right.

Trying to change the ids and titles on the folder content view doesn't do anything. There's no error message.

Same thing with the catalog. GearContent's Title metadata is 'Gear' for all instances. It works for all other types.

GearContent is only addable inside GearFolder. Other contents have similar restrictions and work fine. I'm using plone 4.0.4.

What can I do to make new instances get the title right?

Below content/gearcontent.py:

 """Definition of the Gear Content content type
 """

 from zope.interface import implements

 from Products.Archetypes import atapi
 from Products.ATContentTypes.content import base
 from Products.ATContentTypes.content import schemata

 # -*- Message Factory Imported Here -*-
 from levity7.gears import gearsMessageFactory as _

 from levity7.gears.interfaces import IGearContent
 from levity7.gears.config import PROJECTNAME

 GearContentSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((

     # -*- Your Archetypes field definitions here ... -*-

     atapi.StringField(
         'title',
         storage=atapi.AnnotationStorage(),
         widget=atapi.StringWidget(
             label=_(u"Title"),
             description=_(u"Name for this content."),
         ),
         required=True,
     ),


     atapi.ReferenceField(
         'activities',
         storage=atapi.AnnotationStorage(),
         widget=atapi.ReferenceWidget(
             label=_(u"Adventure Activities"),
             description=_(u"Select all activities that apply to this content."),
         ),
         required=True,
         relationship='gearcontent_activities',
         allowed_types=('Gear Activity'), # specify portal type names here ('Example Type',)
         multiValued=True,
     ),


     atapi.ReferenceField(
         'category',
         storage=atapi.AnnotationStorage(),
         widget=atapi.ReferenceWidget(
             label=_(u"Category"),
             description=_(u"Select a category for this content."),
         ),
         required=True,
         relationship='gearcontent_category',
         allowed_types=('Gear Category'), # specify portal type names here ('Example Type',)
         multiValued=False,
     ),


     atapi.ImageField(
         'image',
         storage=atapi.AnnotationStorage(),
         widget=atapi.ImageWidget(
             label=_(u"Image"),
             description=_(u"A picture of this content."),
         ),
         validators=('isNonEmptyFile'),
     ),


     atapi.StringField(
         'imageLink',
         storage=atapi.AnnotationStorage(),
         widget=atapi.StringWidget(
             label=_(u"Image Link"),
             description=_(u"An URL to the image of this content."),
         ),
         validators=('isURL'),
     ),


     atapi.TextField(
         'description',
         storage=atapi.AnnotationStorage(),
         widget=atapi.RichWidget(
             label=_(u"Description"),
             description=_(u"Description for the content."),
         ),
         required=True,
     ),


     atapi.StringField(
         'reviewLink',
         storage=atapi.AnnotationStorage(),
         widget=atapi.StringWidget(
             label=_(u"Review Link"),
             description=_(u"Link to Review page."),
         ),
         validators=('isURL'),
     ),


     atapi.StringField(
         'diyLink',
         storage=atapi.AnnotationStorage(),
         widget=atapi.StringWidget(
             label=_(u"DIY Link"),
             description=_(u"Link to DIY page."),
         ),
         validators=('isURL'),
     ),


     atapi.TextField(
         'commentary',
         storage=atapi.AnnotationStorage(),
         widget=atapi.TextAreaWidget(
             label=_(u"commentary"),
             description=_(u"commentarys for the content. These will not be displayed."),
         ),
     ),


     atapi.TextField(
         'purchaseHtml',
         storage=atapi.AnnotationStorage(),
         widget=atapi.TextAreaWidget(
             label=_(u"Purchase HTML Code"),
             description=_(u"HTML used to display or add this item to the Cart."),
         ),
     ),


     atapi.IntegerField(
         'score',
         storage=atapi.AnnotationStorage(),
         widget=atapi.IntegerWidget(
             label=_(u"Life This Value"),
             description=_(u"Initial value of 'Life This'"),
         ),
         default=_(u"0"),
         validators=('isInt'),
     ),


 ))

 # Set storage on fields copied from ATContentTypeSchema, making sure
 # they work well with the python bridge properties.

 GearContentSchema['title'].storage = atapi.AnnotationStorage()
 GearContentSchema['description'].storage = atapi.AnnotationStorage()

 schemata.finalizeATCTSchema(GearContentSchema, moveDiscussion=False)


 class GearContent(base.ATCTContent):
     """Gear Content"""
     implements(IGearContent)

     meta_type = "GearContent"
     schema = GearContentSchema

     title = atapi.ATFieldProperty('title')
     description = atapi.ATFieldProperty('description')

     # -*- Your ATSchema to Python Property Bridges Here ... -*-
     title = atapi.ATFieldProperty('title')

     activities = atapi.ATReferenceFieldProperty('activities')

     category = atapi.ATReferenceFieldProperty('category')

     image = atapi.ATFieldProperty('image')

     imageLink = atapi.ATFieldProperty('imageLink')

     description = atapi.ATFieldProperty('description')

     reviewLink = atapi.ATFieldProperty('reviewLink')

     diyLink = atapi.ATFieldProperty('diyLink')

     commentary = atapi.ATFieldProperty('commentary')

     purchaseHtml = atapi.ATFieldProperty('purchaseHtml')

     score = atapi.ATFieldProperty('score')


 atapi.registerType(GearContent, PROJECTNAME)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小嗷兮 2024-11-02 10:19:46

删除“标题”字段。它已在 ATContentTypeSchema 中定义。您正在有效地重新实现它,但没有自动内容对象命名等基线功能。你的掩盖了原型中定义的那个。

Remove your "title" field. It's already defined in ATContentTypeSchema. You're effectively re-implementing it, but without the baseline functionality like automatic content object naming. Yours is masking the one defined in Archetypes.

眼前雾蒙蒙 2024-11-02 10:19:46

问题出在category字段中。看来这是一个保留名称。 (上面出现了“类别”;这是一个拼写错误)。

The problem was in the field category. It seems that's a reserved name. (in the above it appears 'categoty'; it was a typo).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文