覆盖敏捷类型中的标题值
Override Title value in dexterity type
我有一个灵活的自定义类型(模式驱动),没有标题或描述字段。
class IAnimal(model.Schema):
name = schema.TextLine(title=_(u"Name"),required=True,)
specie = schema.Choice(title=_(u"Specie"),vocabulary=animalSpecies)
weight = schema.TextLine(title=_(u"Weight"))
(etc)
我的模型确实不需要标题字段,但是当我创建一些内容时,文件夹列表显示:
— by admin — last modified Oct 17, 2015 02:27 PM
我用 mr.bob 创建了这个产品,但还没有覆盖任何表单。这可以通过覆盖任何形式、自定义行为(如 plone.app.content.interfaces.INameFromTitle)或什么来实现?
我只想将 "name" 字段设置为 "title" 而无需将 "name" 更改为 "title",即使我必须隐藏 "title" 字段模型。
看一些老原型产品,是这样的方法:
def at_post_create_script(self):
title = self.name
plone_utils = getToolByName(self, 'plone_utils', None)
new_id = plone_utils.normalizeString(title)
self.setTitle(new_id)
我不明白为什么你不能简单地提供一个名为 "Name" 的 "title" 字段(最简单的方法),但是你也可以覆盖 title
属性和 Title
基础方法 class.
如果您使用 mr.bob,您可能没有可以自定义的 base class。
检查您的类型定义 XML:在 klass
属性 中您可能有 plone.dexterity.content.Item
。将其更改为新的敏捷基础 class 您必须添加到您的产品(示例:https://github.com/collective/wildcard.media/blob/84b82994dc424fe40b92b1c9af8d48edb558a78d/wildcard/media/content.py#L6)
当您拥有基础 class 时,您可以添加 Title
方法和 title
属性,例如:
class MyType(Item):
implements(IMyType)
def Title(self):
return self.name
@property
def title(self)
return self.name
我有一个灵活的自定义类型(模式驱动),没有标题或描述字段。
class IAnimal(model.Schema):
name = schema.TextLine(title=_(u"Name"),required=True,)
specie = schema.Choice(title=_(u"Specie"),vocabulary=animalSpecies)
weight = schema.TextLine(title=_(u"Weight"))
(etc)
我的模型确实不需要标题字段,但是当我创建一些内容时,文件夹列表显示:
— by admin — last modified Oct 17, 2015 02:27 PM
我用 mr.bob 创建了这个产品,但还没有覆盖任何表单。这可以通过覆盖任何形式、自定义行为(如 plone.app.content.interfaces.INameFromTitle)或什么来实现?
我只想将 "name" 字段设置为 "title" 而无需将 "name" 更改为 "title",即使我必须隐藏 "title" 字段模型。
看一些老原型产品,是这样的方法:
def at_post_create_script(self):
title = self.name
plone_utils = getToolByName(self, 'plone_utils', None)
new_id = plone_utils.normalizeString(title)
self.setTitle(new_id)
我不明白为什么你不能简单地提供一个名为 "Name" 的 "title" 字段(最简单的方法),但是你也可以覆盖 title
属性和 Title
基础方法 class.
如果您使用 mr.bob,您可能没有可以自定义的 base class。
检查您的类型定义 XML:在 klass
属性 中您可能有 plone.dexterity.content.Item
。将其更改为新的敏捷基础 class 您必须添加到您的产品(示例:https://github.com/collective/wildcard.media/blob/84b82994dc424fe40b92b1c9af8d48edb558a78d/wildcard/media/content.py#L6)
当您拥有基础 class 时,您可以添加 Title
方法和 title
属性,例如:
class MyType(Item):
implements(IMyType)
def Title(self):
return self.name
@property
def title(self)
return self.name