我创建了一个自定义表单,以便将字段添加到@@个人信息表单中。我发现可以使用set_own_login_name()
Products.CMFPlone.utils
更改登录名
在我的表单适配器中,我有类似的东西:
def get_username(self):
prop = self.context.getUserName()
return prop
def set_username(self, value):
id = self.context.getProperty('id', '')
value = id if (value == None) else value
return utils.set_own_login_name(self.context, value)
username = property(get_username, set_username)
正在更改login_name,但在单击表单上的“保存”按钮后,表单仍显示原始值。刷新页面后(不重新提交表单),然后显示正确的值。
那么如何强制get_username()
重新索引属性或导致在没有页面刷新的情况下返回新的login_name?
更新:我发现我可以重定向并修复问题,但我希望有人有更优雅的解决方案。似乎应该有一种更直接的方式来更新房产。这是我的解决方法:
data = {}
def get_username(self):
prop = self.context.getUserName()
self.data = {'old': prop, 'new': prop}
return prop
def set_username(self, value):
id = self.context.getProperty('id', '')
value = id if (value == None) else value
self.data['new'] = value
return utils.set_own_login_name(self.context, value)
username = property(get_username, set_username)
def __del__(self):
if (self.data['new'] != self.data['old']):
portalUrl = getToolByName(self.context, 'portal_url')()
self.context.REQUEST.response.redirect(("%s/@@personal-information") % portalUrl)