Skip to content

Commit

Permalink
make gallery available to default folders, added image listing to gal…
Browse files Browse the repository at this point in the history
…lery
  • Loading branch information
santonelli committed Jan 20, 2016
1 parent fea9eee commit 938bfe4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/operun/gallery/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@
permission="zope2.View"
/>

<browser:page
name="gallery"
for="plone.app.contenttypes.interfaces.IFolder"
class=".gallery.GalleryView"
layer="operun.gallery.interfaces.IOperunGalleryLayer"
permission="zope2.View"
/>

</configure>
46 changes: 46 additions & 0 deletions src/operun/gallery/browser/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,49 @@ def __call__(self):
"""

return self.template()

def crop(self, text, count):
"""
Crop given text to given count.
"""
cropped_text = ' '.join((text[0:count].strip()).split(' ')[:-1])

strips = ['.', ',', ':', ';']
for s in strips:
cropped_text = cropped_text.strip(s)

if len(text) > count:
return cropped_text + u'…'
else:
return text

def images(self):
"""
Check if folder contains images and return images
"""
brains = api.content.find(portal_type='Image')

items = []
for item in brains:
obj = item.getObject()
title = obj.title
description = obj.description
url = obj.absolute_url()

if obj.image:
images_view = api.content.get_view('images', obj, self.request) # noqa
tag = images_view.tag('image', height=400, width=400, direction='down') # noqa
else:
tag = None

data = {'title': self.crop(title, 65),
'description': self.crop(description, 265),
'image': tag,
'url': url,
}

items.append(data)



return items
23 changes: 20 additions & 3 deletions src/operun/gallery/browser/templates/gallery.pt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns="http://www.w3.org/1999/xhtml">

<body>

<metal:content-core fill-slot="main">
<metal:content-core define-macro="content-core">
<metal:content-core fill-slot="content-core">
<metal:content-core define-macro="content-core"
tal:define="toc context/table_of_contents|nothing;">

<div id="parent-fieldname-text"
tal:condition="exists:context/text"
tal:content="structure python:context.text.output_relative_to(view.context)"
tal:attributes="class python: toc and 'pat-autotoc' or ''" />

<section id="gallery" tal:define="images view/images" tal:condition="images">
<tal:images tal:repeat="image images">
<div class="image-title">
<h2 tal:content="image/title">Teaser Title</h2>
</div>
<div class="gallery-image">
<img tal:replace="structure image/image"/>
</div>
</tal:images>
</section>

</metal:content-core>
</metal:content-core>
Expand Down

0 comments on commit 938bfe4

Please sign in to comment.