You need the adapted context to set the layout. I use this code for setting a mosaic layout on page create:
def set_mosaic_view(context):
request = getRequest()
safeWrite(context, request)
if not ICustomThemeLayer.providedBy(request): # pragma: no cover
return
adapted_context = ILayoutAware(context, None)
if adapted_context is not None and \
adapted_context.contentLayout is None and \
adapted_context.customContentLayout is None:
# it is OK to use context to setLayout
context.setLayout('layout_view')
# use adapted_context for setting the MOSAIC layout
if 'basic' not in _LAYOUT_CACHE:
_LAYOUT_CACHE['basic'] = resolveResource('++contentlayout++web16theme/basic.html')
# use adapted_context for setting the MOSAIC layout
adapted_context.customContentLayout = _LAYOUT_CACHE.get('basic')
I'm surprised. Exactly how did that not work? Tom is correct that there is also adapter for that, but the default adapter uses the same attributes that you set in your code. On old objects, you may need to reset custom inline layout attribute obj.customContentLayout = u'' to allow use of path in contentLayout instead.
Also, I don't recall there are indexes for those fields by default.
Default ”content layout” per content type can be set with registry configuration. I recall Mosaic’s registry.xml has example that defines the default for Document.