forked from django-cms/django-cms
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request django-cms#1468 from richardbarran/picture_help_text
Picture plugin: small improvements
- Loading branch information
Showing
2 changed files
with
110 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,51 @@ | ||
|
||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
from django.core.exceptions import ValidationError | ||
from cms.models import CMSPlugin, Page | ||
from os.path import basename | ||
|
||
class Picture(CMSPlugin): | ||
""" | ||
A Picture with or without a link | ||
A Picture with or without a link. | ||
""" | ||
CENTER = "center" | ||
LEFT = "left" | ||
RIGHT = "right" | ||
FLOAT_CHOICES = ((CENTER, _("center")), | ||
(LEFT, _("left")), | ||
CENTER = "center" | ||
FLOAT_CHOICES = ((LEFT, _("left")), | ||
(RIGHT, _("right")), | ||
(CENTER, _("center")), | ||
) | ||
|
||
|
||
|
||
image = models.ImageField(_("image"), upload_to=CMSPlugin.get_media_path) | ||
url = models.CharField(_("link"), max_length=255, blank=True, null=True, help_text=_("if present image will be clickable")) | ||
page_link = models.ForeignKey(Page, verbose_name=_("page"), null=True, blank=True, help_text=_("if present image will be clickable")) | ||
alt = models.CharField(_("alternate text"), max_length=255, blank=True, null=True, help_text=_("textual description of the image")) | ||
longdesc = models.CharField(_("long description"), max_length=255, blank=True, null=True, help_text=_("additional description of the image")) | ||
float = models.CharField(_("side"), max_length=10, blank=True, null=True, choices=FLOAT_CHOICES) | ||
|
||
url = models.CharField(_("link"), max_length=255, blank=True, null=True, | ||
help_text=_("If present, clicking on image will take user to link.")) | ||
page_link = models.ForeignKey(Page, verbose_name=_("page"), null=True, | ||
blank=True, help_text=_("If present, clicking on image will take user \ | ||
to specified page.")) | ||
alt = models.CharField(_("alternate text"), max_length=255, blank=True, | ||
null=True, help_text=_("Specifies an alternate text for an image, if \ | ||
the image cannot be displayed.<br />Is also used by search engines to \ | ||
classify the image.")) | ||
longdesc = models.CharField(_("long description"), max_length=255, | ||
blank=True, null=True, help_text=_("When user hovers above picture,\ | ||
this text will appear in a popup.")) | ||
float = models.CharField(_("side"), max_length=10, blank=True, null=True, | ||
choices=FLOAT_CHOICES, help_text=_("Move image left, right or center.")) | ||
|
||
def __unicode__(self): | ||
if self.alt: | ||
return self.alt[:40] | ||
elif self.image: | ||
# added if, because it raised attribute error when file wasn't defined | ||
# added if, because it raised attribute error when file wasn't | ||
# defined. | ||
try: | ||
return u"%s" % basename(self.image.path) | ||
except: | ||
pass | ||
return "<empty>" | ||
|
||
def clean(self): | ||
if self.url and self.page_link: | ||
raise ValidationError( | ||
_("You can enter a Link or a Page, but not both.")) |
Oops, something went wrong.