getMediaPresentation.py

getMediaPresentation.py — Python Source, 1Kb

ファイルのコンテンツ

## Script (Python) "getMediaPresentation"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=obj
##title=Return referenced media object's presentation
##
from Products.CMFCore.utils import getToolByName

INTERFACE = 'Products.COREBlog2.interfaces.IInlineObject.IInlineObject'

itool = getToolByName(context, 'portal_interface')

try:
    if itool.objectImplements(obj, INTERFACE) and obj.isInlineObject():
        tp,macro = obj.getInlineView()
        if tp and macro:
            return container[tp].macros[macro]
except:
    pass

# Metal tempate for media handler
tp = container['media_view']
macro_keys = tp.macros.keys()
ct = ''
try:
    ct = '_' + obj.getContentType()
    ct = ct.replace('/','_')
except:
    pass

# First,see object portal_type and return appropreate template
otp = obj.portal_type
try:
    otp = otp.replace(' ','')
except:
    pass
lotp = obj.portal_type.lower()

key_trials = [otp,lotp,otp + ct,lotp + ct]

for trial in key_trials:
    if trial in macro_keys:
        # The macro for object is there !
        return tp.macros[trial]

# No custom template, so return object itself...
return tp.macros['Othrers__']
このBlogについて
Plone, Zope, Pythonなどのトピックについてのメモです。
カテゴリ
Plone (98)
Plone Products (23)
COREBlog2 (31)
COREBlog1 (29)
ReadingCOREBlog (7)
Zope (66)
Turbogears (18)
Django (12)
Python (25)
Linux (30)
Nagosui (11)
Design (33)
Misc (48)
moblog (5)
最近のエントリ
Glossy Horizontal Menuを使う nyusuke 2008年11月17日
第3回Python東海終了 nyusuke 2008年11月17日
Universalじゃない件 nyusuke 2008年11月15日
CorruptedErrorが出たので直す nyusuke 2008年11月14日
最近のコメント
Re:WebデザイナーのためのDjangoはじめの一歩 nyusuke 2007年06月01日
Re:WebデザイナーのためのDjangoはじめの一歩 pateo 2007年05月31日
Re:東海Python Workshop 01終了 nyusuke 2007年05月31日
Re:東海Python Workshop 01終了 kfuruhata 2007年05月30日