二月 4, 2012

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Products.AutocompleteWidget Sample

Products.AutocompleWidget 有支援 Plone 4.x,範例程式碼並不多,因此特別記錄找到的:

測試結果,使用 multiValued=True 後,編輯介面才看得到變化。

"""Definition of the Wiki Doc content type
"""

from zope.interface import implements, directlyProvides

from Products.Archetypes import atapi
from Products.Archetypes.public import LinesField
from Products.Archetypes.public import DisplayList
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata
from Products.AutocompleteWidget.AutocompleteWidget import AutocompleteWidget
from Products.CMFCore.utils import getToolByName


from tlc.kbase import kbaseMessageFactory as _
from tlc.kbase.interfaces import IWikiDoc
from tlc.kbase.config import PROJECTNAME

WikiDocSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((


LinesField('tags',
searchable=1,
required=0,
mutator='setTagSubject',
accessor='getTagSubject',
edit_accessor='getTagSubject',
vocabulary='getSubjectVocab',
widget=AutocompleteWidget(label='Tags'),
enforceVocabulary=0,
),

))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

WikiDocSchema['title'].storage = atapi.AnnotationStorage()
WikiDocSchema['description'].storage = atapi.AnnotationStorage()

schemata.finalizeATCTSchema(WikiDocSchema, moveDiscussion=False)

class WikiDoc(base.ATCTContent):
"""Description of the Example Type"""
implements(IWikiDoc)

meta_type = "Wiki Doc"
schema = WikiDocSchema

title = atapi.ATFieldProperty('title')
description = atapi.ATFieldProperty('description')

def setTagSubject(self, value):
"""Set tag widget contents to subject of object"""
self.getField('subject').set(self, value)

def getTagSubject(self):
"""Set tag widget contents to subject of object"""
return self.Subject()

def getSubjectVocab(self):
"""Get subject (keywords) vocabulary"""
catalog = getToolByName(self, 'portal_catalog')
return catalog.uniqueValuesFor('Subject')

atapi.registerType(WikiDoc, PROJECTNAME)

一月 14, 2012

hoamon's sandbox
hoamon
hoamon's sandbox is about »

tag cloud

» 「作弊的文化」讀後感

---- 聲明開始 ----


要檢討別人前,先自我檢討。

過去我曾在工作上,利用公司列表機印了幾本 PDF 書籍(大概幾千頁吧!),想當然耳,那些 PDF 檔還是違反著作權抓來的。印了近 10 本後就不這麼作了,因為浪費我的時間,印出來後還得整理裝訂,有時候列表機卡紙,也得自己處理,這根本就是打自己巴掌。於是,我直接花錢請印刷店處理,雖然書錢是自己出的,但一樣不脫「違反著作權」這條法令。等到會上 amazon 買書後,就不印了。買原版的書又精美,又對得起作者,何必跟自己良心過不去。當時自己印得不精美的書,後來也是全丟了,真對不起那些樹木。


另外在軟體使用(N 年前)上,也盜了不少的軟體: Matlab, MS Office, Windows 2000, Windows XP, 嘸蝦米輸入法, Dreamweaver, VisualBasic 6...。後來接觸 Open Source 後,一個一個戒掉了,因為要花錢的軟體,沒有比較好用。現在我用 Ubuntu Linux, Python, Netbeans 來工作,偶爾要用 MS office 時,就把裝在 VirtualBox 裡的學校授權 windows xp 打開,然後使用學校授權的 MS office 來看文件。是的,沒錯,中興大學花了一筆微軟授權費讓我可以在受到他人強迫時,不致於違法。


現在算來,我只有「嘸蝦米輸入法」是自己花錢買一套的,至今未買過其他軟體,當然這不含強迫中獎的微軟隨機版 OS ,還好後來的廠商自己也知道這不合理,所以我才買得到無 OS 的 Notebook 。


最後是音樂、電影,過去會用 emule, bittorrent 等作違法下載,但自從有了中華電信 MOD, 網樂通, Youtube 後,就不這麼作了。以前抓電影,還得自己找字幕、種子。用 mod, 網樂通方便多了,不過花個幾十塊而已。而音樂多半就聽我以前 CD 轉來的 OGG ,要不然就是在 youtube 上找 MV 來聽。


用 mod, 網樂通看電影很不錯,但還是有個缺點,電影類型不夠豐富,違法下載已有一堆網址了,但至今我還看不到「全境擴散(Contagion)」有在上映。只能繼續等,要不就是去買它的 DVD ,不過,現在好像也沒得買合法的。別叫我買 amazon 的 DVD ,我自認英聽還不夠好,沒字幕我是看不懂地。


我大學時是很少考試作弊或是抄別人報告的,要不然就不會被當了三十幾個必修學分,像我的結構學考試向來都是拿 6 分的,因為抄一題題目,老師會給 1 分,我乖乖地抄了 6 題。印象中,只有一堂經濟學考試是幫同學作弊,給他看答案,其他應該沒了吧! 如果還有,那就是我記性不好想不起來了。而研究所以後,我開始認真讀書了,不但成績比大學好很多,也不蹺課了。


以上,大概就是我過去作弊的事。


---- 聲明結束 ----


某日幫老婆在中教大圖書館找書時,不小心看到的一本 2006 年出版的書:「作弊的文化」。

以前很喜歡逛書局、圖書館,有興趣的題材當然會翻,但更有趣的是因為工作人員排列習慣不同,常常會發現一些原本我沒機會瞄到,但事後卻發現很令人驚喜的書。雜食是件好事,這在我接觸「指數投資|被動投資」後體會更深。也在塑化劑事件後,對入口食品改採混亂原則。以前我中餐吃飯時可以連吃同一家的陽春麵半年,也不會受不了,當時的想法很簡單,這世界就那麼多家店讓我吃,如果累計起來,這碗陽春麵總共吃了 180 次,那我就連續吃完 180 次後再去煩惱要改吃什麼,省得我每天花心思在思考吃什麼。但現在不這麼作了,我怕連吃某樣食物半年,體內單一毒素太高,一次就畢業了。混著吃,不同毒物的累計量會平均一點。

這本書題材很特別,主要介紹美國氾濫的作弊文化: 學生考試作弊、購買或抄襲他人報告、入學及畢業資格花錢買來、假造學經歷、律師浮報鐘點、會計師協助作假帳、逃漏稅、侵佔公司資產(包含小物件,像是筆、紙)、使用禁藥、以商逼官或是商人去當官人…等現象。

作者提了一些改正措施,不過,我不相信他講得是對的。因為就算他講得對,也無法施行改正來證明措施正確。那當然他也歸納了一些想法來論述為什麼美國人會作弊,這作弊現象是由來已久,還是最近才興起的。同樣地,我也不相信他的歸納,因為我看過「黑天鵝效應」,歸納不見得是有意義的。

那這本書到底對我有沒有價值? 有! 當然有,看這本書,能夠讓我了解美國人作弊的手段有那些,只要作者是誠實以對,是科學訪談來的資料,就能讓我對美國生活有進一步的體會,這就是對我的價值。

學生考試作弊、購買或抄襲他人報告、入學及畢業資格花錢買來、假造學經歷這幾樣也可在臺灣社會體會到,這應該不難想像吧! 而且美國是更氾濫的。因為美國有很多"""高級"""私立學校是可以被「錢」操控的,建議各位可以去看看「女人香」這部電影。

而律師浮報鐘點,可以去看看「黑色豪門企業」這部電影來一窺全貌。

會計師協助作假帳,可以去看看「世界通訊」、「安隆」的倒閉新聞。

在逃漏稅部份幾乎是全民運動。在「蘋果橘子經濟學」中,也提到某一年全美國少了幾百萬個小孩,因為國稅局全面電腦化,可以比對大家的扶養子女是否有重複。

侵佔公司資產(包含小物件,像是筆、紙),我印象中好像有部電影提到職員拿到公司的信用卡後,結果大刷特刷的,忘了是那一部了。

使用禁藥部份請看艾拉馬奎爾麥可強森的故事。

以上作弊的事就請各位自行搜尋資料或是去看本書來深入了解。我想要討論的是「以商逼官或是商人去當官人」這種事。而且想從美國的現象來討論臺灣在這一部份的問題。

商人當官人,在臺灣政壇上,好像只有發生在「縣市首長」及「立委、議員」上,內閣部份就我印象以來,大概都是國營的金融相關事業董事長後來會當到財經首長,像是彭淮南先當中國商銀董事長後轉任中央銀行總裁,陳裕章從第一金董事長作到金管會主委,好像只有陳沖有當過合庫銀、中信證(民營)、永豐金(民營)董事長後再來作金管會主委及行政院副院長,其他的首長多半是先當官人,後才去當商人的,像是顏慶章、邱正雄、林全。就商人來當官人這件事,我覺得中華民國的防火牆作得還不錯。不像美國,一堆財政部長都是從華爾街跑去的,這一點可去看「高盛陰謀」來略知一二。

商人當官人有什麼不對? 如果是靠選舉選上的,那我沒話說,民主時代,選民接受商人當首長,也了解他會有利益衝突但還是讓他選上,這我沒話說,選後是大家一起承擔的。

但如果是指派的,那就大有問題了。因為無法直接監督,卻又得面臨他瓜田李下,所以可以看到 2008 美國次貸後,高盛活得比貝爾斯登、雷曼兄弟、美林、摩根史坦利還好。要不然,你們也可以想像一下,公共工程委員會主委曾任職於某家營造廠,那他監督的了舊公司所承攬的公共工程嗎? 搞不好,有些還是他經手的呢! 所以幸運的是這種事在中華民國不常發生。這值得慶祝。

而「以商逼官」這件事,我覺得臺灣就很嚴重了。當然,還沒有比美國嚴重啦。


上面這部影片,提到「公司」撥出大量的行銷支出去為候選人宣傳,這無非是希望將「有利於公司」的候選人送進政府體制中,在行政、立法方面協助公司經營。

除了送「合宜候選人」進政府體制,另外還有「形塑輿論」以迫使公務員執行政策轉向,因為公務員『買廣告』去宣傳政策是件不容易的事。要『買廣告』去宣傳,通常只能用在『拍馬屁』上。

有幾件類似『形塑輿論』的事,我分享給各位,但也有可能是我錯了,畢竟『形不形塑』都應該是檯面下的事:
  1. 別讓彭淮南總裁變成下一個袁崇煥!
  2. 證券交易所得稅會讓政府抽很多錢,導致沒有利潤。
  3. 立委名額太多是導致國會亂象的主因,所以我們要刪減立委名額。
第一項,中央銀行的作為是不容外界質疑的,它也不受其他首長的管理,那新聞、報紙講新台幣該不該升值、貶值,幹麼? 削總裁威信,看能不能讓高層換個人,如果不能,或許也能逼總裁心死離職。總之,一個獨立性機關建立了,也找了個正確人選進去,那再指三道四都是不對的。

第二項,很多股民在郭宛容事件後,堅信課徵證所稅是件可怕的事,他們不管租稅正義,只在乎股票表面價值。於是,永遠都是在分皮毛,然後讓大戶吃香喝辣。

第三項,刪減立委名額後,可以看見國會的政黨種類急速減少,從2004年2008年的結果看來,2004年泛藍 128 名,泛綠 147 名,其他有 148 名,小黨比例佔有 35 %,而 2008 年泛藍有 114 名,泛綠有 101 名,其他有 16 名,小黨比例佔有 7 %。小黨比例急速萎縮下,失去了政策多樣性。企業要買通立委,也可以花比較少的人力、金錢。這對弱勢團體來說,只有更失去支持聲音,看不來有什麼其他好處。

另外,還有一種是我覺得「大有問題」的「輿論」:「公務員領得錢比人多,事作得比人少」。

醜化公務員後,要幹麼呢? 首先大家都認為他們爛,所以就不介意立委們削他們預算,甚至讓機關合併但員額減少。事變多了,人卻少了,那他們就不能管那麼多事了。他們不能管那麼多事後,則「黑心企業」就爽啦! 沒人力來稽查業務,甚至要打通關節時,需賄賂的人沒那麼多,這對「黑心企業」都是成本下降的好機會。如果我開的是「黑心企業」,「醜化公務員」絕對是一條好策略。

在「作弊的文化」中,它也提到 IRS 被削弱資源,使得他們無法向逃漏稅的有錢人提出訴訟,因為有錢人有能力與 IRS 乾耗。使得他們只好把目標對向一般平凡百姓,這一類人往往無法找到高級稅務律師反辯。諷刺的是 IRS 資源正是被廣大的美國百姓要求刪減的,因為他們極度討厭稅務員。

簡單講,老鼠去說貓的壞話,結果主人相信了,還把貓趕走,那接下來是誰的天下?

但是話說回來,我們如何能分辯什麼是正確的「輿論」。

首先,別相信「廣告」:


這個廣告聽說效果很好。讓很多人下定決心投給那個團隊,不過,仔細想想,這「準備好了」四個字,講也只花了 5 秒鐘。但一個政策執行要花多少時間,像蘇花高從環島路網決策成形、選址、測量、工法決定…也花了幾十年了。你聽到「準備好了」也是花 5 秒鐘,但你該相信嗎? 另一個有「魔力的廣告詞」是「馬上好」,很多人聽到這句話後,就莫明奇妙地把票奉上了。我覺得很可笑。

第二個,要分得清那個是「廣告」:

看雜誌時,出版商常常把廣告作成報導本文,如果你沒能力分得出來,那如何知道那個是忠實報導,那個是自吹自擂。不過,像這類會把「廣告」及「本文」混合的出版商,最好把它們的讀物當作資源回收物,看過即忘。

第三個,少看新聞及雜誌,多看點書(也就是第一手資料,像是候選人政策白皮書):

了解政治或是選擇正確人選,從新聞、雜誌上獲得的幫助不大。多看點書來了解你想要的理想世界是什麼,這樣你才有學識去要求候選人作到。然後要看候選人政策白皮書,這樣你才知道,這個候選人到底想要作什麼,你也才有得選擇,別去聽新聞記者的轉述,二手資料常常是錯的。

最後我的結論是「了解作弊的手段是有助不作弊的人贏得比賽的法門」,所以不管你想不想、愛不愛,都得了解「作弊的方法」。

十二月 29, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Files to Edit for Adding Archetypes Type

除了用 zopeskel 來建立 Content Type 的方法,手動編輯檔案的話,下列是相關檔案的順序列表:

interfaces/__init__.py
interfaces/mytype.py
content/configure.zcml
content/mytype.py
profiles/default/factorytool.xml
profiles/default/types.xml
profiles/default/types/mytype.xml
config.py
browser/configure.zcml
browser/mytype.py
browser/templates/mytype.pt
locales/

十二月 27, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» typesUseViewActionInListings in Plone PropertiesTool

In my archetypes-based project, I create a folderish type Book to contain Chapter type. One of the last steps is to add Chapter type in typesUseViewActionInListings field.

For GenericSetup, it is in profiles/default/propertiestool.xml:

<property name="typesUseViewActionInListings" type="lines">
<element value="Image"/>
<element value="File"/>
<element value="Chapter"/>
</property>

Note that if Book added to that field, it will be bothering when you browse Book items in Contents tab.

十二月 19, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Collective TinyMCE Templates

collective.tinymcetemplates is a TinyMCE Plugin for templates and snippets. It works with Plone 4.1.3. You can see a "Insert predefined template content" icon added:

» Transmogrifier Export in Action

transmogrifier 可以匯入或匯出 Plone 網站的內容,之前的經驗以匯入 CSV 或 PostgreSQL 資料為主,現在完成匯出到 PostgreSQL 的實作。

以 develop.cfg 為例,要修改的內容如下:

eggs +=
psycopg2
SQLAlchemy == 0.6.5
zope.sqlalchemy
plone.app.transmogrifier

客製 myproj.transmogrifier 的內容摘要如下:

myproj.transmogrifier/configure.zcml

<transmogrifier:registerConfig
name="myproj.transmogrifier.exportContent"
title="MyProject Export Content"
description="Transmogrifier Pipeline config to export contents."
configuration="confs/export.cfg"
/>

<!-- register our blueprints -->
<utility
component=".contentexport.ContentExporterSection"
name="myproj.transmogrifier.contentexporter"
/>

myproj.transmogrifier/browser/configure.zcml

<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:zcml="http://namespaces.zope.org/zcml">

<browser:page
for="*"
class=".contentexport.ContentExport"
name="content-export"
permission="cmf.ManagePortal"
/>
<configure>

myproj.transmogrifier/browser/contentexport.py

class ContentExport(BrowserView):

def __call__(self):
transmogrifier = ITransmogrifier(self.context)
transmogrifier('myproj.transmogrifier.exportContent')
self.request.response.write('exported')

myproj.transmogrifier/confs/export.cfg

[transmogrifier]
pipeline =
contentexport

[contentexport]
blueprint = myproj.transmogrifier.contentexporter
dsn = postgresql://myuser:mysecret@localhost:5432/mydb
portal-types = News Item, Event
review-states = published

另外,還有 myproj.transmogrifier/models.py 和 myproj.transmogrifier/contentexport.py 兩個主檔,分別負責資料庫連線和匯出工作。

十二月 18, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Search Portlet for Current Section

By default, Plone provides a searchbox viewlet and a search portlet. With the viewlet, you can decide whether to search only within the current section. However, the porlet does not apply this behavior. My requirement could be illustrated by this screenshot:

Here are the files to be modified:

$ diff plone/app/portlets/portlets/search.py
55a56,61
> def folder_path(self):
> context_state = getMultiAdapter((self.context, self.request),
> name=u'plone_context_state')
> folder = context_state.folder()
> return '/'.join(folder.getPhysicalPath())
>

$ diff plone/app/portlets/portlets/search.pt
29a30,44
>
> <div class="searchSection">
> <input id="searchbox_currentfolder_only"
> class="noborder"
> type="hidden"
> name="path"
> tal:attributes="value view/folder_path"
> />
> <label for="searchbox_currentfolder_only"
> i18n:translate="label_searchbox_currentfolder_only"
> style="cursor: pointer">
> only in current section
> </label>
> </div>
>

十二月 16, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Table View in Contents Tab

Here is the default view for Plone.

I want Published column instead of Modified column. By 'grep -r listing-table' I find the target file is at plone.app.content/browser/table.pt. Related python files are batching.py, container.py and browser/tavleview.py. My naive guess of changing keyword modified to effective, does not work, showing LocationError.

» Display Logos Based on Paths

Here is a customization in plone.app.layout/viewlets/common.py that can display customized logos based on tab paths.

class LogoViewlet(ViewletBase):
index = ViewPageTemplateFile('logo.pt')

def update(self):
super(LogoViewlet, self).update()

portal = self.portal_state.portal()
bprops = portal.restrictedTraverse('base_properties', None)
if bprops is not None:
logoName = bprops.logoName
else:
logoName = 'logo.jpg'
plone_url = getToolByName(self.context, 'portal_url')()
plone_url_len = len(plone_url)
request = self.request
url = request['URL']
path = url[plone_url_len:]
if path.startswith('/news'):
logoName = 'logo-news.png'
if path.startswith('/events'):
logoName = 'logo-events.png'

To illustrate how the path variable works, add a Python Script in ZMI and use the following sample code:

from Products.CMFCore.utils import getToolByName

plone_url = getToolByName(context, 'portal_url')()
print "plone_url = %s\n" % (plone_url),
plone_url_len = len(plone_url)
request = context.REQUEST
url = request['URL']
path = url[plone_url_len:]
print "url = %s, path = %s" % (url, path)
return printed

十二月 15, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» portal_tab globalnav customization

portal_tab, or globalnav, or global_section in Plone, provides clickable links. Let's say, we want a tab to open in new browser window when clicked. The trick is in plone.app.layout/viewlets/sections.pt.

<ul id="portal-globalnav"
tal:define="selected_tab python:view.selected_portal_tab"
><tal:tabs tal:repeat="tab portal_tabs"
><li tal:define="tid tab/id;
turl tab/url"
tal:attributes="id string:portaltab-${tid};
class python:selected_tab==tid and 'selected' or 'plain'"
><a href=""
tal:content="tab/name"
tal:attributes="href tab/url;
title tab/description|nothing;
target python: (turl.endswith('/my-url') and '_blank' or '')">
Tab Name
</a></li></tal:tabs></ul>

十二月 7, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Localization with i18ndude

以 develop.cfg 為例,先在 parts 裡加一行 i18ndude,再加一整段的 [i18ndude] 內容:

parts =
...
i18ndude

[i18ndude]
unzip = true
recipe = zc.recipe.egg
eggs = i18ndude

以 my.example 模組專案為例,處理 .po 檔案的步驟如下:

$ cd src/my.example/my/example
$ vi configure.zcml
<configure
xmlns:i18n="http://namespaces.zope.org/i18n"

<i18n:registerTranslations directory="locales" />

$ mkdir -p locales/zh_TW/LC_MESSAGES
$ i18ndude rebuild-pot --pot locales/my.example.pot --create my.example .
$ touch locales/zh_TW/LC_MESSAGES/my.example.po
$ i18ndude sync --pot locales/my.example.pot locales/zh_TW/LC_MESSAGES/my.example.po
$ msgfmt -o locales/zh_TW/LC_MESSAGES/my.example.mo locales/zh_TW/LC_MESSAGES/my.example.po

如果有手動增加的 po 內容,通常是寫在 manual.pot 裡,再用下列指令併進 pot 檔案裡。

$ i18ndude rebuild-pot --pot locales/my.example.pot --create my.example --merge manual.pot .

十二月 6, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Creating Windows Buildout Project

試著在 Windows 建立 Plone 4.1.2 的 Buildout 專案環境,事先要安裝 Python 2.6.7、PyWin32PIL 1.1.6easy_installSubversionGit。再下載安裝 zopeskel:

C:\> easy_install zopeskel

接著,可以用 zopeskel 來建立 Buildout 專案,範例指令如下:

C:\> mkdir Plone
C:\> cd Plone
C:\Plone> zopeskel basic_buildout

basic_buildout: A basic buildout skeleton
This creates a basic skeleton for a buildout.
Enter project name: myproj

If at any point, you need additional help for a question, you can enter
'?' and press RETURN.

Expert Mode? (What question mode would you like? (easy/expert/all)?) ['easy']:

如果遇到下列訊息,可以予以略過不理會:

UserWarning:
You don't have the C version of NameMapper installed!
I'm disabling Cheetah's useStackFrames option as it is painfully slow
with the Python version of NameMapper.
You should get a copy of Cheetah with the compiled C version of NameMapper.
You don't have the C version of NameMapper installed!

剛建立的 myproj 專案目錄裡,只有 bootstrap.py 和 buildout.cfg 兩個檔案,執行 python bootstrap.py 之後,會建立必要的目錄架構,特別是 bin 目錄裡會建立 buildout 工具程式,額外的撇步是指定 zc.buildout 版本是 1.4.4,不然預設裝的 1.5.2 版本會造成衝突,範例訊息如下:

C:\Plone\myproj> python bootstrap.py -v 1.4.4
Downloading http://pypi.python.org/packages/2.6/s/setuptools/setup
tools-0.6c11-py2.6.egg
Creating directory 'C:\\Plone\\myproj\\bin'.
Creating directory 'C:\\Plone\\myproj\\parts'.
Creating directory 'C:\\Plone\\myproj\\eggs'.
Creating directory 'C:\\Plone\\myproj\\develop-eggs'.
Getting distribution for 'setuptools'.
Got setuptools 0.6c12dev-r88846.
Generated script 'C:\\Plone\\myproj\\bin\\buildout'.

預設的 buildout.cfg 檔案內容如下:

[buildout]
parts =
templer

[templer]
recipe = zc.recipe.egg
eggs =
PasteScript
templer.core

不過,我並沒使用這個 buildout.cfg 內容,而是直接複製 Linux 環境上安裝的 *.cfg 檔案,修改 base.cfg 和 lxml_static.cfg 的 eggs-directory 和 download-cache 配合 Windows 環境的目錄,再執行 buildout:

C:\Plone\myproj> bin\buildout -c develop.cfg
mr.developer: Creating missing sources dir C:\Plone\myproj\src.
Getting distribution for 'zc.recipe.egg==1.2.2'.
Got zc.recipe.egg 1.2.2.
Getting distribution for 'plone.recipe.zope2instance==4.1.9'.
Got plone.recipe.zope2instance 4.1.9.
Getting distribution for 'Zope2==2.13.10'.
Installing Zope2 2.13.10
Caused installation of a distribution:
zope2 2.13.10
with a different project name.
Got zope2 2.13.10.
Getting distribution for 'mailinglogger==3.3.3'.
Got mailinglogger 3.3.3.
Getting distribution for 'nt-svcutils==2.13.0'.
Got nt-svcutils 2.13.0.
Getting distribution for 'Products.StandardCacheManagers==2.13.0'.
Installing Products.StandardCacheManagers 2.13.0
Caused installation of a distribution:
products.standardcachemanagers 2.13.0
with a different project name.
Got products.standardcachemanagers 2.13.0.
Getting distribution for 'Products.PythonScripts==2.13.0'.
...

安裝 Pillow 時,需要安裝 Visual Studio 2008 Express,據說 2008 之外的版本並不行:

error: Setup script exited with error: Unable to find vcvarsall.bat
An error occured when trying to install Pillow 1.7.2. Look above this message fo
r any errors that were output by easy_install.
While:
Installing instance.
Getting distribution for 'Pillow==1.7.2'.
Error: Couldn't install: Pillow 1.7.2

編譯 lxml 如果遇到錯誤,要補足需要的檔案,以 Plone 4.1.3 為例,要下載 lxml 2.3.2 的原始碼。如果沒成功的話,還可以試試直接安裝較低的 lxml 版本

十二月 2, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» File-explorer like Document Management Tool

collective.edm.listing provides a custom view for folder. It works with Plone Quick Upload to upload new files.

十一月 26, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» POSKeyError: 'No blob file'

執行 Plone migration 時,遇到 POSKeyError 錯誤,發現某個目錄裡的 File 內容出了問題,刪除這些 File 之後,就可以順利從 Plone 4.0.5 昇級到 4.1.2。

十一月 23, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Content Not Existing?

遇到 Plone instance 透過 http://mysite.com/news-events 之類的網址,出現「網頁並不存在」的訊息,透過 http://mysite.com/news-events/folder_contents 網址是可以看到內容,最後發現用 http://mysite.com/news-events/selectViewTemplate?templateId=folder_listing 之類的方式,就能解決問題。發生原因是之前選用了 lead image 擴充模組的顯示方式,當這個顯示方式不存在時,就會造成網頁無法正常顯示的問題。

十一月 19, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Content Type Extension

SchemaExtender 可以動態調整 Archetypes 型別定義值,下列是一個 extender.py 範例:

from zope.component import adapts
from zope.interface import implements

from archetypes.schemaextender.interfaces import ISchemaExtender
from archetypes.schemaextender.field import ExtensionField
from plone.app.blob.field import BlobField

from Products.Archetypes import atapi

from example.blobattype.interfaces import IExampleATType
from example.blobattype import blobattypeMessageFactory as _


class ExtensionBlobField(ExtensionField, BlobField):
""" derivative of blobfield for extending schemas """


class ExampleATTypeExtender(object):
adapts(IExampleATType)
implements(ISchemaExtender)

fields = [
ExtensionBlobField('afile',
widget=atapi.FileWidget(
label=_(u"A file"),
description=_(u"Some file"),
),
required=True,
validators=('isNonEmptyFile'),
),

ExtensionBlobField('secondfile',
widget=atapi.FileWidget(
label=_(u"Some other file"),
description=_(u"Some other file"),
),
required=True,
validators=('isNonEmptyFile'),
),
]

def __init__(self, context):
self.context = context

def getFields(self):
return self.fields

十一月 17, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» ATBTreeFolder vs ATFolder

最近把一個 Plone 網站從 3.3.5 昇級到 4.0.7,在 ZMI 裡看得到 ATBTreeFolder 和 ATFolder 兩種目錄型別,ATBTreeFolder 就是所謂的 Large Folder,在 Plone 3 之前的時代,用它來儲存大量的內容項目,到 Plone 4 之後,目錄型別被統合了

ATBTreeFolder 在 ZMI 裡提供 Security 設定頁籤,可以指定 Local Roles,不過 Plone 4 裡的 ATFolder 並沒有這樣的設定介面,必須搭配 plone.app.workflow 編輯 sharing.xml 來擴充權限設定介面

十一月 10, 2011

limodou的學習記錄
limodou
limodouµÄѧϰÉú»î is about »
» sphinx i18nµÄÖ§³Ö

ʹÓÃSpninxÊÇÖ§³Öi18nµÄ£¬ÎĵµÔÚÕâÀï¡£

Ò»¡¢·­Òë

¾­¹ýÎÒµÄÊÔÑ飬¾ßÌåµÄÃüÁî¾ÍÊÇ£º

sphinx-build -b gettext -d ../locale/doctrees ./ ../locale/en

-b gettext ±íʾҪÉú³Épot¸ñʽ

-d ../locale/doctrees ºÃÏóÊÇ»º´æ

./ Ô´ÎļþĿ¼

../locale/en Êä³öĿ¼

Õâ¸öÃüÁîÊÇ¿¼ÂÇÒÔÏÂĿ¼½á¹¹£º

/project

    /docs

        #you are here

    /locale

        /en

ÄãÔÚdocsĿ¼ÏÂÀ´½øÐвÙ×÷¡£Éú³Épotºó¾Í¿ÉÒÔ·­ÒëÁË¡£

ÒÔÉÏÃæÎªÀý£¬·­ÒëÍêµÄPOÎļþ·Åµ½ locale/en/LC_MESSAGES Ï£¬Í¬Ê±Éú³ÉmoÎļþ¡£

¶þ¡¢Éú³ÉÎĵµ

ÕâÑùmo×¼±¸Íê³É¡£ÏÂÃæÔÙ´Îͨ¹ýÕý³£µÄ·­ÒëÀ´Éú³ÉÄ¿±ê½á¹û£¬Èçhtml¸ñʽÎĵµ¡£

Ê×ÏÈÒª¼ì²éconf.pyÖÐÊÇ·ñÓÐlocale_dirsµÄÅäÖã¬Èç¹ûûÓУ¬ÔòÌí¼Ó½øÈ¥:

locale_dirs = ['../locale']

ÕâÀï¿ÉÒÔÌí¼Ó¶à¸ö¡£È»ºó£¬»òÕßÖ±½ÓÐÞ¸Äconf.pyÖеÄlanaguageµÄֵΪĿ±êÓïÑÔ£¬»òÕßÔÚ±àÒëʱÔÚÃüÁîÐÐÀ´Ö¸¶¨£¬È磺

sphinx-build -b html -d ../html/doctrees -D language=zh_CN ./ ../html

ÕâÀï²ÎÊý½âÊÍһϣº

-b html ½«Éú³Éhtml¸ñʽÎĵµ

-d ../html/doctrees »º´æÄ¿Â¼£¬ÕâÀïºÍlocaleÒª²»Í¬£¬²»È»»á±¨´í

-D language=zh_CN ÔÚÃüÁîÐÐÖ¸¶¨ÐÞ¸ÄÅäÖÃÖеÄlanaugeµÄÖµ£¬ÕâÀïΪzh_CN¡£


Àà±ð£ºPython ²é¿´ÆÀÂÛ

十一月 8, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» CMF Action Condition

使用 Products.Carousel 時,會新增一個 Carousel tab,如果想在特定的目錄裡才出現它,可以在 ZMI portal_actions/object/carousel 的 Condition (Expression) 欄位輸入下列表示式:

python: (context.id in ['carousel']) and plone_context_state.is_folderish()

十月 17, 2011

marr's weblog
marrtw
marr weblog is about »

tag cloud

» Search Events and News via Calendar Portlet

Plone 的月曆方框預設是搭配 Event 來顯示,如果某一天是在 Event 發生的期間,就可以在月曆上點選來顯示,它會先利用類似 search?review_state=published&start.query;:record:list:date... 網址格式來搜尋,如果想要增加其他內容型別到月曆方框,例如新聞的話,就要到 ZMI 的 portal_calendar 新增型別,並為型別新增 start 和 end 屬性值。

A Feedjack powered Planet
A Django site.