我一直在关注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
我在该部分下的构建中包含了 plone.app.users
以下是我的文件内容:
位置: 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/propertiestool.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>
TL;博士
使用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>)
任何人都可以对它试图告诉我的内容提供任何见解吗?