我的基于原型的内容类型无法添加

编程入门 行业动态 更新时间:2024-10-28 15:26:17
本文介绍了我的基于原型的内容类型无法添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个附加软件包,其中引入了一些基于原型的内容类型; 这些是在该程序包的默认配置文件中定义的.

I'm developing an add-on package which introduces a few Archetypes-based content types; these are defined in the default profile of that package.

在快速安装程序中(重新)安装软件包后,可以在类型工具中看到我的类型;但是我无法添加它们TTW,并且它们也没有在folder_constraintypes_form中列出.我确实在文件夹"门户类型的允许的内容类型"多选列表中选择了它们.

After (re-) installing my package in the Quick-Installer, I can see my types in the types tool; but I can't add them TTW, and they are not listed in the folder_constraintypes_form. I did select them in the "Allowed content types" multiselect list of the Folder portal type.

由于我在bin/instance debug会话中从FactoryTypeInformation._getFactoryMethod获得了ValueError,因此我开发"了Products.CMFPlone(分支2.2)并像这样更改了TypesTool.py:

Since I got a ValueError from FactoryTypeInformation._getFactoryMethod in an bin/instance debug session, I "developed" Products.CMFPlone (branch 2.2) and changed the TypesTool.py like so:

from pprint import pprint # ADDED ... class FactoryTypeInformation(TypeInformation): ... def _getFactoryMethod(self, container, check_security=1): if not self.product or not self.factory: raise ValueError, ('Product factory for %s was undefined' % self.getId()) pd = container.manage_addProduct # ADDED p = container.manage_addProduct[self.product] self_product = self.product # ADDED self_factory = self.factory # ADDED m = getattr(p, self.factory, None) if m is None: pprint(locals()) # ADDED raise ValueError, ('Product factory for %s was invalid' % self.getId()) if not check_security: return m if getSecurityManager().validate(p, p, self.factory, m): return m raise AccessControl_Unauthorized( 'Cannot create %s' % self.getId() )

debug会话现在看起来像这样:

The debug session now looks like this:

>>> root = app.plone >>> from Products.CMFCore.utils import getToolByName >>> tmp_folder = root.temp >>> type_name = 'MyType' >>> types_tool = getToolByName(tmp_folder, 'portal_types') >>> type_info = types_tool.getTypeInfo(type_name) >>> type_info <DynamicViewTypeInformation at /plone/portal_types/MyType> >>> new_content_item = type_info._constructInstance(tmp_folder, 'shiny_new_object') {'check_security': 0, 'container': <ATFolder at /plone/temp>, 'pd': <App.FactoryDispatcher.ProductDispatcher object at 0x227afd0>, 'p': <App.FactoryDispatcher.FactoryDispatcher object at 0x7b97450>, 'self': <DynamicViewTypeInformation at /plone/portal_types/MyType>, 'm': None, 'self_factory': 'addMyType', 'self_product': 'MyCompany.MyProduct'} Traceback (most recent call last): File "<console>", line 1, in <module> File "/opt/zope/instances/zope-devel/src/Products.CMFCore/Products/CMFCore/TypesTool.py", line 551, in _constructInstance m = self._getFactoryMethod(container, check_security=0) File "/opt/zope/instances/zope-devel/src/Products.CMFCore/Products/CMFCore/TypesTool.py", line 467, in _getFactoryMethod self.getId()) ValueError: Product factory for MyType was invalid

因此,FactoryDispatcher缺少必要的addMyType属性. 可能我的声明不完整?

So, the FactoryDispatcher lacks the necessary addMyType attribute. Probably my declarations are incomplete?

这就是我所拥有的:

config.py:

# -*- coding: utf-8 -*- from Products.CMFCore.permissions import setDefaultRoles from os import sep from .permissions import (AddMyType, ) PROJECTNAME = "MyCompany.MyProduct" PRODUCT_HOME = sep.join(__file__.split(sep)[:-1]) MANAGERS_ONLY = ('Manager',) MANAGERS_AND_OWNER = ('Manager', 'Owner') # Permissions DEFAULT_ADD_CONTENT_PERMISSION = "Add portal content" setDefaultRoles(DEFAULT_ADD_CONTENT_PERMISSION, MANAGERS_AND_OWNER) ADD_CONTENT_PERMISSIONS = { 'MyType': AddMyType, } for perm in ADD_CONTENT_PERMISSIONS.values(): setDefaultRoles(perm, MANAGERS_ONLY)

content/mytype.py:

# -*- coding: utf-8 -*- __author__ = """unknown <unknown>""" __docformat__ = 'plaintext' from AccessControl import ClassSecurityInfo from zope.interface import implements from ..interfaces import IMyType from ..config import PROJECTNAME from Products.ATContentTypes.content.base import ATCTContent from Products.ATContentTypes.content.schemata import ATContentTypeSchema from Products.ATContentTypes.content.base import registerATCT as registerType MyType_schema = ( ATContentTypeSchema.copy() ) class MyType(ATCTContent): """ description of my type """ security = ClassSecurityInfo() implements(IMyType) meta_type = 'MyType' _at_rename_after_creation = True schema = MyType_schema registerType(MyType, PROJECTNAME)

interfaces.py:

# -*- coding: utf-8 -*- """Module where all interfaces, events and exceptions live.""" from zope.publisher.interfaces.browser import IDefaultBrowserLayer from zope.interface import Interface class ISupBetonqualiLayer(IDefaultBrowserLayer): """Marker interface that defines a browser layer.""" class IMyType(Interface): """Marker interface for .mytype.MyType """

permissions.py:

# -*- coding: utf-8 -*- vim: ts=8 sts=4 sw=4 si et tw=79 """ Permissions """ AddMyType = 'MyCompany.MyProduct: Add MyType'

profiles/default/factorytool.xml:

<?xml version="1.0"?> <object name="portal_factory" meta_type="Plone Factory Tool"> <factorytypes> <type portal_type="MyType"/> </factorytypes> </object>

profiles/default/rolemap.xml:

<?xml version="1.0"?> <rolemap> <roles> <role name="MyAuthor"/> </roles> <permissions> <permission name="MyCompany.MyProduct: Add MyType" acquire="True"> <role name="MyAuthor"/> <role name="Manager"/> </permission> </permissions> </rolemap>

profiles/default/types.xml:

<?xml version="1.0"?> <object name="portal_types" meta_type="Plone Types Tool"> <object name="MyType" meta_type="Factory-based Type Information with dynamic views"/> </object>

profiles/default/types/MyType.xml:

<?xml version="1.0"?> <object name="MyType" meta_type="Factory-based Type Information with dynamic views" xmlns:i18n="xml.zope/namespaces/i18n"> <property name="title">MyType</property> <property name="description"> Some description text which is indeed visible in the types tool </property> <property name="content_icon">SomeExisting.png</property> <property name="content_meta_type">MyType</property> <property name="product">MyCompany.MyProduct</property> <property name="factory">addMyType</property> <property name="immediate_view">mytype_view</property> <property name="global_allow">True</property> <property name="filter_content_types">False</property> <property name="allowed_content_types"> </property> <property name="allow_discussion">False</property> <property name="default_view">mytype_view</property> <property name="view_methods"> <element value="base_view"/> </property> <property name="default_view_fallback">False</property> <alias from="(Default)" to="(dynamic view)"/> <alias from="index.html" to="(dynamic view)"/> <alias from="view" to="(selected layout)"/> <alias from="edit" to="base_edit"/> <alias from="properties" to="base_metadata"/> <action title="View" action_id="view" category="object" condition_expr="" url_expr="string:${object_url}/view" visible="True"> <permission value="View"/> </action> <action title="Edit" action_id="edit" category="object" condition_expr="not:object/@@plone_lock_info/is_locked_for_current_user" url_expr="string:${object_url}/edit" visible="True"> <permission value="Modify portal content"/> </action> </object>

  • 原型是否应负责创建缺少的addMyType方法?
  • 什么会导致失败?
  • 我的配置中明显缺少什么吗?
  • 到目前为止,该站点仅包含基于Archtypes的对象.如果现在添加基于敏捷的类型,我会遇到麻烦吗? "(我对敏捷完全没有经验)"
    • Should not Archetypes take care of creating that missing addMyType method?
    • What could make this fail?
    • Is there something obviously missing in my configuration?
    • The site contains Archtypes-based objects exclusively so far. Will I come into trouble if I add Dexterity-based types now? ''(I'm totally inexperienced with Dexterity)''
    • 在有人告诉我这样做之前:我创建了 Plone社区论坛中的一个问题已经;到目前为止没有运气.如果任一页面上都有重要信息,我将对其进行同步.

      Before someone tells me to do so: I created a question in the Plone community forum already; no luck so far. If important information comes in on either page, I'll sync it.

      推荐答案

      以下是使您的内容类型可添加的缺失部分:

      These are the missing parts to make your contenttype addable:

      1.)通过添加以下内容在MyCompany/MyProduct/configure.zcml中注册内容目录:

      1.) Register the content-directory in MyCompany/MyProduct/configure.zcml by adding:

      <include package=".content" />

      2.)添加具有以下内容的文件MyCompany/MyProduct/content/configure.zcml:

      2.) Add the file MyCompany/MyProduct/content/configure.zcml with this content:

      <configure xmlns="namespaces.zope/zope" xmlns:five="namespaces.zope/five" i18n_domain="MyCompany.MyProduct"> <class class=".mytype.MyType"> <require permission="zope2.View" interface="..interfaces.IMyType" /> </class> </configure>

      3.)通过将class MyType(*basecls)替换为class MyType(ATCTContent),修复MyCompany/MyProduct/content/mytype.py中随后发生的语法错误.

      3.) Fix the then occurring syntax-error in MyCompany/MyProduct/content/mytype.py by replacing class MyType(*basecls) with class MyType(ATCTContent).

      最后但并非最不重要的一点是,消除以前使事情起作用的尝试.最好将类型外包给专用的pckg,然后用zopeskel,imo创建它.

      And last but not least remove the former attempts of making things work. Best would be to outsource the type to a dedicated pckg and create it with zopeskel, imo.

      对于添加类型后发生的视图错误,请随时打开一个新任务;-)

      For the view-error occurring after adding a type, feel free to open a new quest ;-)

更多推荐

我的基于原型的内容类型无法添加

本文发布于:2023-07-17 10:47:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1132413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原型   类型   内容

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!