1

我的问题和修复尝试

我有一个 Plone 4 站点,我在其上使用了collective.examples.userdata,以便在注册表单和@@personal-information页面上注册新的自定义字段。我的一个字段需要是一个选择列表,允许用户指定他们所在组织的哪个团队。

我已经成功地让选择列表出现在注册表和@@personal-information表格上,但是当我试图弄清楚如何将其添加到mysite.com/portal_memberdata页面时,我感到很沮丧。

我尝试在此页面中添加一个包含以下信息的字段:

名称:团队

类型:选择

价值:getTeamValue

getTeamValue是一个 Python 脚本,包含:

return ('(nothing selected)','Volunteers','Trustees',
'Quality, Education & Learning','Bereavement Support',
'Supportive Care Services','Hospice at Home',
'Day Services','Medical Team','Inpatient Unit'
,'HR','Support Services','Accounts & IT',
'Communications','Trading','Fundraising')

现在,当我更改下拉列表值并尝试保存更改时,(on @@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 776, in update
  Module zope.formlib.form, line 620, in success
  Module plone.app.users.browser.account, line 64, in handle_edit_action
  Module zope.formlib.form, line 543, in applyChanges
  Module zope.formlib.form, line 538, in applyData
  Module zope.schema._bootstrapfields, line 227, in set
  Module kcs.userdata.adapter, line 20, in set_team
  Module Products.PlonePAS.tools.memberdata, line 261, in setMemberProperties
  Module Products.PlonePAS.sheet, line 75, in setProperty
  Module Products.PlonePAS.sheet, line 72, in validateProperty
PropertyValueError: Invalid value (Volunteers) for property 'team' of type lines

我也尝试将Value字段设置为linesand string,但两者都导致相同的回溯,但是底线的lines单词被替换为stringorselection等​​。

使用的代码

这些是我在插件中使用的代码摘录,用于将选择框添加到用户注册中:

适配器.py

def get_team(self):
  return self.context.getProperty('team','')
def set_team(self, value):
  return self.context.setMemberProperties({'team': value})
team = property(get_team, set_team)

用户数据架构.py

team = schema.Choice(
  title=_(u'label_team', default=u'Select your team'),
  description=_(u'help_team', default=u"Select your team from the list below"),
  values = [
    _(u'Volunteers'),
    _(u'Trustees'),
    _(u'Quality, Education & Learning'),
    _(u'Bereavement Support'),
    _(u'Supportive Care Services'),
    _(u'Hospice at Home'),
    _(u'Day Services'),
    _(u'Medical Team'),
    _(u'Inpatient Unit'),
    _(u'HR'),
    _(u'Support Services'),
    _(u'Accounts & IT'),
    _(u'Communications'),
    _(u'Trading'),
    _(u'Fundraising')
  ],
  required=True,
)

memberdata_properties.xml

<?xml version="1.0"?>
<object name="portal_memberdata" meta_type="Plone Memberdata Tool">
  <property name="position" type="string"></property>
  <property name="linkedin" type="string"></property>
  <property name="team" type="choice"></property>
  <property name="accept" type="boolean"></property>
</object>

属性工具.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" />
      <element value="linkedin" />
      <element value="team" />
      <element value="accept" />
    </property>
  </object>
</object>

如果我需要提供更多信息,请告诉我,任何想法将不胜感激。

4

0 回答 0