Skip to content

Commit

Permalink
updated gallery to handle folder containing images
Browse files Browse the repository at this point in the history
  • Loading branch information
santonelli committed Jan 26, 2016
1 parent 0d8b44c commit ddbee21
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
72 changes: 53 additions & 19 deletions src/operun/gallery/browser/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone import api

from random import choice

import logging

logger = logging.getLogger(__name__)


class GalleryView(BrowserView):

template = ViewPageTemplateFile('templates/gallery.pt')
Expand Down Expand Up @@ -35,30 +38,61 @@ def crop(self, text="", count=0):
else:
return ''


def images(self):
"""
Check if folder contains images and return images
"""
brains = api.content.find(context=self.context, portal_type='Image', depth=1)
folders = self.context.getFolderContents({'portal_type': ('Folder', 'Gallery',)}, full_objects=True)
images = self.context.getFolderContents({'portal_type': ('Image',)}, full_objects=True)

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=450, width=450, direction='down') # noqa
else:
tag = None

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

if folders:
for obj in folders:
title = obj.title
description = obj.description
url = obj.absolute_url()

subimages = obj.getFolderContents({'portal_type': ('Image',)}, full_objects=True)

if subimages:
obj = choice(subimages)

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

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

items.append(data)

if images:
for obj in images:
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=450, width=450, direction='down') # noqa
else:
tag = None

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

items.append(data)

return items
15 changes: 11 additions & 4 deletions src/operun/gallery/browser/templates/gallery.pt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@
<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 ''" />
-->

<div class="row" id="image-gallery" tal:define="images view/images" tal:condition="images">
<div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 gallery-image-wrapper" tal:repeat="image images">
<div class="gallery-image">
<a href="" data-lightbox="" data-title="" tal:attributes="href image/url;
data-lightbox context/id;
data-title image/title">
<div class="gallery-image" tal:define="type image/type">

<a href="" data-lightbox="" data-title="" tal:attributes="href image/url; data-lightbox context/id; data-title image/title" tal:condition="python: type == 'image'">
<div class="gallery-image-title" tal:content="image/title"></div>
<img tal:replace="structure image/image" />
</a>

<a href="" tal:attributes="href image/url" tal:condition="python: type == 'folder'">
<div class="gallery-image-title" tal:content="image/title"></div>
<img tal:replace="structure image/image" />
</a>

</div>
</div>
</div>
Expand Down

0 comments on commit ddbee21

Please sign in to comment.