小编Eso*_*oth的帖子

在Plone 5中使用GenericSetup注册资源

文档中的CSS页面http://docs.plone.org/adapt-and-extend/theming/templates_css/css.html#plone-css仍建议使用cssregistry.xml,即使资源存储在注册表中现在.这是首选方法,而不是registry.xml吗?据我所知,它将它们添加到plone遗留包中.鉴于它的名字,听起来这是我应该摆脱的东西.

假设我不想继续使用plone遗留包,那么将我的css/js添加到plone包中是不是很糟糕,还是应该为我的命名空间创建一个新的包?

plone plone-5.x

5
推荐指数
0
解决办法
84
查看次数

使用灵巧行为来提供方法

我一直在使用模式行为没有问题,但我想要一个提供一些逻辑的方法.现在我有

class IMyFoo(form.Schema):
    requester = schema.TextLine(title=_(u"Requestor"),
              required=False,
          )

    def foo(self):
      """ foo """

alsoProvides(IMyFoo, IFormFieldProvider)
Run Code Online (Sandbox Code Playgroud)

并在zcml中

<plone:behavior
    title="My behavior"
    description="Some desc"
    provides=".behaviors.IMyFoo"
    for=".interfaces.ISomeInterface"
    />
Run Code Online (Sandbox Code Playgroud)

我在portal_types中的内容类型的行为部分中包含了IMyFoo.这给了我架构但不是foo()方法.所以我尝试使用以下代码阅读http://plone-training.readthedocs.org/en/latest/behaviors2.html来为它添加工厂

class MyFoo(object):    
    def foo(self):
      return 'bar'
Run Code Online (Sandbox Code Playgroud)

并在zcml中

<plone:behavior
    title="My behavior"
    description="Some desc"
    provides=".behaviors.IMyFoo"
    factory=".behaviors.MyFoo"
    for=".interfaces.ISomeInterface"
    />
Run Code Online (Sandbox Code Playgroud)

但这似乎没有什么区别,或者至少,我不知道如何访问该方法.我能够得到的最接近的是:

class IMyFoo(Interface):
  """ Marker """

class MyFoo(object):

  def __init__(self, context):
      self.context = context

  def foo(self):
    return 'bar'

<adapter for=".interfaces.ISomeInterface"
     factory=".behaviors.MyFoo"
     provides=".behaviors.IMyFoo" />
Run Code Online (Sandbox Code Playgroud)

我将IMyFoo放在fti中的behavior属性中,然后通过遍历所有行为来调用它

behavior = resolveDottedName(context.portal_types.getTypeInfo(context.portal_type).behaviors[-1]))
behavior(self).myfoo()
Run Code Online (Sandbox Code Playgroud)

当然,通过这样的FTI并不是正确的方法.但是我现在处于亏损状态.在Archetypes中,我只需创建一个mixin类,并使用我想要使用的任何内容类型继承它.我可以在这里做同样的事,但我的理解是行为应该是它们的替代品,所以我想弄清楚如何使用这种首选方法.

zope plone grok dexterity

2
推荐指数
1
解决办法
223
查看次数

重启时丢失一些z3c关系数据

我有以下代码,用于以编程方式将关系值分配给自定义内容类型.

publications = # some data

catalog = getToolByName(context, 'portal_catalog')
for pub in publications:
  if pub['custom_id']:
    results = catalog(custom_id=pub['custom_id'])
    if len(results) == 1:
      obj = results[0].getObject()
      measures = []
      for m in pub['measure']:
        if m in context.objectIds():
          m_id = intids.getId(context[m])
          relation = RelationValue(m_id)
          measures.append(relation)
      obj.measures = measures
      obj.reindexObject()
      notify(ObjectModifiedEvent(obj))
Run Code Online (Sandbox Code Playgroud)

自定义内容类型的模式片段

measures = RelationList(
  title=_(u'Measure(s)'),
  required=False,
  value_type=RelationChoice(title=_(u'Measure'),
                            source=ObjPathSourceBinder(object_provides='foo.bar.interfaces.measure.IMeasure')),
  )
Run Code Online (Sandbox Code Playgroud)

当我运行我的脚本时,一切都很好看.问题是当我的自定义内容模板尝试调用"pub/from_object/absolute_url"时,该值为空 - 仅在重新启动后.有趣的是,我可以在重启后获得pub/from_object的其他属性,而不是它的URL.

plone dexterity

2
推荐指数
1
解决办法
61
查看次数

标签 统计

plone ×3

dexterity ×2

grok ×1

plone-5.x ×1

zope ×1