Permalink
Browse files

active and inline ordering fields for links/images

  • Loading branch information...
1 parent b4b8885 commit 7f4ffd8924dc6e70c25745b30520320852d8eac8 @evildmp committed Jan 30, 2013
@@ -341,17 +341,26 @@ class ImageSetItemEditor(SupplyRequestMixin, admin.StackedInline, AutocompleteMi
extra=1
- fieldset_basic = ('', {'fields': (('image',),)})
+ fieldset_basic = ('', {'fields': ((
+ 'image',
+ 'inline_item_ordering',
+ 'active',
+ ),)})
fieldset_advanced = ('Caption', {
- 'fields': (( 'auto_image_title', 'manual_image_title'), ( 'auto_image_caption', 'manual_image_caption'),),
+ 'fields': (
+ ( 'auto_image_title', 'manual_image_title'),
+ ( 'auto_image_caption', 'manual_image_caption'),
+ ),
'classes': ('collapse',)
})
- fieldsets = (fieldset_basic, fieldset_advanced,
+ fieldsets = (
+ fieldset_basic,
+ fieldset_advanced,
("Link", {
'fields': (
('destination_content_type', 'destination_object_id',),
'alt_text',
- ( 'auto_link_title', 'manual_link_title'), ( 'auto_link_description', 'manual_link_description'),
+ ('auto_link_title', 'manual_link_title'), ( 'auto_link_description', 'manual_link_description'),
),
'description': "Links will only be applied if <em>all</em> images in the set have links.",
'classes': ('collapse',),
@@ -533,6 +542,7 @@ class EmbeddedVideoSetItemEditor(SupplyRequestMixin, admin.StackedInline, Autoco
'fields': (
('service', 'video_code', 'aspect_ratio'),
('video_title', 'video_autoplay'),
+ ('active', ),
),
}),
# ('Other options', {
@@ -566,8 +576,8 @@ def notes(self,instance):
def render(self, context, embeddedvideoset, placeholder):
# don't do anything if there are no items in the embeddedvideoset
- if embeddedvideoset.number_of_items:
- video = embeddedvideoset.embeddedvideoset_item.order_by('?')[0]
+ if embeddedvideoset.active_items:
+ video = embeddedvideoset.active_items.order_by('?')[0]
# calculate the width of the block the image will be in
width = int(width_of_image_container(context, embeddedvideoset))
@@ -582,7 +592,6 @@ def render(self, context, embeddedvideoset, placeholder):
# no items, use a null template
else:
- # print "using a null template" , imageset
self.render_template = "null.html"
# context.update({
# 'placeholder':placeholder,

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -11,6 +11,7 @@
from filer.fields.image import FilerImageField
from filer.fields.file import FilerFileField
+from arkestra_utilities.import_free_model_mixins import ArkestraGenericPluginItemOrdering
from links.models import LinkMethodsMixin
class FilerImage(CMSPlugin):
@@ -156,6 +157,10 @@ def items_have_links(self):
def number_of_items(self):
return self.imageset_item.count()
+ @property
+ def active_items(self):
+ return self.imageset_item.filter(active=True)
+
def __unicode__(self):
return u"image-set-%s" % self.kind
@@ -165,9 +170,9 @@ def copy_relations(self, oldinstance):
plugin_item.plugin = self
plugin_item.save()
-class ImageSetItem(models.Model, LinkMethodsMixin):
+class ImageSetItem(ArkestraGenericPluginItemOrdering, LinkMethodsMixin, models.Model):
class Meta:
- ordering=('id',)
+ ordering=('inline_item_ordering', 'id',)
plugin = models.ForeignKey(ImageSetPlugin, related_name="imageset_item")
image = FilerImageField()
alt_text = models.CharField(null=True, blank=True, max_length=255,
@@ -257,8 +262,8 @@ class EmbeddedVideoSetPlugin(CMSPlugin):
width = models.FloatField(choices = IMAGE_WIDTHS, default = 1000.0)
@property
- def number_of_items(self):
- return self.embeddedvideoset_item.count()
+ def active_items(self):
+ return self.embeddedvideoset_item.filter(active=True)
def __unicode__(self):
return u"embedded-video-set-%s" % self.id
@@ -269,9 +274,9 @@ def copy_relations(self, oldinstance):
plugin_item.plugin = self
plugin_item.save()
-class EmbeddedVideoSetItem(models.Model, LinkMethodsMixin):
+class EmbeddedVideoSetItem(LinkMethodsMixin, ArkestraGenericPluginItemOrdering):
class Meta:
- ordering=('id',)
+ ordering=('inline_item_ordering', 'id',)
plugin = models.ForeignKey(
EmbeddedVideoSetPlugin,
related_name="embeddedvideoset_item"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,4 @@
+from django.conf import settings
+
+settings.configure(DEBUG=True, TEMPLATE_DEBUG=True,
+ TEMPLATE_DIRS=('/home/web-apps/myapp', '/home/web-apps/base'))
@@ -1,16 +1,82 @@
+import os
from django.test import TestCase
from django import forms
from django.contrib.contenttypes.models import ContentType
+from django.core.files import File as DjangoFile
from cms.models.placeholdermodel import Placeholder
from cms.api import add_plugin
+from filer.models.imagemodels import Image
+from filer.tests.helpers import create_image
-from models import EmbeddedVideoSetItem
+
+from models import EmbeddedVideoSetItem, ImageSetItem
"""
create a plugin, with no items, should not render
with items - check urls that are generated
"""
+class ImageLinkSetTests(TestCase):
+
+ def create_filer_image(self):
+ self.img = create_image()
+ self.image_name = 'test_file.jpg'
+ self.filename = os.path.join(os.path.dirname(__file__),
+ self.image_name)
+ self.img.save(self.filename, 'JPEG')
+ file_obj= DjangoFile(open(self.filename), name=self.image_name)
+ image = Image.objects.create(owner=self.superuser,
+ original_filename=self.image_name,
+ file=file_obj)
+ return image
+
+ def test_imagelinkset_plugin_item(self):
+ """
+ test the output of the image link set plugin
+ """
+ img = Image()
+ img.save()
+ # create a placeholder
+ placeholder = Placeholder(slot=u"some_slot")
+ placeholder.save() # a good idea, if not strictly necessary
+
+ # add the plugin
+ plugin = add_plugin(placeholder, u"ImageSetPublisher", u"en",
+ width = 1000.0,
+ )
+ plugin.save()
+
+ # get the corresponding plugin instance
+ instance = plugin.get_plugin_instance()[1]
+
+ self.assertEquals(plugin.active_items.count(), 0)
+ self.assertEquals(instance.render({}, plugin, placeholder), {})
+
+ # add an image to the plugin
+ item1 = ImageSetItem(
+ plugin=plugin,
+ image_id=img.id,
+ active=False,
+ )
+ self.assertEquals(list(plugin.active_items), [])
+
+ # now the item is active
+ item1.active=True
+ item1.save()
+ self.assertListEqual(list(plugin.active_items), [item1])
+
+ # add a second image to the plugin
+ item2 = ImageSetItem(
+ plugin=plugin,
+ image_id=img.id,
+ )
+ item2.save()
+ self.assertListEqual(list(plugin.active_items), [item1, item2])
+
+ # now the ordering should be reversed
+ item1.inline_item_ordering=1
+ item1.save()
+ self.assertListEqual(list(plugin.active_items), [item2, item1])
class EmbeddedVideoTests(TestCase):
@@ -30,19 +96,26 @@ def test_embedded_video_plugin_item(self):
# get the corresponding plugin instance
instance = plugin.get_plugin_instance()[1]
-
- self.assertEquals(plugin.number_of_items, 0)
+ self.assertEquals(plugin.active_items.count(), 0)
self.assertEquals(instance.render({}, plugin, placeholder), {})
- # add a video to the plugin
+ # add a video to the plugin - but it's not active
item1 = EmbeddedVideoSetItem(
plugin=plugin,
service="vimeo",
video_code="1234",
video_title="one",
+ active=False,
+ inline_item_ordering=1
)
item1.save()
+ self.assertEquals(plugin.active_items.count(), 0)
+ self.assertEquals(instance.render({}, plugin, placeholder), {})
+ # now the item is active
+ item1.active=True
+ item1.save()
+ self.assertEquals(list(plugin.active_items), [item1])
self.assertDictEqual(
instance.render({}, plugin, placeholder),
{
@@ -53,3 +126,12 @@ def test_embedded_video_plugin_item(self):
}
)
+ # add a second video to the plugin
+ item2 = EmbeddedVideoSetItem(
+ plugin=plugin,
+ service="vimeo",
+ video_code="5678",
+ video_title="two",
+ )
+ item2.save()
+ self.assertEquals(list(plugin.active_items), [item2, item1])
@@ -0,0 +1,14 @@
+# this file exists to help avoid circular imports
+
+from django.db import models
+
+class ArkestraGenericPluginItemOrdering(models.Model):
+ class Meta:
+ abstract = True
+
+ inline_item_ordering = models.PositiveSmallIntegerField(
+ "Position",
+ help_text="0 is first",
+ default = 0,
+ )
+ active = models.BooleanField(default=True)
@@ -1,8 +1,6 @@
from django.db import models
-from links.models import ExternalLink
-from links.link_functions import object_links
-
+from links.models import ExternalLink
class URLModelMixin(models.Model):
@@ -34,4 +32,6 @@ class Meta:
precise_location = models.CharField(help_text=u"Precise location <em>within</em> the building, for visitors",
max_length=255, null=True, blank=True)
access_note = models.CharField(help_text = u"Notes on access/visiting hours/etc",
- max_length=255, null=True, blank=True)
+ max_length=255, null=True, blank=True)
+
+
@@ -0,0 +1,3 @@
+# this file contains some useful objects and functions
+# for use in other tests
+
@@ -0,0 +1,4 @@
+from django.conf import settings
+
+settings.configure(DEBUG=True, TEMPLATE_DEBUG=True,
+ TEMPLATE_DIRS=('/home/web-apps/myapp', '/home/web-apps/base'))
View
@@ -25,6 +25,7 @@ class PluginInlineLink(SupplyRequestMixin, admin.StackedInline):
'destination_content_type', 'destination_object_id',
'text_override',
('include_description', 'key_link',),
+ ('inline_item_ordering', 'active', ),
),
}),
('Overrides', {
@@ -124,6 +125,7 @@ class PluginInlineCarousel(admin.StackedInline):
'fields': (
('destination_content_type', 'destination_object_id',),
('link_title', 'image', ),
+ ('inline_item_ordering', 'active', ),
),
}),
)
Oops, something went wrong.

0 comments on commit 7f4ffd8

Please sign in to comment.