我一直关注Plone 4网站中的collective.examples.userdata,试图在/@@ personal-information页面添加更多字段。
我希望添加以下字段(所有字段都是文本字符串):
我决定尝试获得"位置"现场工作,并已成功安装和激活我的插件,没有任何麻烦。
当我去mysite.com / @@ personal-preferences:
时,我会得到这个追溯Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module zope.formlib.form, line 795, in __call__
Module five.formlib.formbase, line 50, in update
Module zope.formlib.form, line 758, in update
Module plone.fieldsets.form, line 30, in setUpWidgets
Module zope.formlib.form, line 383, in setUpEditWidgets
TypeError: ('Could not adapt', <PloneSite at /peacehospice>, <InterfaceClass
kcs.userdata.userdataschema.IEnhancedUserDataSchema>)
我的附加结构如下:
kcs.userdata
|
--kcs
|
--__init.py__
--userdata
|
--adapter.py
--configure.zcml
--__init__.py
--tests.py
--userdataschema.py
--profiles
|
--default
|
--componentregistry.xml
--metadata_properties.xml
--propertiestool.xml
kcs.userdata 文件夹位于我的实例文件夹内的src文件夹中。
我在eggs
部分
以下是我的文件内容:
位置: kcs.userdata / setup.py
from setuptools import setup, find_packages
import os
version = '1.0'
setup(name='kcs.userdata',
version=version,
description="",
long_description=open("README.txt").read() + "\n" +
open(os.path.join("docs", "HISTORY.txt")).read(),
# Get more strings from
# http://pypi.python.org/pypi?:action=list_classifiers
classifiers=[
"Framework :: Plone",
"Programming Language :: Python",
],
keywords='',
author='',
author_email='',
url='http://svn.plone.org/svn/collective/',
license='GPL',
packages=find_packages(exclude=['ez_setup']),
namespace_packages=['kcs'],
include_package_data=True,
zip_safe=False,
install_requires=[
'setuptools',
'plone.app.users >= 1.0b7',
],
entry_points="""
# -*- Entry points: -*-
[z3c.autoinclude.plugin]
target = plone
""",
setup_requires=["PasteScript"],
paster_plugins=["ZopeSkel"],
)
位置: kcs.userdata / kcs / userdata / adapter.py
from plone.app.users.browser.personalpreferences import UserDataPanelAdapter
class EnhancedUserDataPanelAdapter(UserDataPanelAdapter):
def get_position(self):
return self.context.getProperty('position','')
def set_position(self, value):
return self.context.setMemberProperties({'position': value})
position = property(get_position, set_position)
位置: kcs.userdata / kcs / userdata / configure.zcml:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="kcs.userdata">
<five:registerPackage package="." initialize=".initialize" />
<genericsetup:registerProfile
name="default"
title="KCS User Data"
directory="profiles/default"
description='Adds position field to user data'
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
</configure>
位置:kcs.userdata / kcs / userdata / init .py
from zope.i18nmessageid import MessageFactory
_ = MessageFactory("kcs.userdata")
def initialize(context):
"""Initializer called when used as a Zope 2 product."""
位置: kcs.userdata / kcs / userdata / userdataschema.py
from zope.interface import Interface, implements
from zope import schema
from kcs.userdata import _
from plone.app.users.userdataschema import IUserDataSchemaProvider
from plone.app.users.userdataschema import IUserDataSchema
def validateAccept(value):
if not value == True:
return False
return True
class UserDataSchemaProvider(object):
implements(IUserDataSchemaProvider)
def getSchema(self):
return IEnhancedUserDataSchema
class IEnhancedUserDataSchema(IUserDataSchema):
position = schema.TextLine(
title=_(u'label_position', default=u'Position'),
description=_(u'help_position', default=u"Fill in your position in the company"),
required=False,
)
位置: kcs.userdata / kcs / userdata / profiles / default / componentregistry.xml
<?xml version="1.0"?>
<componentregistry>
<utilities>
<utility
interface="plone.app.users.userdataschema.IUserDataSchemaProvider"
factory="kcs.userdata.userdataschema.UserDataSchemaProvider"
/>
</utilities>
</componentregistry>
位置:kcs.userdata / kcs / userdata / profiles / default / metadata_properties.xml
<?xml version="1.0"?>
<object name="portal_memberdata" meta_type="Plone Memberdata Tool">
<property name="position" type="string"></property>
</object>
位置: kcs.userdata / kcs / userdata / profiles / default / propertyiestool.xml
<?xml version="1.0"?>
<object name="portal_properties" meta_type="Plone Properties Tool">
<object name="site_properties" meta_type="Plone Property Sheet">
<property name="user_registration_fields" type="lines">
<element value="position" />
</property>
</object>
</object>
使用collective.examples.userdata示例制作自定义插件,在尝试查看mysite.com/@@personal-information时,我收到以下追溯:
Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module zope.formlib.form, line 795, in __call__
Module five.formlib.formbase, line 50, in update
Module zope.formlib.form, line 758, in update
Module plone.fieldsets.form, line 30, in setUpWidgets
Module zope.formlib.form, line 383, in setUpEditWidgets
TypeError: ('Could not adapt', <PloneSite at /peacehospice>, <InterfaceClass
kcs.userdata.userdataschema.IEnhancedUserDataSchema>)
任何人都可以提供任何有关它试图告诉我的信息吗?
答案 0 :(得分:3)
您缺少overrides.zcml
,注册适配器覆盖:
<adapter
provides=".userdataschema.IEnhancedUserDataSchema"
for="Products.CMFCore.interfaces.ISiteRoot"
factory=".adapter.EnhancedUserDataPanelAdapter"
/>
答案 1 :(得分:0)
您还可以在see link
中注册本地+到您的plonesite持久性实用程序