Generated: Wed 2013-06-12 20:11 CEST
Source file: /home/dkaufhold/projects/cmsplugin-image-gallery/src/image_gallery/templatetags/image_gallery_tags.py
Stats: 11 executed, 0 missed, 3 excluded, 12 ignored
"""Template tags for the ``image_gallery`` app."""
from django import template
from filer.models import Image
from image_gallery.models import Gallery
register = template.Library()
@register.inclusion_tag('image_gallery/pictures.html', takes_context=True)
def render_pictures(context, selection='recent', amount=3):
"""Template tag to render a list of pictures."""
folder_pks = [gallery.folder.pk for gallery in Gallery.objects.all()]
pictures = Image.objects.filter(folder__id__in=folder_pks)
if selection == 'recent':
context.update({
'pictures': pictures.order_by('-uploaded_at')[:amount]
})
elif selection == 'random':
context.update({
'pictures': pictures.order_by('?')[:amount]
})
else:
return None
return context