limpbrains avatar limpbrains committed 97dedf3

initial commit

Comments (0)

Files changed (7)

Empty file added.

Binary file added.

fbpicture/cms_plugins.py

+from cms.plugin_pool import plugin_pool
+from cms.plugin_base import CMSPluginBase
+from django.utils.translation import ugettext_lazy as _
+from fbpicture.models import FbPicture
+from django.conf import settings
+
+class FbPicturePlugin(CMSPluginBase):
+    model = FbPicture
+    name = _("Filebrowser Picture")
+    render_template = "cms/fbplugins/picture.html"
+    text_enabled = True
+    
+    def render(self, context, instance, placeholder):
+        if instance.url:
+            link = instance.url
+        elif instance.page_link:
+            link = instance.page_link.get_absolute_url()
+        else:
+            link = ""
+        context.update({
+            'picture':instance,
+            'link':link, 
+            'placeholder':placeholder
+        })
+        return context 
+    
+    def icon_src(self, instance):
+        # TODO - possibly use 'instance' and provide a thumbnail image
+        return settings.CMS_MEDIA_URL + u"images/plugins/image.png"
+ 
+plugin_pool.register_plugin(FbPicturePlugin)
Add a comment to this file

fbpicture/cms_plugins.pyc

Binary file added.

fbpicture/models.py

+
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+from cms.models import CMSPlugin, Page
+from os.path import basename
+from filebrowser.fields import FileBrowseField
+
+from django.conf import settings
+
+class FbPicture(CMSPlugin):
+    """
+    A Picture with or without a link
+    """
+    LEFT = "left"
+    RIGHT = "right"
+    FLOAT_CHOICES = ((LEFT, _("left")),
+                     (RIGHT, _("right")),
+                     )
+    
+    
+    image = FileBrowseField(_("image"), max_length=255, format='Image')
+    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)
+    
+    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
+            try:
+                return u"%s" % basename(self.image.path)
+            except:
+                pass
+        return "<empty>"

Binary file added.

fbpicture/templates/cms/fbplugins/picture.html

+{% if link %}<a href="{{ link }}">{% endif %}
+<img {% if picture.float %}class="{{ picture.float }}" {% endif %}alt="{{ picture.alt }}" src="{{ picture.image }}" />
+{% if link %}</a>{% endif %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.