Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
image plugin improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
evildmp committed Jan 20, 2012
1 parent 3c8867e commit 28cbd89
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 228 deletions.
514 changes: 309 additions & 205 deletions arkestra_image_plugin/cms_plugins.py

Large diffs are not rendered by default.

45 changes: 35 additions & 10 deletions arkestra_image_plugin/models.py
@@ -1,13 +1,20 @@
from posixpath import join, basename, splitext, exists

from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.db import models from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext_lazy as _
from django.conf import settings

from cms.models import CMSPlugin, Page from cms.models import CMSPlugin, Page
from cms.models.fields import PageField from cms.models.fields import PageField
from django.utils.translation import ugettext_lazy as _ from cms import settings as cms_settings
from posixpath import join, basename, splitext, exists
from filer.fields.image import FilerImageField from filer.fields.image import FilerImageField
from filer.fields.file import FilerFileField from filer.fields.file import FilerFileField
from cms import settings as cms_settings
from django.conf import settings from links.models import LinkMethodsMixin


class FilerImage(CMSPlugin): class FilerImage(CMSPlugin):
LEFT = "left" LEFT = "left"
Expand Down Expand Up @@ -55,6 +62,8 @@ class FilerImage(CMSPlugin):
) )
float = models.CharField(_("float"), max_length=10, blank=True, null=True, choices=FLOAT_CHOICES) float = models.CharField(_("float"), max_length=10, blank=True, null=True, choices=FLOAT_CHOICES)




''' '''
@property @property
def scaled_image_url(self): def scaled_image_url(self):
Expand Down Expand Up @@ -84,6 +93,7 @@ def link(self):
class ImageSetPlugin(CMSPlugin): class ImageSetPlugin(CMSPlugin):
IMAGESET_KINDS = ( IMAGESET_KINDS = (
("basic", "Basic"), ("basic", "Basic"),
("multiple", "Multiple images"),
("lightbox", "LightBox"), ("lightbox", "LightBox"),
("slider", "Slider"), ("slider", "Slider"),
) )
Expand All @@ -105,12 +115,14 @@ class ImageSetPlugin(CMSPlugin):
(-350.0, u'350 pixels'), (-350.0, u'350 pixels'),
) )
), ),
('', u"Image's native width"), ('0', u"Image's native width (use with caution)"),
) )
width = models.FloatField(null=True, blank=True, choices = IMAGE_WIDTHS, default = 1000.0) width = models.FloatField(choices = IMAGE_WIDTHS, default = 1000.0)
height = models.PositiveIntegerField(null=True, blank=True) height = models.PositiveIntegerField(null=True, blank=True,
help_text = "Only applies when <strong>Aspect ratio</strong> is <em>Automatic</em>")

ASPECT_RATIOS = ( ASPECT_RATIOS = (
(0, u'Native'), (0, u'Automatic'),
(3.0, u'3x1'), (3.0, u'3x1'),
(1.778, u'16x9'), (1.778, u'16x9'),
(1.618, u'Golden ratio (horizonal)'), (1.618, u'Golden ratio (horizonal)'),
Expand All @@ -123,24 +135,37 @@ class ImageSetPlugin(CMSPlugin):
(0.563, u'16x9'), (0.563, u'16x9'),
(0.3, u'1x3'), (0.3, u'1x3'),
) )
aspect_ratio = models.FloatField(null=True, choices = ASPECT_RATIOS, default = 0) aspect_ratio = models.FloatField(null=True, choices = ASPECT_RATIOS, default = 0,
help_text = "<em>Automatic</em> means native aspect ratio will be used where possible and calculated otherwise")

LEFT = "left" LEFT = "left"
RIGHT = "right" RIGHT = "right"
FLOAT_CHOICES = ((LEFT, _("left")), FLOAT_CHOICES = ((LEFT, _("left")),
(RIGHT, _("right")), (RIGHT, _("right")),
) )
float = models.CharField(_("float"), max_length=10, blank=True, null=True, choices=FLOAT_CHOICES) float = models.CharField(_("float"), max_length=10, blank=True, null=True, choices=FLOAT_CHOICES)
items_per_row = models.PositiveSmallIntegerField(blank = True, null = True,
help_text = "Only applies to Multiple and Lightbox plugins")

@property
def items_have_links(self):
return all(item.destination_content_object is not None for item in self.imageset_item.all())

def __unicode__(self): def __unicode__(self):
return u"image-set-%s" % self.kind return u"image-set-%s" % self.kind




class ImageSetItem(models.Model): class ImageSetItem(models.Model, LinkMethodsMixin):
plugin = models.ForeignKey(ImageSetPlugin, related_name="imageset_item") plugin = models.ForeignKey(ImageSetPlugin, related_name="imageset_item")
image = FilerImageField() image = FilerImageField()
alt_text = models.CharField(null=True, blank=True, max_length=255) alt_text = models.CharField(null=True, blank=True, max_length=255)
use_description_as_caption = models.BooleanField(verbose_name = "Use description", default=False, help_text = "Use image's description field as caption") use_description_as_caption = models.BooleanField(verbose_name = "Use description", default=False, help_text = "Use image's description field as caption")
caption = models.TextField(_("Caption"), blank=True, null=True) caption = models.TextField(_("Caption"), blank=True, null=True)


destination_content_type = models.ForeignKey(ContentType, verbose_name="Type", related_name = "links_to_%(class)s", null = True, blank = True)
destination_object_id = models.PositiveIntegerField(verbose_name="Item", null = True, blank = True)
destination_content_object = generic.GenericForeignKey('destination_content_type', 'destination_object_id')

def __unicode__(self): def __unicode__(self):
if self.image: if self.image:
return self.image.label return self.image.label
Expand Down
Expand Up @@ -30,4 +30,4 @@
{% endaddtoblock %} {% endaddtoblock %}




<div class="fancybox">{% for item in imageset.items %}<a class='{{ class|default:"fancy" }}' rel='{{ rel|default:"gallery_1" }}' href="{{ item.url}}" title='{{ item.caption|default:"" }}'><img class="fancybox-icon" alt="" src="{% thumbnail item.image icon_size crop subject_location=image.subject_location %}" /></a>{% endfor %}</div> <div class="fancybox" style="width: {{ imageset.container_width }}px;">{% for item in imageset.items %}<a class='{{ class|default:"fancy" }}' rel='{{ rel|default:"gallery_1" }}' href="{{ item.large_url}}" title='{{ item.caption|default:"" }}'><img class="fancybox-icon" alt="" src="{% thumbnail item.image imageset.size crop subject_location=image.subject_location %}" /></a>{% endfor %}</div>
@@ -0,0 +1,5 @@
{% load thumbnail %}

<ul class="multiple-images" style="width: {{ imageset.container_width }}px;">
{% for item in imageset.items %}<li {% if item.lastinrow %}class="lastinrow"{% endif %}><img alt="" src="{% thumbnail item.image item.icon_size crop subject_location=image.subject_location %}" /></li>{% endfor %}
</ul>
@@ -1,7 +1,12 @@
{% load thumbnail filer_tags filer_image_tags %}{% spaceless %} {% load thumbnail filer_tags filer_image_tags %}
<span class = "image {{imageset.float}}"><img alt="{% if imageset_item.alt %}{{ imageset_item.alt }}{% endif %}" class="plugin" src="{% thumbnail imageset_item.image.file image_size crop subject_location=imageset_item.image.subject_location %}" /> {% spaceless %}
{% if imageset_item.caption %}<span style="width: {{caption_width}}px" class="image_caption">{{ imageset_item.caption }}</span>{% endif %} <span class = "image {{imageset.float}}">
{% if imageset_item.show_author %} {% if imageset_item.url %}<a href="{{ imageset_item.url }}">{% endif %}
<span class="image_author">(Author: {{ imageset_item.image.author }})</span> <img alt="{% if imageset_item.alt %}{{ imageset_item.alt }}{% endif %}" class="plugin" src="{% thumbnail imageset_item.image.file image_size crop subject_location=imageset_item.image.subject_location %}" />
{% endif %} {% if imageset_item.url %}</a>{% endif %}
</span>{% endspaceless %} {% if imageset_item.caption %}<span style="width: {{caption_width}}px" class="image_caption">{{ imageset_item.caption }}</span>{% endif %}
{% if imageset_item.show_author %}
<span class="image_author">(Author: {{ imageset_item.image.author }})</span>
{% endif %}
</span>
{% endspaceless %}
@@ -1,7 +1,7 @@
{% load sekizai_tags thumbnail %} {% load sekizai_tags thumbnail %}
<ul id="{{ imageset|default:"slider"}}"> <ul id="{{ imageset|default:"slider"}}">
{% for item in imageset.items %} {% for item in imageset.items %}
<li><img src="{% thumbnail item.image icon_size crop subject_location=item.image.subject_location %}" alt=""></li> <li><img src="{% thumbnail item.image imageset.size crop subject_location=item.image.subject_location %}" alt=""></li>
{% endfor %} {% endfor %}
</ul> </ul>


Expand All @@ -12,8 +12,8 @@
<link rel="stylesheet" href="{{ STATIC_URL }}slider/css/theme-minimalist-square.css"> <link rel="stylesheet" href="{{ STATIC_URL }}slider/css/theme-minimalist-square.css">
<style> <style>
#{{ imageset|default:"slider"}} { #{{ imageset|default:"slider"}} {
width: {{ icon_size.0 }}px; width: {{ imageset.size.0 }}px;
height: {{ icon_size.1 }}px; height: {{ imageset.size.1 }}px;
list-style: none; list-style: none;
/* Prevent FOUC (see FAQ page) and keep things readable if javascript is disabled */ /* Prevent FOUC (see FAQ page) and keep things readable if javascript is disabled */
overflow-y: auto; overflow-y: auto;
Expand Down
1 change: 0 additions & 1 deletion arkestra_utilities/output_libraries/plugin_widths.py
Expand Up @@ -27,7 +27,6 @@ def get_placeholder_width(context, plugin):
placeholder_width = context.get("placeholder_width") placeholder_width = context.get("placeholder_width")
placeholder_width = placeholder_width or context.get("width") placeholder_width = placeholder_width or context.get("width")
placeholder_width = float(placeholder_width or 100.0) placeholder_width = float(placeholder_width or 100.0)
# placeholder_width = float(context.get("placeholder_width", context.get("width", 100.0)))


# run all registered placeholder_width modifiers # run all registered placeholder_width modifiers
for cls in adjuster_pool.adjusters["placeholder_width"]: for cls in adjuster_pool.adjusters["placeholder_width"]:
Expand Down
10 changes: 9 additions & 1 deletion arkestra_utilities/static/arkestra/css/arkestra_images.css
@@ -1,4 +1,12 @@
/* Navigation Links */ /* Arkestra image plugin */

ul.multiple-images {padding: 0; margin: 0;}
ul.multiple-images li {display: inline-block; margin-right: 6px;}
ul.multiple-images li.lastinrow {margin-right: 0px;}

/* Slider
Navigation Links */
body div.anythingSlider-minimalist-square .anythingControls { body div.anythingSlider-minimalist-square .anythingControls {
float: right; float: right;
position: relative; position: relative;
Expand Down

0 comments on commit 28cbd89

Please sign in to comment.