# -*- coding: utf-8 -*- #$Id$ ############################################################################# # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################## # __init__.pyはZopeが最初に呼び出すコードです。ここでプロダクトとして登録し # たり、セキュリティーやロールを設定します。 from Products.Archetypes.public import process_types, listTypes from Products.CMFCore import utils from Products.CMFCore.DirectoryView import registerDirectory from permissions import initialize as initialize_permissions from config import * ##Import tools and utilities here # SKINS_DIR以下のサブディレクトリ全てを Filesystem Directory View として登 # 録します。 registerDirectory(SKINS_DIR, GLOBALS) # Zopeがプロダクトの初期化のために最初に実行する関数です。コードで表現する # と以下のようになります。 # import Products.ATExtFlash # Products.ATExtFlash.initialize(context) def initialize(context): ##Import Types here to register them # Zopeがinitializeを呼び出した時点で、関連する全てのpythonコードを呼び # 出しておくことで、refresh実行時に再読込の対象となります。また、コンテ # ンツタイプ実装クラスの登録もここで行います。ATExtFlashでは、 # content/__init__.py でコンテンツタイプ実装クラスの記述されているモジ # ュールをimportしているので、ここではcontentをimportするだけで全てのコ # ンテンツタイプがArchetypeに登録されます。 import content # Archetypeに登録済みのコンテンツタイプ情報を取り出します。Archetypeへ # の登録はcontent/atextflash.pyでregisterTypeを呼び出して、 # atextflash.pyのimport時に行っています。 # Products.Archetypes.public.process_types()は、コンテンツタイプ、コン # テンツのコンストラクタ、ファイルタイプインフォメーション(FTI)がそれぞ # れリストで返します。 content_types, constructors, ftis = process_types( listTypes(PROJECTNAME), PROJECTNAME) # このプロダクトに特有のパーミッションやロールを取得します。取得される # 情報の定義はATExtFlash.permissions で行っています。 permissions = initialize_permissions() # コンテンツタイプのリストとコンストラクタのリストを、"コンテンツタイプ # とコンストラクタのタプル" のリストに変換して次の処理を扱いやすくして # います。 allTypes = zip(content_types, constructors) # 各コンテンツタイプを順番に登録します。 for atype, constructor in allTypes: kind = "%s: %s" % (config.PROJECTNAME, atype.archetype_name) # CMFCoreのコンテンツタイプ初期化関数を呼び出してコンテンツタイプを # 登録します。 utils.ContentInit( # ZMIのオブジェクト追加ドロップダウンメニューに表示される名前で # すが、内部ではmeta_typeとして扱われます。ただし、各コンテンツ # タイプ実装クラスで設定しているmeta_typeとの関連はありません。 kind, # kind(meta_type)で追加できるコンテンツタイプ実装クラスオブジェ # クトのタプルを設定します。複数指定した場合、ZMIで追加実行時に # どのコンテンツタイプのオブジェクトを追加するか選択するメニュ # ー画面が表示されます。 content_types = (atype,), # initialize_permissions()で取得した情報のうち、今登録しようと # しているコンテンツタイプのパーミッション情報を指定します。 permission = permissions[atype.portal_type], # オブジェクト追加時に実行されるコンストラクタを指定します。 # content_types引数に設定した要素数と同じ数のコンストラクタが必 # 要です。 extra_constructors = (constructor,), # ファイルタイプインフォメーションを設定します。 fti = ftis, # ContentInitの初期化実行関数を呼び出します。CMFCoreとして必要 # な処理を行った後で、Zopeへのプロダクト登録関数を呼び出してい # ます。 ).initialize(context)