對網頁技術人員而言,多少都要接觸 Javascript 語言衍生的生態圈,為了和這股潮流接軌,新版 Plone 透過 Mockup 讓 Javascript 客戶端的整合,變得更容易。這個導入及轉換工作,採用 PatternsLib 設計概念,會逐步改寫 Plone 的服務工具,例如 plone.app.widgets 和 plone.app.toolbar 這兩個模組,是利用 Mockup 機制做出的成果範例。
多國語系的支援是透過 plone.app.multilingual 模組,它在 Plone 4.3 時代就存在,新版環境就是預設安裝,啟用後就能套用。下列是批次匯入內容的範例:
#!/usr/bin/python # -*- coding: utf-8 -*- from Testing import makerequest from AccessControl.SecurityManagement import newSecurityManager from Products.CMFCore.utils import getToolByName root = makerequest.makerequest(app) site = root.mysite admin = root.acl_users.getUserById('admin') admin = admin.__of__(site.acl_users) newSecurityManager(None, admin) from zope.site.hooks import setHooks from zope.component.hooks import setSite setHooks() setSite(site) site.setupCurrentSkin(site.REQUEST) from plone.dexterity.utils import createContentInContainer from plone.app.multilingual.interfaces import ITranslationManager from plone.app.multilingual import api as pamapi from plone import api as ploneapi from Products.CMFPlone.interfaces import ILanguage from plone.dexterity.utils import iterSchemata, iterSchemataForType #from plone.rfc822 import constructMessageFromSchemata #from plone.rfc822 import initializeObjectFromSchemata import csv def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs): csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs) for row in csv_reader: yield [unicode(cell, 'utf-8') for cell in row] wftool = getToolByName(site, 'portal_workflow') with open('/home/marr/plone511/zinstance/csv_script/item.csv', 'rb') as f: dialect = csv.Sniffer().sniff(f.read(), delimiters="\t") f.seek(0) reader = unicode_csv_reader(f, dialect) for row in reader: folder = site.en.events item = createContentInContainer(folder, 'Event', title=row[3]) oldid = item.id # language = ILanguage(item).get_language() # print language manager = ITranslationManager(item) manager.add_translation('en') en = manager.get_translation('en') # manager.register_translation('en', en) en.title = row[3] en.description = row[4] manager.add_translation('zh') zh = manager.get_translation('zh') zh.title = row[1] zh.description = row[2] ploneapi.content.delete(obj=item) # site.en.events.manage_renameObject(oldid, str(row[0])) # site.zh.events.manage_renameObject(oldid, str(row[0])) #wftool.doActionFor(site.en.events[str(row[0])], 'publish') wftool.doActionFor(en, 'publish') #wftool.doActionFor(site.zh.events[str(row[0])], 'publish') wftool.doActionFor(zh, 'publish') en.reindexObject() #print row[0] + " en done." zh.reindexObject() #print row[0] + " zh done." #print pamapi.get_translation_manager(item).get_translations() import transaction transaction.commit()