Plone 4: changing the login name on the @@personal-information form

僤鯓⒐⒋嵵緔 提交于 2019-12-12 13:22:29

问题


I have created a custom form to add fields to the @@personal-information form. I found that the login name can be changed by using set_own_login_name() which is provided by Products.CMFPlone.utils

In my form adapter, I have something like this:

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)

The login_name is being changed, but after clicking the "Save" button on the form, the form still shows the original value. Upon refreshing the page (without resubmitting the form) it then shows the correct value.

So how can I force get_username() to re-index the property or cause the new login_name to be returned without a page refresh?

UPDATE: I discovered that I can redirect and it fixes the issue, but I am hoping someone has a more elegant solution. It seems like there ought to be a more straight-forward way of updating the property. Here is my workaround:

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)

来源:https://stackoverflow.com/questions/8734872/plone-4-changing-the-login-name-on-the-personal-information-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!