Permalink
Browse files

experimental (currently absolutely non-funcitonal) replacement for th…

…e image filtering
  • Loading branch information...
1 parent 6a5d87c commit 7957e2333474dd4ab9bd507e70836393f671cb34 Stefan Foulis committed Apr 29, 2009
Showing with 1,549 additions and 261 deletions.
  1. +15 −0 image_filer/actions.py
  2. +0 −55 image_filer/admin.py
  3. +116 −0 image_filer/admin/__init__.py
  4. +28 −0 image_filer/admin/filters.py
  5. +43 −14 image_filer/filters.py
  6. BIN image_filer/media/image_filer/icons/plainfolder.png
  7. +97 −0 image_filer/media/image_filer/jquery.cookie.js
  8. +551 −0 image_filer/media/image_filer/jquery.uploadify-v1.6.2/License.txt
  9. BIN image_filer/media/image_filer/jquery.uploadify-v1.6.2/Uploadify Manual.pdf
  10. BIN image_filer/media/image_filer/jquery.uploadify-v1.6.2/cancel.png
  11. +14 −0 image_filer/media/image_filer/jquery.uploadify-v1.6.2/check.php
  12. +19 −0 image_filer/media/image_filer/jquery.uploadify-v1.6.2/jquery-1.3.2.min.js
  13. +246 −0 image_filer/media/image_filer/jquery.uploadify-v1.6.2/jquery.uploadify (Source).js
  14. +20 −0 image_filer/media/image_filer/jquery.uploadify-v1.6.2/jquery.uploadify.js
  15. +16 −0 image_filer/media/image_filer/jquery.uploadify-v1.6.2/upload.php
  16. BIN image_filer/media/image_filer/jquery.uploadify-v1.6.2/uploader.fla
  17. BIN image_filer/media/image_filer/jquery.uploadify-v1.6.2/uploader.swf
  18. +30 −0 image_filer/media/image_filer/jquery.uploadify-v1.6.2/uploadify.css
  19. +145 −0 image_filer/migrations/0002_test.py
  20. +29 −18 image_filer/models/__init__.py
  21. +17 −13 image_filer/models/tools.py
  22. +1 −33 image_filer/templates/image_filer/base.html
  23. +58 −44 image_filer/templates/image_filer/directory_listing.html
  24. +44 −18 image_filer/templates/image_filer/include/clipboard.html
  25. +0 −18 image_filer/templates/image_filer/include/folderlisting.html
  26. +2 −6 image_filer/templates/image_filer/include/row_folder.html
  27. +3 −3 image_filer/templates/image_filer/include/row_image.html
  28. +1 −4 image_filer/templates/image_filer/include/tableheader.html
  29. 0 image_filer/templatetags/__init__.py
  30. +6 −5 image_filer/urls.py
  31. +48 −30 image_filer/views.py
View
@@ -0,0 +1,15 @@
+"""
+Some Image-Fielr Actions
+"""
+
+from django import template
+from django.core.exceptions import PermissionDenied
+from django.contrib.admin import helpers
+from django.contrib.admin.util import get_deleted_objects, model_ngettext
+from django.shortcuts import render_to_response
+from django.utils.encoding import force_unicode
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
+from django.utils.text import capfirst
+from django.utils.translation import ugettext_lazy, ugettext as _
+
View
@@ -1,55 +0,0 @@
-from django.contrib import admin
-from models import Folder, Image, FolderPermission, ImagePermission
-from models import ImageManipulationProfile, ImageManipulationStep, ImageManipulationTemplate
-from models import Bucket, BucketItem
-
-admin.site.register([FolderPermission, ImagePermission, ImageManipulationTemplate])
-
-
-class ImageAdmin(admin.ModelAdmin):
- list_display = ('label','admin_thumbnail', 'has_all_mandatory_data')
- list_per_page = 10
- search_fields = ['name', 'original_filename','default_alt_text','default_caption','usage_restriction_notes','notes']
- fieldsets = (
- (None, {
- 'fields': ('name', 'contact', 'owner', )
- }),
- ('Copyright and Author', {
- #'classes': ('collapse',),
- 'fields': ('author', 'must_always_publish_author_credit', 'must_always_publish_copyright')
- }),
- ('Restrictions', {
- #'classes': ('collapse',),
- 'fields': ('can_use_for_web', 'can_use_for_print','can_use_for_teaching','can_use_for_research','can_use_for_private_use')
- }),
- ('Manipulation (only works with cloned images)', {
- #'classes': ('collapse',),
- 'fields': ('manipulation_profile', )
- }),
- )
-admin.site.register(Image, ImageAdmin)
-
-class FolderAdmin(admin.ModelAdmin):
- list_display = ('name', 'owner',)
- list_per_page = 20
-admin.site.register(Folder, FolderAdmin)
-
-class ImageManipulationStepInline(admin.TabularInline):
- model = ImageManipulationStep
- fieldsets = (
- (None, {
- 'fields': ('filter_identifier', 'data', 'order')
- }),
- )
-class ImageManipulationProfileAdmin(admin.ModelAdmin):
- inlines = [ ImageManipulationStepInline, ]
-admin.site.register(ImageManipulationProfile, ImageManipulationProfileAdmin)
-
-
-
-class BucketItemInline(admin.TabularInline):
- model = BucketItem
-class BucketAdmin(admin.ModelAdmin):
- model = Bucket
- inlines = [ BucketItemInline, ]
-admin.site.register(Bucket, BucketAdmin)
@@ -0,0 +1,116 @@
+from django.contrib import admin
+from image_filer.models import *
+from django.http import HttpResponseRedirect
+from django.utils.safestring import mark_safe
+
+from django.contrib.admin import actions
+
+#hack
+import image_filer.admin.filters
+
+admin.site.register([FolderPermission, ImagePermission, ImageManipulationTemplate])
+
+
+print models
+
+class DirectoryTest(Folder):
+ """
+ Dummy Directory Model to allow the addition of an entry in the app menu
+ """
+ def label_link(self):
+ return mark_safe( '<a href="/admin/image_filer/directory/?folder_id=%s">%s</a>' % (self.id, self.label) )
+
+ def icon_link(self):
+ return mark_safe( '<img src="/media/img/icons/plainfolder.png" alt="Folder Icon" />' )
+
+ class Meta:
+ proxy = True
+ verbose_name = "[TEST] Directory Test"
+ verbose_name_plural = "[TEST] Directory Tests"
+
+class DirectoryTestAdmin(admin.ModelAdmin):
+ list_display = ('icon_link','label_link',)
+ def queryset(self, request):
+ folder_id = request.GET.get('folder_id', None)
+ qs = super(DirectoryAdmin, self).queryset(request)
+ if folder_id:
+ qs = qs.filter(parent=int(folder_id))
+ else:
+ qs = qs.filter(parent__isnull=True)
+ return qs
+admin.site.register([DirectoryTest], DirectoryTestAdmin)
+
+class Directory(Folder):
+ """
+ Dummy Directory Model to allow the addition of an entry in the app menu
+ """
+ class Meta:
+ proxy = True
+ verbose_name = "Directory Listing"
+ verbose_name_plural = "Directory Listing"
+
+class DirectoryAdmin(admin.ModelAdmin):
+ pass
+admin.site.register([Directory], DirectoryAdmin)
+
+
+class ImageAdmin(admin.ModelAdmin):
+ list_display = ('label','admin_thumbnail', 'has_all_mandatory_data')
+ list_per_page = 10
+ search_fields = ['name', 'original_filename','default_alt_text','default_caption','usage_restriction_notes','notes', 'author']
+ fieldsets = (
+ (None, {
+ 'fields': ('name', 'contact', 'owner', )
+ }),
+ ('Copyright and Author', {
+ #'classes': ('collapse',),
+ 'fields': ('author', 'must_always_publish_author_credit', 'must_always_publish_copyright')
+ }),
+ ('Restrictions', {
+ #'classes': ('collapse',),
+ 'fields': ('can_use_for_web', 'can_use_for_print','can_use_for_teaching','can_use_for_research','can_use_for_private_use')
+ }),
+ ('Manipulation (only works with cloned images)', {
+ #'classes': ('collapse',),
+ 'fields': ('manipulation_profile', )
+ }),
+ )
+admin.site.register(Image, ImageAdmin)
+#X = ["image_files__%s" % x for x in ImageAdmin.search_fields]
+
+class FolderAdmin(admin.ModelAdmin):
+ list_display = ('icon_img', 'name', 'owner',)
+ #list_display_links = ('icon_img', 'name', )
+ list_editable =('name', )
+ list_per_page = 20
+ list_filter = ('name', 'owner',)
+ verbose_name = "DEBUG Folder Admin"
+ search_fields = ['name', 'image_files__name' ]# + X
+
+ def icon_img(self,xs):
+ return mark_safe('<img src="/media/img/icons/plainfolder_32x32.png" alt="Folder Icon" />')
+ icon_img.allow_tags = True
+admin.site.register(Folder, FolderAdmin)
+
+class ImageManipulationStepInline(admin.TabularInline):
+ model = ImageManipulationStep
+ fieldsets = (
+ (None, {
+ 'fields': ('filter_identifier', 'data', 'order')
+ }),
+ )
+class ImageManipulationProfileAdmin(admin.ModelAdmin):
+ inlines = [ ImageManipulationStepInline, ]
+admin.site.register(ImageManipulationProfile, ImageManipulationProfileAdmin)
+
+
+
+class ClipboardItemInline(admin.TabularInline):
+ model = ClipboardItem
+class ClipboardAdmin(admin.ModelAdmin):
+ model = Clipboard
+ inlines = [ ClipboardItemInline, ]
+ filter_horizontal = ('files',)
+ raw_id_fields = ('user',)
+ verbose_name = "DEBUG Clipboard"
+admin.site.register(Clipboard, ClipboardAdmin)
@@ -0,0 +1,28 @@
+from image_filer.filters import library
+from image_filer.filters import BaseFilter, ResizeFilter
+
+print "importing image_filer.admin.filters!"
+
+class AdminThumbnailFilter(BaseFilter):
+ identifier = 'admin_thumbnail'
+ name = 'Admin Thumbnail'
+ def render(self, im):
+ print 'rendering AdminThumbnailFilter'
+ return ResizeFilter().render(im, size_x=128, size_y=128, crop=True, upscale=True, crop_from='center')
+library.register(AdminThumbnailFilter)
+
+class AdminTinyThumbnailFilter(BaseFilter):
+ identifier = 'admin_tiny_thumbnail'
+ name = 'Admin Tiny Thumbnail'
+ def render(self, im):
+ print 'rendering AdminTinyThumbnailFilter'
+ return ResizeFilter().render(im, size_x=32, size_y=32, crop=True, upscale=True, crop_from='center')
+library.register(AdminTinyThumbnailFilter)
+
+class AdminSidebarPreviewFilter(BaseFilter):
+ identifier = 'admin_sidebar_preview'
+ name = 'Admin Sidebar Preview'
+ def render(self, im):
+ print 'rendering AdminSidebarPreviewFilter'
+ return ResizeFilter().render(im, size_x=250, size_y=100, crop=True, upscale=True, crop_from='center')
+library.register(AdminSidebarPreviewFilter)
View
@@ -1,4 +1,5 @@
from inspect import isclass
+from fnmatch import filter
try:
import Image
import ImageColor
@@ -15,10 +16,44 @@
except ImportError:
raise ImportError("The Python Imaging Library was not found.")
-filters = []
+#filters = [] #hack for compatibility
+filters_by_identifier = {}
+
+class FilterRegistry(object):
+ def __init__(self):
+ self.builtin_filters = {}
+ self.application_filters = {}
+ self.project_filters = {}
+ self.db_filters = {}
+ self.registry_priority = [self.db_filters, self.project_filters,
+ self.application_filters, self.builtin_filters]
+
+ def _register(self, filter, library):
+ library[filter.identifier] = filter
+ filters_by_identifier[filter.identifier] = filter #hack for compatibility
+
+ def register_builtin_filter(self, filter):
+ self._register(filter, self.builtin_filters)
+ def register_application_filter(self, filter):
+ self._register(filter, self.application_filters)
+ def register_project_filter(self, filter):
+ self._register(filter, self.project_filters)
+ def register_db_filter(self, filter):
+ self._register(filter, self.db_filters)
+ def register(self, filter):
+ self.register_project_filter(filter)
+
+ def get(self, identifier):
+ for reg in self.registry_priority:
+ if reg.has_key(identifier):
+ return reg[identifier]
+ return None
+
+library = FilterRegistry()
+
class BaseFilter(object):
- pass
+ identifier = "base_filter"
class ResizeFilter(BaseFilter):
name = "Resize to specified dimensions"
@@ -63,20 +98,20 @@ def render(self, im, size_x=128, size_y=64, crop=True, crop_from='top', upscale=
return im
im = im.resize(new_dimensions, Image.ANTIALIAS)
return im
-filters.append(ResizeFilter)
+library.register_builtin_filter(ResizeFilter)
class TinyResizeFilterHack(ResizeFilter):
name = "Tiny Resize Filter Hack"
identifier = "resize_simple_tiny_hack"
def render(self, im, size_x=24, size_y=24, crop=True, crop_from='top', upscale=True):
return super(TinyResizeFilterHack, self).render(im, size_x=size_x, size_y=size_y)
-filters.append(TinyResizeFilterHack)
+library.register_builtin_filter(TinyResizeFilterHack)
class MiddleResizeFilterHack(ResizeFilter):
name = "Middle Resize Filter Hack"
identifier = "resize_simple_middle_hack"
def render(self, im, size_x=196, size_y=196, crop=True, crop_from='top', upscale=False):
return super(MiddleResizeFilterHack, self).render(im, size_x=size_x, size_y=size_y)
-filters.append(MiddleResizeFilterHack)
+library.register_builtin_filter(MiddleResizeFilterHack)
class ReflectionFilter(BaseFilter):
name = "Sexy Web 2.0 reflection filter"
@@ -131,7 +166,7 @@ def render(self, im, bgcolor="#FFFFFF", amount=0.4, opacity=0.6):
# return the image complete with reflection effect
return composite
-filters.append(ReflectionFilter)
+library.register_builtin_filter(ReflectionFilter)
"""
Create image filter objects for all the built in PIL filters
@@ -143,14 +178,8 @@ def render(self, im, bgcolor="#FFFFFF", amount=0.4, opacity=0.6):
class NewSubclass(BaseFilter):
_pil_filter = klass
name = klass.name
- identifier = klass.name
+ identifier = klass.name.replace(' ', '').lower()
def render(self, im):
return im.filter(self._pil_filter)
NewSubclass.__name__ = "%s%s" % (klass.name, "Filter")
- filters.append(NewSubclass)
-
-
-
-filters_by_identifier = {}
-for filter in filters:
- filters_by_identifier[filter.identifier] = filter
+ library.register_builtin_filter(NewSubclass)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 7957e23

Please sign in to comment.