我在我的Plone 4站點中有一個自定義註冊和@@個人喜好頁面,它有一些額外的字段,例如用於粘貼他們的社交網絡的區域鏈接和他們公司的位置 - 它還顯示他們在網站上註冊的日期。 (我用collective.examples.userdata做到這一點)Python腳本來獲取Plone中個人喜好字段的內容
我能成功使用下面的定義在頁面模板中引用這些字段:
tal:define="membership context/portal_membership;
info python:membership.getMemberInfo(user.getId());
userPosition python:user.getProperty('position');
userFB python:user.getProperty('facebook');
userLinkedIn python:user.getProperty('linkedin');
userTwitter python:user.getProperty('twitter');
userRegDay python:user.getProperty('regday')"
我想寫一個Python腳本,它會搶最後definiton python:user.getProperty('regday')
,並做一些數學來顯示他們在網站上註冊了多久。
我的劇本呼籲memberLength,是我的自定義文件夾,我一直在用下面的調用它:
tal:content="context/memberLength"
我已經嘗試了很多事情,但不斷得到回溯的錯誤,所以我真的不知道如何實現的Python告訴得到這些領域的詳細信息。我已經試過以下(下面的例子是我只是試圖讓蟒蛇獲取字段信息):
Python腳本:
membership = context.portal_membership.getMemberInfo()
return "%s" % membership
但是,它返回基本當前用戶信息(用戶名,說明等)的字典,沒有什麼對我有用的 - 我的自定義字段沒有出現在此字典中。
membership = context.getProperty('regday', 'Could not find')
return "%s" % membership
以上的回報我的「找不到」的消息,這樣也不行,同樣也適用於下面的腳本:
membership = context.portal_membership.getProperty('regday','Could not find')
return "%s" % membership
我嘗試這樣做:
membership = context.portal_membership.user.getProperty('regday','Could not find')
return "%s" % membership
但是我得到了一個AttributeError: user
回溯消息。
我也試過這個tal聲明:context/userRegDay/membershipLegth
但是那給了我一個錯誤,所以我嘗試了Python的替代方案context.userRegDay.membershipLegth()
- 但它們不起作用。
我上面的所有字段都存在於我的portal_memberdata
頁面的Properties
選項卡中。
Google在這裏幫助不大,我能找到的只有this page但是它並不能真正涵蓋我所要做的事情,據我所知。
誰能告訴我如何讓我的UserRegDay變量傳遞給我的Python腳本?或者,我是否全力以赴?
向任何經驗豐富的Plone人提前道歉,他們的血壓可能因閱讀我的嘗試而升高。
非常感謝。
不幸的是我遇到了一些問題,我想,也許userdata.examples導致某種與它的問題,更可能我的Python知識讓我失望...'member.getProperty(」 regday')似乎是返回一個對象而不是一個字符串,如果我指定了一個替代字段,比如'username',它也會返回一個對象。僅供參考我的修改後的腳本是:http://pastie.org/8610556但是,如果我直接複製並粘貼代碼並更新用戶標識,它也會返回對象,我試圖將其全部構建到列表中,但是這給了我一個回溯('成員中的item:append.mylist(item)') – Dan
更新:我試過'member.getProperty('regday','couldnt find')'並且它返回'couldnt find',所以我在想別的東西出了問題。也許更好的方法是避免'collective.examples.userdata'? – Dan
@Dan'collective.examples.userdata'定義了一些額外的字段,比如'gender'。他們在你的網站上工作嗎?另一個問題,你是否實際定製了'collective.examples.userdata'或者你有自己的實現?或者兩者同時安裝?你還可以粘貼腳本的輸出(哪個對象?)。 – Mathias