Skip to content

Instantly share code, notes, and snippets.

@l34marr
Last active December 14, 2015 06:49
Show Gist options
  • Save l34marr/5046287 to your computer and use it in GitHub Desktop.
Save l34marr/5046287 to your computer and use it in GitHub Desktop.
working with atctListTemple()
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"
lang="en-US"
metal:use-macro="here/main_template/macros/master"
i18n:domain="plone">
<body>
<metal:content-core fill-slot="content-core">
<metal:main_macro define-macro="content-core"
tal:define="result python:here.atctListTemple(temples=1, subtemples=1, folders=1, images=0, subimages=0, others=1);
temples result/temples;
folders result/folders;
otherContents result/others;
Batch python:modules['Products.CMFPlone'].Batch;
b_start python:request.get('b_start', 0);
kssClassesView context/@@kss_field_decorator_view;
getKssClasses nocall:kssClassesView/getKssClassesInlineEditable;
templateId template/getId;
batch python:Batch(temples, 128, int(b_start), orphan=1)">
<div metal:define-macro="text-field-view"
id="parent-fieldname-text" class="stx"
tal:define="kss_class python:getKssClasses('text',
templateId=templateId, macro='text-field-view');
has_text exists:context/aq_explicit/getText;
text python:has_text and here.getText() or ''"
tal:condition="text"
tal:attributes="class python:test(here.Format() in ('text/structured',
'text/x-rst', ), 'stx' + kss_class, 'plain' + kss_class)">
<div metal:define-slot="inside" tal:replace="structure text">The body</div>
</div>
<tal:foldertemples tal:condition="python:folders or temples">
<tal:temples tal:condition="batch" tal:repeat="temple batch">
<div class="templeAlbumEntry">
<a tal:define="id python:int(b_start)+int(repeat['temple'].number()-1)"
tal:attributes="href string:${temple/absolute_url}/view;
target string:_blank;
title temple/Description">
<span class="templeAlbumEntryTitle" tal:content="temple/pretty_title_or_id">
Title
</span>
<!-- span class="templeAlbumEntryWrapper"
tal:define="photo python: here.getFirstPhoto(temple)" -->
<!-- tal:photo condition="photo" -->
<!-- img src="" alt="" tal:replace="structure python:photo.tag(scale='thumb', title=photo.Description())" / -->
<!-- /tal:photo -->
<!-- /span -->
</a>
</div>
</tal:temples>
<div class="photoAlbum" tal:condition="folders">
<tal:folders tal:repeat="folder folders">
<div class="templeAlbumEntry templeAlbumFolder"
tal:define="temple_brains_in_folder python:folder.atctListTemple(subtemples=1)['subtemples'];
number_of_temples python:len(temple_brains_in_folder);
random python:modules['random'];">
<!-- random_image python:number_of_temples and random.choice(temple_brains_in_folder).getObject() or None" -->
<a tal:attributes="href folder/getURL;
title folder/Description">
<span class="templeAlbumEntryWrapper">
<!-- img src="" alt=""
tal:condition="number_of_temples"
tal:replace="structure python:random_image.tag(scale='thumb', title=folder.Description)" / -->
</span>
<span class="templeAlbumEntryTitle">
<tal:title content="folder/pretty_title_or_id">Title</tal:title>
<tal:in_temples condition="python: 'temples' in context.absolute_url()">
(<tal:number content="number_of_temples" />)
</tal:in_temples>
</span>
</a>
</div>
</tal:folders>
</div>
<div class="visualClear"><!-- --></div>
</tal:foldertemples>
<p class="discreet"
i18n:domain="atcontenttypes"
i18n:translate="text_no_albums_uploaded"
tal:condition="python:not (folders or temples)">
No albums or photos uploaded yet.
</p>
<div tal:condition="python:folders or temples"
metal:use-macro="here/batch_macros/macros/navigation" />
<tal:listing condition="otherContents"
define="folderContents otherContents">
<metal:listing metal:use-macro="here/folder_listing/macros/listing">
<metal:empty metal:fill-slot="no_items_in_listing"></metal:empty>
</metal:listing>
</tal:listing>
<metal:subtopics use-macro="here/atct_topic_view/macros/folderlisting_macro" />
</metal:main_macro>
</metal:content-core>
</body>
</html>
# Title: Helper method for temple folder view
# Parameter List: temples=0, subtemples=0, folders=0, images=0, subimages=0, others=0
# Bound Names: context, container, script, traverse_subpath
result = {}
is_topic = context.portal_type == 'Topic'
if temples:
if is_topic:
result['temples'] = context.queryCatalog(portal_type=('Temple',),
full_objects=True)
else:
result['temples'] = context.getFolderContents({'portal_type': ('Temple',)},
full_objects=True)
if subtemples:
# Handle brains or objects
if getattr(context, 'getPath', None) is not None:
path = context.getPath()
else:
path = '/'.join(context.getPhysicalPath())
# Explicitly set path to remove default depth
if is_topic:
result['subtemples'] = context.queryCatalog(portal_type=('Temple',),
path=path)
else:
result['subtemples'] = context.getFolderContents({'portal_type': ('Temple',),
'path': path})
if folders:
# We don't need the full objects for the folders
if is_topic:
result['folders'] = context.queryCatalog(portal_type='Folder')
else:
result['folders'] = context.getFolderContents({'portal_type': ('Folder',)})
if images:
if is_topic:
result['images'] = context.queryCatalog(portal_type=('Image',),
full_objects=True)
else:
result['images'] = context.getFolderContents({'portal_type': ('Image',)},
full_objects=True)
if subimages:
# Handle brains or objects
if getattr(context, 'getPath', None) is not None:
path = context.getPath()
else:
path = '/'.join(context.getPhysicalPath())
# Explicitly set path to remove default depth
if is_topic:
result['subimages'] = context.queryCatalog(portal_type=('Image',),
path=path)
else:
result['subimages'] = context.getFolderContents({'portal_type': ('Image',),
'path': path})
if others:
searchContentTypes = context.plone_utils.getUserFriendlyTypes()
filtered = [p_type for p_type in searchContentTypes
if p_type not in ('Temple', 'Folder',)]
if filtered:
# We don't need the full objects for the folder_listing
if is_topic:
result['others'] = context.queryCatalog(portal_type=filtered)
else:
result['others'] = context.getFolderContents({'portal_type': filtered})
else:
result['others'] = ()
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment