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

Commit

Permalink
Merge branch 'origin/feature/multi-boilerplate-fixes' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	setup.py
  • Loading branch information
jmelett committed Mar 2, 2015
2 parents 3e11359 + 31c2790 commit cc69bb1
Show file tree
Hide file tree
Showing 22 changed files with 271 additions and 22 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ env:
- TOX_ENV=py27-dj16
- TOX_ENV=pep8

matrix:
allow_failures:
- env: TOX_ENV=pep8

install:
- pip install tox coveralls

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
0.3 (2015-01-26)
================

* multi-boilerplate support
new requirement: aldryn-boilerplates (needs configuration)

* removed ``feature`` plugin style by default. Add it to the ``GALLERY_STYLES`` setting to restore
old behaviour
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include LICENSE.txt
recursive-include aldryn_gallery/templates *
recursive-include aldryn_gallery/boilerplates *
recursive-include aldryn_gallery/locale *
recursive-include aldryn_gallery/migrations *
recursive-include aldryn_gallery/static *
recursive-exclude * *.pyc
18 changes: 17 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@ Aldryn Gallery
Aldryn Gallery is build on the principle of plugin-in-plugin provided by django-cms
since version 3.0.

The gallery requires **jQuery** and `classjs <https://github.com/finalangel/classjs-plugins>`_ cl.gallery.
Installation
============

::

pip install aldryn-gallery

Add ``aldryn_gallery`` to ``INSTALLED_APPS``.

Configure ``aldryn-boilerplates`` (https://pypi.python.org/pypi/aldryn-boilerplates/).

To use the old templates, set ``ALDRYN_BOILERPLATE_NAME='legacy'``.
To use https://github.com/aldryn/aldryn-boilerplate-standard (recommended, will be renamed to
``aldryn-boilerplate-bootstrap3``) set ``ALDRYN_BOILERPLATE_NAME='bootstrap3'``.

When using the ``legacy`` boilerplate, **jQuery** and
`classjs <https://github.com/finalangel/classjs-plugins>`_ cl.gallery are required.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "aldryn_gallery/base.html" %}
{% extends "aldryn_gallery/plugins/gallery_base.html" %}
{% load i18n cms_tags shuffle %}

{% block content_gallery %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{# Slide for a filer.Image instance #}
<div class="item{% if forloop.first %} active{% endif %}">
<img src="{{ image.url }}" alt="{{ image.default_alt_text|default:image.label }}" />
</div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{# Slide for a SlideCMSPlugin instance #}
<div class="item{% if forloop.first %} active{% endif %}">
{% with link=instance.get_link %}
{% with link=instance.get_link image=instance.image %}
{% if link %}
<a href="{{ link }}"{% if instance.target %} target="{{ instance.target }}"{% endif %}>
{% if image %}<img src="{{ image.url }}" alt="{{ image.default_alt_text|default:image.label }}" />{% else %}{{ instance.link_text }}{% endif %}
{% if image %}
<img src="{{ image.url }}" alt="{{ image.default_alt_text|default:image.label }}" />{% else %}{{ instance.link_text }}
{% endif %}
</a>
{% elif image %}
<img src="{{ image.url }}" alt="{{ image.default_alt_text|default:image.label }}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for image in instance.folder.files %}
{% include slide_template %}
{% endfor %}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load static sekizai_tags %}

<div class="plugin plugin-gallery plugin-gallery-{{ instance.style }}" id="plugin-gallery-{{ instance.pk }}">
{% block content_gallery %}{% endblock %}
</div>

{% addtoblock "js" %}<script src="{% static "js/libs/class.min.js" %}"></script>{% endaddtoblock %}
{% addtoblock "js" %}<script src="{% static "js/addons/cl.gallery.min.js" %}"></script>{% endaddtoblock %}
{% addtoblock "js" %}
<script>
jQuery(window).load(function () {
new Cl.Gallery('#plugin-gallery-{{ instance.pk }}', {
'engine': '{{ instance.engine }}',
'duration': {{ instance.duration }},
'timeout': {{ instance.timeout }}
});
});
</script>
{% endaddtoblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "aldryn_gallery/plugins/standard/gallery.html" %}
{% load i18n cms_tags shuffle %}

{% block content_gallery %}
<div class="wrapper">
<p class="trigger-previous"><a href="#{% trans "previous" %}">{% trans "previous" %}</a></p>
<ul class="viewport">
{% if instance.shuffle %}
{% for plugin in instance.child_plugin_instances|shuffle %}
{% render_plugin plugin %}
{% endfor %}
{% else %}
{% for plugin in instance.child_plugin_instances %}
{% render_plugin plugin %}
{% endfor %}
{% endif %}
</ul>
<p class="trigger-next"><a href="#{% trans "next" %}">{% trans "next" %}</a></p>
</div>
<nav>
{% for slide in slides %}
<a href="#{{ forloop.counter }}">{{ forloop.counter }}</a>
{% endfor %}
</nav>
{% endblock content_gallery %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<li class="item"{% if image %} style="background-image:url({{ image.url }});"{% endif %}>
{% if instance.content %}
<div class="item-content">
{{ instance.content|safe }}
</div>
{% endif %}
</li>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends "aldryn_gallery/base.html" %}
{% load i18n cms_tags shuffle %}

{% block content_gallery %}
<div class="wrapper">
<p class="trigger-previous"><a href="#{% trans "previous" %}">{% trans "previous" %}</a></p>
<ul class="viewport">
{% if instance.shuffle %}
{% for plugin in instance.child_plugin_instances|shuffle %}
{% render_plugin plugin %}
{% endfor %}
{% else %}
{% for plugin in instance.child_plugin_instances %}
{% render_plugin plugin %}
{% endfor %}
{% endif %}
</ul>
<p class="trigger-next"><a href="#{% trans "next" %}">{% trans "next" %}</a></p>
</div>
<nav>
{% for slide in slides %}
<a href="#{{ forloop.counter }}">{{ forloop.counter }}</a>
{% endfor %}
</nav>
{% endblock content_gallery %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<li class="item">
{% with link=instance.get_link %}
{% if link %}
<a href="{{ link }}"{% if instance.target %} target="{{ instance.target }}"{% endif %}>
{% if image %}<img src="{{ image.url }}" alt="{{ image.default_alt_text|default:image.label }}" />{% else %}{{ instance.link_text }}{% endif %}
</a>
{% elif image %}
<img src="{{ image.url }}" alt="{{ image.default_alt_text|default:image.label }}" />
{% endif %}
{% endwith %}
{% if instance.content %}
<div class="item-content">
{{ instance.content|safe }}
</div>
{% endif %}
</li>
33 changes: 25 additions & 8 deletions aldryn_gallery/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _
from django.conf import settings

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
Expand All @@ -21,20 +22,23 @@ class GalleryChildBase(GalleryBase):
class Meta:
abstract = True

render_template = False
require_parent = True
parent_classes = ['GalleryCMSPlugin']

def render(self, context, instance, placeholder):
# get style from parent plugin, render chosen template
self.render_template = self.get_slide_template(instance)
context['instance'] = instance
context['image'] = instance.image
return context

def get_slide_template(self, instance):
return 'aldryn_gallery/%s/slide.html' % getattr(
instance.parent.get_plugin_instance()[0], 'style', GalleryPlugin.STANDARD)
def get_slide_template(self, instance, name='slide'):
return 'aldryn_gallery/plugins/{}/{}.html'.format(
getattr(instance.parent.get_plugin_instance()[0], 'style', GalleryPlugin.STANDARD),
name,
)

def get_render_template(self, context, instance, placeholder):
return self.get_slide_template(instance=instance)


# Plugins
Expand All @@ -47,7 +51,6 @@ class GalleryCMSPlugin(GalleryBase):
child_classes = ['SlideCMSPlugin', 'SlideFolderCMSPlugin']

def render(self, context, instance, placeholder):
self.render_template = 'aldryn_gallery/%s/gallery.html' % instance.style
context['instance'] = instance
if instance.child_plugin_instances:
number_of_slides = sum([plugin.folder.file_count if isinstance(plugin, SlideFolderPlugin) else 1
Expand All @@ -57,22 +60,36 @@ def render(self, context, instance, placeholder):
context['slides'] = range(number_of_slides)
return context

def get_render_template(self, context, instance, placeholder):
return 'aldryn_gallery/plugins/{}/gallery.html'.format(instance.style)


class SlideCMSPlugin(GalleryChildBase):
name = _('Slide')
model = SlidePlugin


class SlideFolderCMSPlugin(GalleryChildBase):
"""
Slide Plugin that renders a slide for each image in the linked folder.
"""
name = _('Slide folder')
model = SlideFolderPlugin
render_template = 'aldryn_gallery/base_folder.html'

def render(self, context, instance, placeholder):
context['instance'] = instance
context['slide_template'] = self.get_slide_template(instance)
if settings.ALDRYN_BOILERPLATE_NAME == 'legacy':
context['slide_template'] = self.get_slide_template(instance=instance, name='slide')
else: # for 'bootstrap3' boilerplate and the recommended structure for other boilerplates
context['slide_template'] = self.get_slide_template(instance=instance, name='image_slide')
return context

def get_render_template(self, context, instance, placeholder):
if settings.ALDRYN_BOILERPLATE_NAME == 'legacy':
return 'aldryn_gallery/plugins/slide_folder.html'
else: # for 'bootstrap3' boilerplate and the recommended structure for other boilerplates
return self.get_slide_template(instance=instance, name='slide_folder')


plugin_pool.register_plugin(GalleryCMSPlugin)
plugin_pool.register_plugin(SlideCMSPlugin)
Expand Down

0 comments on commit cc69bb1

Please sign in to comment.