Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Fix template selection in plugin #19

Merged
merged 4 commits into from
Mar 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Gallery",
"name": "Aldryn Gallery",
"description": "Easy to use and powerfull gallery system",
"url": "https://github.com/aldryn/aldryn-gallery",
"package-name": "aldryn-gallery",
Expand Down
11 changes: 10 additions & 1 deletion aldryn_gallery/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from django import forms
from django.template import TemplateDoesNotExist
from django.template.loader import select_template
Expand All @@ -12,11 +13,19 @@ class Meta:
fields = ['style', 'engine', 'timeout', 'duration', 'shuffle']
model = GalleryPlugin

def get_slide_template(self, style, name='slide'):
return 'aldryn_gallery/plugins/{}/{}.html'.format(
style, name,
)

def clean_style(self):
style = self.cleaned_data.get('style')
# Check if template for style exists:
try:
select_template(['aldryn_gallery/%s/gallery.html' % style])
if settings.ALDRYN_BOILERPLATE_NAME == 'legacy':
select_template([self.get_slide_template(style=style, name='slide')])
else: # for 'bootstrap3' boilerplate and the recommended structure for other boilerplates
select_template([self.get_slide_template(style=style, name='image_slide')])
except TemplateDoesNotExist:
raise forms.ValidationError("Not a valid style (Template does not exist)")
return style
2 changes: 2 additions & 0 deletions aldryn_gallery/templatetags/shuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@register.filter
def shuffle(arg):
# slice it, cast it to list
if not arg:
return arg
my_list = list(arg[:])
random.shuffle(my_list)
return my_list