Commits

Simon Meers committed 4c06d9d

Initial commit

  • Participants

Comments (0)

Files changed (8)

+*.pyc
+*~
+
+.DS_Store
+pip-log.txt
+*.egg-info
+
+# Aptana/pycharm/pydev stuff
+.tmp_*~
+.idea
+.project
+.pydevproject
+.settings*
+include MANIFEST.in
+include README.rst
+recursive-include gallery/templates *.html
+recursive-include gallery/static *.js *.css
+A simple FeinCMS gallery that does not require/support medialibrary, translations, etc.

gallery/__init__.py

Empty file added.
+from django.contrib import admin
+from .models import Gallery, Photo
+
+ADMIN_THUMBNAIL_SIZE = (100, 100)
+class PhotoAdmin(admin.ModelAdmin):
+    list_display = ('admin_thumbnail', 'caption', 'gallery')
+    list_filter = ('gallery',)
+    def admin_thumbnail(self, photo):
+        return '<img src="%s" />' % (
+            photo.get_thumbnail(size=ADMIN_THUMBNAIL_SIZE).url)
+    admin_thumbnail.allow_tags = True
+    admin_thumbnail.short_description = 'Thumbnail'
+
+class PhotoInline(admin.TabularInline):
+    model = Photo
+    extra = 0
+
+class GalleryAdmin(admin.ModelAdmin):
+    inlines = [PhotoInline]
+
+admin.site.register(Photo, PhotoAdmin)
+admin.site.register(Gallery, GalleryAdmin)

gallery/models.py

+import os
+
+from django.db import models
+from django.template.loader import render_to_string
+from django.utils.translation import ugettext_lazy as _
+
+from easy_thumbnails.files import get_thumbnailer
+
+
+class Gallery(models.Model):
+    created = models.DateTimeField(auto_now_add=True)
+    title = models.CharField(max_length=255)
+
+    class Meta:
+        verbose_name_plural = 'Galleries'
+        ordering = ('created',)
+
+    def __unicode__(self):
+        return self.title
+
+
+class Photo(models.Model):
+    created = models.DateTimeField(auto_now_add=True)
+    gallery = models.ForeignKey(Gallery, related_name='photos')
+    photo = models.ImageField(
+        max_length=255, upload_to='uploads/gallery_photos')
+    caption = models.CharField(max_length=255, blank=True)
+
+    class Meta:
+        ordering = ('created',)
+
+    def __unicode__(self):
+        return self.caption or u'Image without caption'
+
+    def get_thumbnail(self, **kwargs):
+        options = dict(size=(100, 100), crop=True)
+        options.update(kwargs)
+        return get_thumbnailer(self.photo).get_thumbnail(options)
+
+
+class GalleryContent(models.Model):
+    gallery = models.ForeignKey(Gallery)
+    show_title = models.BooleanField(default=True)
+    show_captions = models.BooleanField(default=True)
+
+    class Meta:
+        abstract = True
+        verbose_name = 'Gallery'
+        verbose_name_plural = 'Galleries'
+
+    def render(self, **kwargs):
+        return render_to_string(
+            'gallery/render.html', {
+                'gallery': self.gallery,
+                'show_title': self.show_title,
+                'show_captions': self.show_captions,})

gallery/templates/gallery/render.html

+{% load thumbnail %}
+<div class="gallery">
+  {% if show_title and gallery.title %}
+    <h3>{{ gallery.title }}</h3>
+  {% endif %}
+  {% for photo in gallery.photos.all %}
+    <div class="gallery_photo">
+      <a href="{% thumbnail photo.photo 800x800 %}">
+        <img src="{% thumbnail photo.photo 200x200 upscale crop polaroid %}" title="{{ photo.caption }}" />
+        {% if show_captions and photo.caption %}
+          <span class="caption">{{ photo.caption }}</span>
+        {% endif %}
+      </a>
+    </div>
+  {% endfor %}
+  <div style="clear: both;"></div>
+</div>
+import setuptools
+
+setuptools.setup(
+    name='feincms-gallery',
+    version='0.1',
+    description='Simple FeinCMS Gallery',
+    author='Simon Meers',
+    author_email='simon@simonmeers.com',
+    packages=setuptools.find_packages(),
+    classifiers=[
+        'Development Status :: 3 - Alpha',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: BSD License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Framework :: Django',],
+    install_requires=[],
+    include_package_data=True)