Commits

Anonymous committed 80395db

Reorganised for unified namespace
Simplified load_template tag

Comments (0)

Files changed (18)

gnocchi/__init__.py

+__import__('pkg_resources').declare_namespace(__name__)
+

gnocchi/gallery/__init__.py

Empty file added.

gnocchi/gallery/admin.py

+from django.contrib import admin
+from gnocchi.gallery import models
+from easy_thumbnails.files import get_thumbnailer
+from gnocchi.tools.admin import InlineAttributeAdmin
+
+class ImageInline(admin.TabularInline):
+    model = models.Image
+
+class GalleryAdmin(admin.ModelAdmin):
+    list_display = ('name', 'slug',)
+    prepopulated_fields = {
+        'slug': ('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):
+        img = get_thumbnailer(obj.image).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',)
+    inlines = (
+        InlineAttributeAdmin,
+    )
+
+admin.site.register(models.ThumbnailConfig, ThumbnailConfigAdmin)

gnocchi/gallery/management/__init__.py

Empty file added.

gnocchi/gallery/management/commands/__init__.py

Empty file added.

gnocchi/gallery/management/commands/gallery_sync.py

+from django.core.management.base import BaseCommand
+from django.conf import settings
+
+from gnocchi.gallery.models import Gallery, Image
+
+import os
+
+class Command(BaseCommand):
+    def handle(self):
+        root = os.path.join(settings.MEDIA_ROOT, 'gallery/')
+        for slug in os.listdir(root):
+            try:
+                gallery = Gallery.objects.get(slug=slug)
+            except Gallery.DoesNotExist:
+                print "No gallery matching %s. Skipping..." % slug
+                continue
+            print "Scanning gallery: %s" % gallery
+            for name in os.listdir(os.path.join(root, slug)):
+                filename = os.path.join('gallery', slug, name)
+                try:
+                    image = Image.objects.get(image=filename)
+                except Image.DoesNotExist:
+                    print "Adding Image: %s" % filename
+                    image = Image.objects.create(
+                        gallery=gallery,
+                        image=filename,
+                    )
+            print "Finished: %s" % gallery
+        print "Done!"

gnocchi/gallery/models.py

+from django.db import models
+import os
+
+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
+
+def upload_to(instance, filename):
+    return os.path.join('gallery', instance.gallery.slug, filename)
+
+class Image(models.Model, AttrHelper):
+    image = models.ImageField(upload_to=upload_to)
+    gallery = models.ForeignKey(Gallery, related_name='images')
+    name = models.CharField(max_length=128, blank=True)
+    order = models.IntegerField(default=0)
+
+    attributes = generic.GenericRelation('tools.Attribute')
+    tags = TaggableManager(blank=True)
+
+    class Meta:
+        ordering = ('order', 'id',)
+        verbose_name_plural = 'Gallery Images'
+
+class ThumbnailConfig(models.Model, AttrHelper):
+    name = models.CharField(max_length=128)
+
+    attributes = generic.GenericRelation('tools.Attribute')

gnocchi/gallery/templatetags/__init__.py

Empty file added.

gnocchi/gallery/templatetags/gallery.py

+from django import template
+from django.db.models import Q
+from django.utils.html import escape
+
+from gnocchi.gallery.models import Gallery, ThumbnailConfig
+
+import re
+from easy_thumbnails.files import get_thumbnailer
+
+register = template.Library()
+
+@register.simple_tag(takes_context=True)
+def load_gallery(context, gallery, varname='gallery'):
+    try:
+        context[varname] = Gallery.objects.get(Q(name=gallery)|Q(slug=gallery))
+    except Gallery.DoesNotExist:
+        context[varname] = None
+    return ''
+
+
+RE_SIZE = re.compile(r'(\d+)x(\d+)$')
+
+@register.filter
+def config_thumbnail(source, name):
+    '''Turns an image field or image path into a URL to a thumbnail, made using
+    the named config.
+    '''
+
+    try:
+        config = ThumbnailConfig.objects.get(name=name)
+    except ThumbnailConfig.DoesNotExist:
+        return ''
+    config._load_cache()
+    opts = config._attributes
+    if 'size' in opts:
+        m = RE_SIZE.match(opts['size'])
+        if m:
+            opts['size'] = (int(m.group(1)), int(m.group(2)))
+        else:
+            return ''
+    thumbnail = get_thumbnailer(source).get_thumbnail(config._attributes)
+    return escape(thumbnail.url)

gnocchi_gallery/__init__.py

Empty file removed.

gnocchi_gallery/admin.py

-from django.contrib import admin
-from gnocchi_gallery import models
-import os
-from easy_thumbnails.files import get_thumbnailer
-from gnocchi_tools.admin import InlineAttributeAdmin
-from django.conf import settings
-
-class ImageInline(admin.TabularInline):
-    model = models.Image
-
-class GalleryAdmin(admin.ModelAdmin):
-    list_display = ('name', 'slug',)
-    prepopulated_fields = {
-        'slug': ('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):
-        img = get_thumbnailer(obj.image).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',)
-    inlines = (
-        InlineAttributeAdmin,
-    )
-
-admin.site.register(models.ThumbnailConfig, ThumbnailConfigAdmin)

gnocchi_gallery/management/__init__.py

Empty file removed.

gnocchi_gallery/management/commands/__init__.py

Empty file removed.

gnocchi_gallery/management/commands/gallery_sync.py

-from django.core.management.base import BaseCommand, CommandError
-from django.conf import settings
-
-from gnocchi_gallery.models import Gallery, Image
-
-import os
-
-class Command(BaseCommand):
-    def handle(self, *args, **kwargs):
-        root = os.path.join(settings.MEDIA_ROOT, 'gallery/')
-        for slug in os.listdir(root):
-            try:
-                gallery = Gallery.objects.get(slug=slug)
-            except Gallery.DoesNotExist:
-                print "No gallery matching %s. Skipping..." % slug
-                continue
-            print "Scanning gallery: %s" % gallery
-            for name in os.listdir(os.path.join(root, slug)):
-                filename = os.path.join('gallery', slug, name)
-                try:
-                    im = Image.objects.get(image=filename)
-                except Image.DoesNotExist:
-                    print "Adding Image: %s" % filename
-                    image = Image.objects.create(
-                        gallery=gallery,
-                        image=filename,
-                    )
-            print "Finished: %s" % gallery
-        print "Done!"

gnocchi_gallery/models.py

-from django.db import models
-import os
-
-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
-
-def upload_to(instance, filename):
-    return os.path.join('gallery', instance.gallery.slug, filename)
-
-class Image(models.Model, AttrHelper):
-    image = models.ImageField(upload_to=upload_to)
-    gallery = models.ForeignKey(Gallery, related_name='images')
-    name = models.CharField(max_length=128, blank=True)
-    order = models.IntegerField(default=0)
-
-    attributes = generic.GenericRelation('gnocchi_tools.Attribute')
-    tags = TaggableManager(blank=True)
-
-    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')

gnocchi_gallery/templatetags/__init__.py

Empty file removed.

gnocchi_gallery/templatetags/gallery.py

-from django import template
-from django.db.models import Q
-from django.utils.html import escape
-
-from gnocchi_gallery.models import Gallery, ThumbnailConfig
-from gnocchi_tools.template import parse_args
-
-import re
-from easy_thumbnails.files import get_thumbnailer
-
-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)
-
-RE_SIZE = re.compile(r'(\d+)x(\d+)$')
-
-@register.filter
-def config_thumbnail(source, name):
-    '''Turns an image field or image path into a URL to a thumbnail, made using
-    the named config.
-
-    '''
-
-    try:
-        config = ThumbnailConfig.objects.get(name=name)
-    except ThumbnailConfig.DoesNotExist:
-        return ''
-    config._load_cache()
-    opts = config._attributes
-    if 'size' in opts:
-        m = RE_SIZE.match(opts['size'])
-        if m:
-            opts['size'] = (int(m.group(1)), int(m.group(2)))
-        else:
-            return ''
-    thumbnail = get_thumbnailer(source).get_thumbnail(config._attributes)
-    return escape(thumbnail.url)
 from setuptools import setup, find_packages
 
 setup( name='gnocchi-gallery',
-    version = '1.0',
+    version = '1.1',
     description = 'A simple gallery app',
     author = 'Curtis Maloney',
     author_email = 'curtis@tinbrain.net',
     install_requires = [
         'Django>=1.2',
         'django-taggit',
+        'gnocchi-tools>=1.1',
         'easy-thumbnails',
     ]
 )