@@ -316,7 +316,17 @@ def thumbnails(self):
316
316
self ._thumbnails = tns
317
317
return self ._thumbnails
318
318
def __unicode__ (self ):
319
- return self .label
319
+ # this simulates the way a file field works and
320
+ # allows the sorl thumbnail tag to use the Image model
321
+ # as if it was a image field
322
+ try :
323
+ rel_url = u"%s" % self .file .url
324
+ rel_url = rel_url .lstrip ('/media/' )
325
+ print " image unicode returning %s" % rel_url
326
+ return rel_url
327
+ except :
328
+ print "image unicode failed"
329
+ return ""
320
330
321
331
322
332
class FolderPermissionManager (models .Manager ):
@@ -505,15 +515,27 @@ def children(self):
505
515
parent_url = None
506
516
507
517
if 'cms' in settings .INSTALLED_APPS :
508
- from cms .models import CMSPlugin
518
+ from cms .models import CMSPlugin , Page
509
519
from sorl .thumbnail .main import DjangoThumbnail
510
520
class ImagePublication (CMSPlugin ):
521
+ LEFT = "left"
522
+ RIGHT = "right"
523
+ FLOAT_CHOICES = ((LEFT , _ ("left" )),
524
+ (RIGHT , _ ("right" )),
525
+ )
511
526
image = ImageFilerModelImageField ()
512
527
alt_text = models .CharField (null = True , blank = True , max_length = 255 )
513
528
caption = models .CharField (null = True , blank = True , max_length = 255 )
514
529
width = models .PositiveIntegerField (null = True , blank = True )
515
530
height = models .PositiveIntegerField (null = True , blank = True )
516
531
532
+ longdesc = models .TextField (null = True , blank = True )
533
+ free_link = models .CharField (_ ("link" ), max_length = 255 , blank = True , null = True , help_text = _ ("if present image will be clickable" ))
534
+ page_link = models .ForeignKey (Page , verbose_name = _ ("page" ), null = True , blank = True , help_text = _ ("if present image will be clickable" ))
535
+ float = models .CharField (_ ("side" ), max_length = 10 , blank = True , null = True , choices = FLOAT_CHOICES )
536
+
537
+
538
+
517
539
#crop_ax = models.PositiveIntegerField(null=True, blank=True)
518
540
#crop_ay = models.PositiveIntegerField(null=True, blank=True)
519
541
#crop_bx = models.PositiveIntegerField(null=True, blank=True)
@@ -534,6 +556,9 @@ def __unicode__(self):
534
556
else :
535
557
return u"Image Publication %s" % self .caption
536
558
return ''
559
+ @property
560
+ def alt (self ):
561
+ return self .alt_text
537
562
if 'reversion' in settings .INSTALLED_APPS :
538
563
import reversion
539
564
reversion .register (ImagePublication , follow = ["cmsplugin_ptr" ])
0 commit comments