Commits

cur...@tinbrain.net  committed 7210707

Initial checkin

  • Participants

Comments (0)

Files changed (8)

+syntax: glob
+*~
+*.pyc
+====
+NOTE
+====
+
+This application is written to use the "pregen" fork of SmileyChris'
+easy-thumbnails.
+
+It's not essential, but the purpose of the ThumbnailConfig is for the aliases.

File gnocchi_gallery/__init__.py

Empty file added.

File gnocchi_gallery/admin.py

+from django.contrib import admin
+from gnocchi_gallery import models
+import os
+from easy_thumbnails.files import get_thumbnailer
+from django.conf import settings
+
+class ImageInline(admin.TabularInline):
+    model = models.Image
+
+class GalleryAdmin(admin.ModelAdmin):
+    list_display = ('name',)
+    inlines = (
+        ImageInline,
+    )
+
+admin.site.register(models.Gallery, GalleryAdmin)
+
+class ImageAdmin(admin.ModelAdmin):
+    list_display = ('thumb', 'gallery', 'image', 'name', 'order',)
+    list_filter = ('gallery', 'order',)
+    list_editable = ('order',)
+
+    def thumb(self, obj):
+        fname = obj.image
+        # Strip media root from file path
+        if os.path.commonprefix([fname, settings.MEDIA_ROOT]) == settings.MEDIA_ROOT:
+            fname = fname[len(settings.MEDIA_ROOT):]
+        img = get_thumbnailer(fname).get_thumbnail({'size': (70, 70,)})
+        return '<img src="%s" alt="" />' % (img.url,)
+    thumb.short_description = 'Thumbnail'
+    thumb.allow_tags = True
+
+admin.site.register(models.Image, ImageAdmin)
+
+class ThumbnailConfigAdmin(admin.ModelAdmin):
+    list_display = ('name',)
+
+admin.site.register(models.ThumbnailConfig, ThumbnailConfigAdmin)

File gnocchi_gallery/models.py

+from django.db import models
+
+from gnocchi_tools.attr import AttrHelper
+from taggit.managers import TaggableManager
+from django.contrib.contenttypes import generic
+
+class Gallery(models.Model):
+    name = models.CharField(max_length=128)
+    slug = models.SlugField()
+
+    class Meta:
+        verbose_name_plural = 'Galleries'
+    def __unicode__(self):
+        return self.name
+
+class Image(models.Model, AttrHelper):
+    gallery = models.ForeignKey(Gallery, related_name='images')
+    name = models.CharField(max_length=128, blank=True)
+    description = models.TextField(blank=True)
+
+    image = models.ImageField(upload_to='gallery')
+    order = models.IntegerField(default=0)
+
+    attributes = generic.GenericRelation('gnocchi_tools.Attribute')
+    tags = TaggableManager()
+
+    class Meta:
+        ordering = ('order', 'id',)
+        verbose_name_plural = 'Gallery Images'
+
+class ThumbnailConfig(models.Model, AttrHelper):
+    name = models.CharField(max_length=128)
+
+    attributes = generic.GenericRelation('gnocchi_tools.Attribute')

File gnocchi_gallery/templatetags/__init__.py

Empty file added.

File gnocchi_gallery/templatetags/gallery.py

+from django import template
+from django.db.models import Q
+from gnocchi_gallery.models import Gallery
+from gnocchi_tools.template import parse_args
+
+register = template.Library()
+
+class LoadGalleryNode(template.Node):
+    def __init__(self, gallery, var):
+        self.gallery = gallery
+        self.var = var
+
+    def render(self, context):
+        name = self.gallery.resolve(context)
+        varname = self.var
+        if not isinstance(varname, basestring):
+            varname = varname.resolve(context)
+        try:
+            context[varname] = Gallery.objects.get(Q(name=name)|Q(slug=name))
+        except Gallery.DoesNotExist:
+            context[varname] = None
+        return ''
+
+@register.tag
+def load_gallery(parser, token):
+    args, kwargs, varname = parse_args(parser, token, 'gallery')
+    if len(args) != 1 or kwargs:
+        raise template.TemplateSyntaxError, \
+            'load_gallery requires one position, and no keyword, argument.' % args[0]
+    return LoadGalleryNode(args[0], varname)
+from setuptools import setup, find_packages
+
+setup( name='gnocchi-gallery',
+    version = '1.0',
+    description = 'A simple gallery app',
+    author = 'Curtis Maloney',
+    author_email = 'curtis@tinbrain.net',
+    url = 'http://bitbucket.org/funkybob/gnocchi-gallery/',
+    keywords = ['django', 'gallery',],
+    packages = find_packages(),
+    zip_safe = False,
+    classifiers = [
+        'Environment :: Web Environment',
+        'Framework :: Django',
+        'License :: OSI Approved :: BSD License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+    ],
+    install_requires = [
+        'Django>=1.2',
+        'django-taggit',
+        'easy-thumbnails',
+    ]
+)