Skip to content
Browse files

Enhanced plugin and added GalleryImageExtension model

- Added display_type to GalleryPlugin model
- Added new setting GALLERY_DISPLAY_TYPE_CHOICES
- Added GalleryImageExtension model
- Added inline for image extensions to Filer's Image admin
  • Loading branch information...
1 parent 3cca651 commit 8d8222d215450416c2afe0e814d64983ae4ec833 @mbrochh mbrochh committed
View
4 CHANGELOG.txt
@@ -1,5 +1,9 @@
=== ongoing ===
+- Added display_type to GalleryPlugin model
+- Added new setting GALLERY_DISPLAY_TYPE_CHOICES
+- Added GalleryImageExtension model
+- Added inline for image extensions to Filer's Image admin
=== 0.5 ===
View
17 README.rst
@@ -72,6 +72,23 @@ Default: 10
Amount of galleries to display in the list view.
+GALLERY_DISPLAY_TYPE_CHOICES
+++++++++++++++++++++++++++++
+
+Default::
+
+ (
+ ('default', _('Default')),
+ ('teaser', _('Teaser')),
+ )
+
+When you use the ``Filer Gallery`` plugin, you can select the gallery that
+should be rendered and a display type. This is useful if one and the same
+gallery should be rendrerd in different ways at different places on your
+site. The selected value will be added to the plugin template's context with
+the variable name ``{{ display_type }}``.
+
+
Contribute
----------
View
12 image_gallery/admin.py
@@ -2,8 +2,9 @@
from django.contrib import admin
from cms.admin.placeholderadmin import PlaceholderAdmin
+from filer.admin.imageadmin import ImageAdmin
-from image_gallery.models import Gallery, GalleryCategory
+from . import models
class GalleryAdmin(PlaceholderAdmin):
@@ -17,5 +18,10 @@ class GalleryCategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'slug')
-admin.site.register(GalleryCategory, GalleryCategoryAdmin)
-admin.site.register(Gallery, GalleryAdmin)
+class GalleryImageInline(admin.TabularInline):
+ model = models.GalleryImageExtension
+
+
+admin.site.register(models.GalleryCategory, GalleryCategoryAdmin)
+admin.site.register(models.Gallery, GalleryAdmin)
+ImageAdmin.inlines = ImageAdmin.inlines[:] + [GalleryImageInline]
View
11 image_gallery/app_settings.py
@@ -1,4 +1,15 @@
"""Settings of the ``image_gallery``` application."""
from django.conf import settings
+from django.utils.translation import ugettext_lazy as _
+
+GALLERY_DISPLAY_TYPE_CHOICES_DEFAULT = (
+ ('default', _('Default')),
+ ('teaser', _('Teaser')),
+)
PAGINATION_AMOUNT = getattr(settings, 'GALLERY_PAGINATION_AMOUNT', 10)
+DISPLAY_TYPE_CHOICES = getattr(
+ settings,
+ 'GALLERY_DISPLAY_TYPE_CHOICES',
+ GALLERY_DISPLAY_TYPE_CHOICES_DEFAULT
+)
View
1 image_gallery/cms_plugins.py
@@ -17,6 +17,7 @@ def render(self, context, instance, placeholder):
'gallery': instance.gallery,
'images': instance.gallery.get_folder_images(),
'placeholder': placeholder,
+ 'display_type': instance.display_type,
})
return context
View
120 image_gallery/migrations/0004_auto__add_field_galleryplugin_display_type.py
@@ -0,0 +1,120 @@
+# flake8: noqa
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'GalleryPlugin.display_type'
+ db.add_column('cmsplugin_galleryplugin', 'display_type',
+ self.gf('django.db.models.fields.CharField')(default='', max_length=256, blank=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'GalleryPlugin.display_type'
+ db.delete_column('cmsplugin_galleryplugin', 'display_type')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 9, 3, 0, 0)'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+ 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ 'cms.placeholder': {
+ 'Meta': {'object_name': 'Placeholder'},
+ 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'filer.folder': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('parent', 'name'),)", 'object_name': 'Folder'},
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'filer_owned_folders'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['filer.Folder']"}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
+ },
+ 'image_gallery.gallery': {
+ 'Meta': {'object_name': 'Gallery'},
+ 'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['image_gallery.GalleryCategory']", 'null': 'True', 'blank': 'True'}),
+ 'date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'folder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['filer.Folder']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'image_gallery.gallerycategory': {
+ 'Meta': {'object_name': 'GalleryCategory'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '32'})
+ },
+ 'image_gallery.galleryplugin': {
+ 'Meta': {'object_name': 'GalleryPlugin', 'db_table': "'cmsplugin_galleryplugin'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'display_type': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
+ 'gallery': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['image_gallery.Gallery']"})
+ }
+ }
+
+ complete_apps = ['image_gallery']
View
159 image_gallery/migrations/0005_auto__add_galleryimageextension.py
@@ -0,0 +1,159 @@
+# flake8: noqa
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'GalleryImageExtension'
+ db.create_table('image_gallery_galleryimageextension', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('image', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['filer.Image'])),
+ ('is_featured_image', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ))
+ db.send_create_signal('image_gallery', ['GalleryImageExtension'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'GalleryImageExtension'
+ db.delete_table('image_gallery_galleryimageextension')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 9, 3, 0, 0)'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+ 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ 'cms.placeholder': {
+ 'Meta': {'object_name': 'Placeholder'},
+ 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'filer.file': {
+ 'Meta': {'object_name': 'File'},
+ '_file_size': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'folder': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'all_files'", 'null': 'True', 'to': "orm['filer.Folder']"}),
+ 'has_all_mandatory_data': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'original_filename': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_files'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'polymorphic_ctype': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'polymorphic_filer.file_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}),
+ 'sha1': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '40', 'blank': 'True'}),
+ 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
+ },
+ 'filer.folder': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('parent', 'name'),)", 'object_name': 'Folder'},
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'filer_owned_folders'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['filer.Folder']"}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
+ },
+ 'filer.image': {
+ 'Meta': {'object_name': 'Image', '_ormbases': ['filer.File']},
+ '_height': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ '_width': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'author': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'date_taken': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'default_alt_text': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'default_caption': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'file_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['filer.File']", 'unique': 'True', 'primary_key': 'True'}),
+ 'must_always_publish_author_credit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'must_always_publish_copyright': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'subject_location': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '64', 'null': 'True', 'blank': 'True'})
+ },
+ 'image_gallery.gallery': {
+ 'Meta': {'object_name': 'Gallery'},
+ 'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['image_gallery.GalleryCategory']", 'null': 'True', 'blank': 'True'}),
+ 'date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'folder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['filer.Folder']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'image_gallery.gallerycategory': {
+ 'Meta': {'object_name': 'GalleryCategory'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '32'})
+ },
+ 'image_gallery.galleryimageextension': {
+ 'Meta': {'object_name': 'GalleryImageExtension'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['filer.Image']"}),
+ 'is_featured_image': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'image_gallery.galleryplugin': {
+ 'Meta': {'object_name': 'GalleryPlugin', 'db_table': "'cmsplugin_galleryplugin'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'display_type': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
+ 'gallery': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['image_gallery.Gallery']"})
+ }
+ }
+
+ complete_apps = ['image_gallery']
View
160 ...migrations/0006_auto__chg_field_galleryimageextension_image__add_unique_galleryimageex.py
@@ -0,0 +1,160 @@
+# flake8: noqa
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'GalleryImageExtension.image'
+ db.alter_column('image_gallery_galleryimageextension', 'image_id', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['filer.Image'], unique=True))
+ # Adding unique constraint on 'GalleryImageExtension', fields ['image']
+ db.create_unique('image_gallery_galleryimageextension', ['image_id'])
+
+
+ def backwards(self, orm):
+ # Removing unique constraint on 'GalleryImageExtension', fields ['image']
+ db.delete_unique('image_gallery_galleryimageextension', ['image_id'])
+
+
+ # Changing field 'GalleryImageExtension.image'
+ db.alter_column('image_gallery_galleryimageextension', 'image_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['filer.Image']))
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2013, 9, 3, 0, 0)'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+ 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+ 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ 'cms.placeholder': {
+ 'Meta': {'object_name': 'Placeholder'},
+ 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'filer.file': {
+ 'Meta': {'object_name': 'File'},
+ '_file_size': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'folder': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'all_files'", 'null': 'True', 'to': "orm['filer.Folder']"}),
+ 'has_all_mandatory_data': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_public': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+ 'original_filename': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_files'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'polymorphic_ctype': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'polymorphic_filer.file_set'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}),
+ 'sha1': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '40', 'blank': 'True'}),
+ 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
+ },
+ 'filer.folder': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('parent', 'name'),)", 'object_name': 'Folder'},
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'filer_owned_folders'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['filer.Folder']"}),
+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
+ },
+ 'filer.image': {
+ 'Meta': {'object_name': 'Image', '_ormbases': ['filer.File']},
+ '_height': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ '_width': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'author': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'date_taken': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'default_alt_text': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'default_caption': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'file_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['filer.File']", 'unique': 'True', 'primary_key': 'True'}),
+ 'must_always_publish_author_credit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'must_always_publish_copyright': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'subject_location': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '64', 'null': 'True', 'blank': 'True'})
+ },
+ 'image_gallery.gallery': {
+ 'Meta': {'object_name': 'Gallery'},
+ 'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['image_gallery.GalleryCategory']", 'null': 'True', 'blank': 'True'}),
+ 'date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+ 'folder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['filer.Folder']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'location': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'image_gallery.gallerycategory': {
+ 'Meta': {'object_name': 'GalleryCategory'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '32'})
+ },
+ 'image_gallery.galleryimageextension': {
+ 'Meta': {'object_name': 'GalleryImageExtension'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['filer.Image']", 'unique': 'True'}),
+ 'is_featured_image': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
+ },
+ 'image_gallery.galleryplugin': {
+ 'Meta': {'object_name': 'GalleryPlugin', 'db_table': "'cmsplugin_galleryplugin'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'display_type': ('django.db.models.fields.CharField', [], {'max_length': '256', 'blank': 'True'}),
+ 'gallery': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['image_gallery.Gallery']"})
+ }
+ }
+
+ complete_apps = ['image_gallery']
View
60 image_gallery/models.py
@@ -10,6 +10,8 @@
from filer.fields.folder import FilerFolderField
from filer.models.imagemodels import Image
+from . import app_settings
+
class Gallery(models.Model):
"""
@@ -65,8 +67,29 @@ def __unicode__(self):
def get_absolute_url(self):
return reverse('image_gallery_detail', kwargs={'pk': self.pk, })
+ def get_featured_images(self):
+ """
+ Returns those images of a given Gallery that are featured images.
+
+ TODO: Find a way to test this
+
+ """
+ result = []
+ for image in self.get_folder_images():
+ try:
+ if image.galleryimageextension.is_featured_image:
+ result.append(image)
+ except GalleryImageExtension.DoesNotExist:
+ pass
+ return result
+
def get_folder_images(self):
- """Returns a set of images, which have been placed in this folder."""
+ """
+ Returns a set of images, which have been placed in this folder.
+
+ TODO: Find a way to test this
+
+ """
qs_files = self.folder.files.instance_of(Image)
return qs_files.filter(is_public=True)
@@ -107,9 +130,42 @@ def __unicode__(self):
return self.name
+class GalleryImageExtension(models.Model):
+ """
+ Adds extra fields to the FilerImage admin.
+
+ :image: The Image instance this object is extending.
+ :is_featured_image: A boolean field that can be used for example to render
+ a teaser of a gallery and only show a few featured images.
+ """
+ image = models.OneToOneField(
+ Image,
+ verbose_name=_('Image'),
+ )
+
+ is_featured_image = models.BooleanField(
+ default=False,
+ verbose_name=_('Is featured image'),
+ )
+
+
class GalleryPlugin(CMSPlugin):
- """Plugin model to link to a specific gallery instance."""
+ """
+ Plugin model to link to a specific gallery instance.
+
+ :gallery: The gallery instance that this plugin should render
+ :display_type: A string that will be passed to the plugin templates. This
+ allows you to render the gallery differently at different places on your
+ page.
+
+ """
gallery = models.ForeignKey(
Gallery,
verbose_name=_('Gallery'),
)
+
+ display_type = models.CharField(
+ max_length=256,
+ choices=app_settings.DISPLAY_TYPE_CHOICES,
+ blank=True,
+ )
View
14 image_gallery/tests/factories.py
@@ -2,7 +2,7 @@
from factory import DjangoModelFactory, LazyAttribute, SubFactory, Sequence
from filer.models import Folder, Image
-from image_gallery.models import Gallery, GalleryCategory, GalleryPlugin
+from .. import models
class FolderFactory(DjangoModelFactory):
@@ -16,14 +16,20 @@ class ImageFactory(DjangoModelFactory):
class GalleryCategoryFactory(DjangoModelFactory):
- FACTORY_FOR = GalleryCategory
+ FACTORY_FOR = models.GalleryCategory
name = Sequence(lambda i: 'name {}'.format(i))
slug = LazyAttribute(lambda a: a.name.replace(' ', '-'))
+class GalleryImageExtensionFactory(DjangoModelFactory):
+ FACTORY_FOR = models.GalleryImageExtension
+
+ image = SubFactory(ImageFactory)
+
+
class GalleryFactory(DjangoModelFactory):
- FACTORY_FOR = Gallery
+ FACTORY_FOR = models.Gallery
title = 'Test Gallery'
folder = SubFactory(FolderFactory)
@@ -32,6 +38,6 @@ class GalleryFactory(DjangoModelFactory):
class GalleryPluginFactory(DjangoModelFactory):
- FACTORY_FOR = GalleryPlugin
+ FACTORY_FOR = models.GalleryPlugin
gallery = SubFactory(GalleryFactory)
View
11 image_gallery/tests/models_tests.py
@@ -5,6 +5,7 @@
from .factories import (
GalleryFactory,
GalleryCategoryFactory,
+ GalleryImageExtensionFactory,
GalleryPluginFactory,
)
@@ -25,6 +26,16 @@ def test_get_folder_images(self):
'Should return an empty image list.'))
+class GalleryImageExtensionTestCase(TestCase):
+ """Tests for the ``GalleryImageExtension`` model class."""
+ longMessage = True
+
+ def test_instantiation(self):
+ obj = GalleryImageExtensionFactory()
+ self.assertTrue(obj, msg=(
+ 'Should be able to instantiate and save the object.'))
+
+
class GalleryCategoryTestCase(TestCase):
"""Tests for the ``GalleryCategory`` model class."""
longMessage = True

0 comments on commit 8d8222d

Please sign in to comment.
Something went wrong with that request. Please try again.