tehfink avatar tehfink committed ad35c19

initial commit

Comments (0)

Files changed (7)

Add a comment to this file

cmsplugin_photologue/__init__.py

Empty file added.

cmsplugin_photologue/cms_plugins.py

+from cms.plugin_base import CMSPluginBase
+from cms.plugin_pool import plugin_pool
+from models import *
+from django.utils.translation import ugettext as _
+from photologue.models import *
+from django.conf import settings
+
+SAMPLE_SIZE = ":%s" % getattr(settings, 'CMSPLUGIN_PHOTOLOGUE_SAMPLE_SIZE', 3)
+
+class CMSPhotologueGalleryPlugin(CMSPluginBase):
+    model = PhotologueGalleryPlugin
+    name = _("Photologue Gallery")
+    render_template = "plugins/photologue_gallery.html"
+
+    def render(self, context, instance, placeholder):
+        context.update({'gallery':instance.gallery, 'placeholder':placeholder})
+        context.update({'queryset': Gallery.objects.filter(is_public=True), 'allow_empty': True, 'paginate_by': 5, 'sample_size':SAMPLE_SIZE})
+        return context
+
+plugin_pool.register_plugin(CMSPhotologueGalleryPlugin)
+
+
+class CMSPhotologuePhotoPlugin(CMSPluginBase):
+    model = PhotologuePhotoPlugin
+    name = _("Photologue Photo")
+    render_template = "plugins/photologue_photo.html"
+
+#    def __init__(self):
+#        self.is_thumb = 0
+#        pass
+
+#    is_thumb = 1
+        
+    def render(self, context, instance, placeholder):
+#        is_thumb = self.is_thumb
+        context.update({'photo':instance.photo, 'placeholder':placeholder})
+        context.update({'slug_field': 'title_slug', 'queryset': Photo.objects.filter(is_public=True), 'is_thumb' : instance.is_thumb})
+        return context
+
+plugin_pool.register_plugin(CMSPhotologuePhotoPlugin)

cmsplugin_photologue/models.py

+from django.db import models
+from cms.models import CMSPlugin
+from photologue.models import *
+from django.utils.translation import ugettext_lazy as _
+
+class PhotologueGalleryPlugin(CMSPlugin):
+        gallery = models.ForeignKey(Gallery)
+
+class PhotologuePhotoPlugin(CMSPlugin):
+        IS_THUMB_CHOICES = (
+            (u'0', u'No'),
+            (u'1', u'Yes'),
+        )
+        photo = models.ForeignKey(Photo)
+        is_thumb = models.CharField(_('is thumbnail'), max_length=1, choices=IS_THUMB_CHOICES, default='0', help_text=_('Show thumbnail or full size image'))

cmsplugin_photologue/templates/plugins/photologue_gallery.html

+
+    <div class="photo-gallery">
+        <h2><a href="{{ gallery.get_absolute_url }}">{{ gallery.title }}</a></h2>
+        {% for photo in gallery.sample|slice:sample_size %}
+        <div class="gallery-photo">
+            <a href="{{ photo.get_absolute_url }}"><img src="{{ photo.get_thumbnail_url }}" alt="{{ photo.title }}"/></a>
+        </div>
+        {% endfor %}
+    </div>

cmsplugin_photologue/templates/plugins/photologue_photo.html

+
+<div class="gallery-photo">
+    <a href="{{ photo.image.url }}"><img src="  {% ifequal is_thumb '1' %}
+                                                    {{ photo.get_thumbnail_url }}
+                                                {% else %}
+                                                    {{ photo.get_display_url }}
+                                                {% endifequal %}
+                                             " alt="{{ photo.title }}"/></a>
+    {% if photo.caption %}<p>{{ photo.caption }}</p>{% endif %}
+</div>

cmsplugin_photologue/tests.py

+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+

cmsplugin_photologue/urls.py

+#url bridge for django-cms2 to django-photologue
+#include this module in your django-cms2 project's settings.py
+#eg: CMS_APPLICATIONS_URLS = ( ('cmsplugin_photologue.urls', 'Photologue plugin app'), )
+
+from django.conf.urls.defaults import *
+from django.conf import settings
+
+#get variables defined in photologue.urls
+from photologue.urls import gallery_args, photo_args
+
+#defines a context processor because 'sites' is not being passed to photologue template for some reason
+def current_site(request):
+    """
+    A context processor to add the "current site" to the current Context
+    """
+    from django.contrib.sites.models import Site
+    try:
+        current_site = Site.objects.get_current()
+        return {
+            'site': current_site,
+        }
+    except Site.DoesNotExist:
+        # always return a dict
+        return {'current_site':''} # an empty string
+
+#add this context_processor as a FUNCTION
+gallery_args["context_processors"] = [current_site]
+photo_args["context_processors"] = [current_site]
+
+#import photologue urls
+urlpatterns = patterns('',
+    url(r'^', include('photologue.urls')),
+)
+
+#add our custom call to display gallery list for the root request; this only works in
+#this position because there is no root request definition defined in photologue.urls
+urlpatterns += patterns('django.views.generic.date_based',
+   url(r'^/?$', 'archive_index', gallery_args, name='pl-gallery-archive', ),
+)
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.