Browse files

still unstable

  • Loading branch information...
1 parent 7bb21e4 commit de6784752015a6283c698e1802e83177c269fe10 @stefanfoulis committed Jun 23, 2009
View
4 example/django_project/settings.py
@@ -14,7 +14,7 @@
MANAGERS = ADMINS
if True:
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- DATABASE_NAME = 'image_filer_example' # Or path to database file if using sqlite3.
+ DATABASE_NAME = 'image_filer_example2' # Or path to database file if using sqlite3.
DATABASE_USER = 'root' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = 'localhost' # Set to empty string for localhost. Not used with sqlite3.
@@ -103,7 +103,7 @@
'django.contrib.sites',
'django.contrib.admin',
- 'south',
+ #'south',
'mptt',
'sorl.thumbnail',
View
15 image_filer/admin/__init__.py
@@ -56,11 +56,11 @@ def has_delete_permission(self, request, obj=None):
admin.site.register([Directory], DirectoryAdmin)
-class ImageAdmin(PrimitivePermissionAwareModelAdmin):
+class ImageFileAdmin(PrimitivePermissionAwareModelAdmin):
list_display = ('label',)
list_per_page = 10
search_fields = ['name', 'original_filename','default_alt_text','default_caption','usage_restriction_notes','notes', 'author']
- raw_id_fields = ('contact', 'owner',)
+ raw_id_fields = ('owner',)
# save_as hack, because without save_as it is impossible to hide the
# save_and_add_another if save_as is False.
# To show only save_and_continue and save in the submit row we need save_as=True
@@ -83,15 +83,12 @@ class ImageAdmin(PrimitivePermissionAwareModelAdmin):
# 'fields': ('manipulation_profile', )
#}),
)
- def admin_thumbnail(self,xs):
- return mark_safe('<img src="/media/image_filer/icons/plainfolder_32x32.png" alt="Folder Icon" />')
- admin_thumbnail.allow_tags = True
def response_change(self, request, obj):
'''
Overrides the default to be able to forward to the directory listing
instead of the default change_list_view
'''
- r = super(ImageAdmin, self).response_change(request, obj)
+ r = super(ImageFileAdmin, self).response_change(request, obj)
print r['Location']
if r['Location']:
# it was a successful save
@@ -110,7 +107,7 @@ def response_change(self, request, obj):
def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
extra_context = {'show_delete': True}
context.update(extra_context)
- return super(ImageAdmin, self).render_change_form(request=request, context=context, add=False, change=False, form_url=form_url, obj=obj)
+ return super(ImageFileAdmin, self).render_change_form(request=request, context=context, add=False, change=False, form_url=form_url, obj=obj)
def delete_view(self, request, object_id, extra_context=None):
'''
@@ -128,7 +125,7 @@ def delete_view(self, request, object_id, extra_context=None):
except self.model.DoesNotExist:
obj = None
- r = super(ImageAdmin, self).delete_view(request=request, object_id=object_id, extra_context=extra_context)
+ r = super(ImageFileAdmin, self).delete_view(request=request, object_id=object_id, extra_context=extra_context)
url = r.get("Location", None)
if url in ["../../../../","../../"]:
@@ -140,7 +137,7 @@ def delete_view(self, request, object_id, extra_context=None):
return HttpResponseRedirect(url)
return r
-admin.site.register(Image, ImageAdmin)
+admin.site.register([ImageFile], ImageFileAdmin)
class AddFolderPopupForm(forms.ModelForm):
folder = forms.HiddenInput()
View
151 image_filer/models/__init__.py
@@ -96,40 +96,6 @@ class Folder(models.Model):
objects = FolderManager()
-
- def _get_file_relationships(self):
- # TODO: make this a "multi iterator" that can iterate over multiple
- # querysets without having to load all objects
- rel = []
- for attr in dir(self):
- if not attr.startswith('_') and attr.endswith('_files'):
- # TODO: also check for fieldtype
- #print attr
- rel.append(getattr(self, attr))
- return rel
-
- @property
- def file_count(self):
- c = 0
- rel = self._get_file_relationships()
- for files in rel:
- c += files.count()
- return c
- @property
- def children_count(self):
- return self.children.count()
- @property
- def item_count(self):
- return self.file_count + self.children_count
- @property
- def files(self):
- rel = self._get_file_relationships()
- result = []
- for files in rel:
- for file in files.all():
- result.append(file)
- return result
-
def has_edit_permission(self, request):
return self.has_generic_permission(request, 'edit')
def has_read_permission(self, request):
@@ -165,6 +131,26 @@ def has_generic_permission(self, request, type):
def __unicode__(self):
return u"%s" % (self.name,)
+ def __init__(self, *args, **kwargs):
+ class Statistics(object):
+ def __init__(self, instance):
+ self._instance = instance
+
+ @property
+ def file_count(self):
+ c = 0
+ rel = self._instance._get_file_relationships()
+ for files in rel:
+ c += files.count()
+ return c
+ @property
+ def children_count(self):
+ return self._instance.children.count()
+ @property
+ def item_count(self):
+ return self.file_count + self.children_count
+ self.statistics = Statistics(self)
+ return super(Folder, self).__init__(*args, **kwargs)
class Meta:
unique_together = (('parent','name'),)
ordering = ('name',)
@@ -176,6 +162,90 @@ class Meta:
except mptt.AlreadyRegistered:
pass
+
+class File(models.Model):
+ """
+ Represents a "File" thing that is in a Folder.
+ Subclasses should their own overrides for many functions to be more specific,
+ but this class has all the needed methods for basic usage.
+ path: return the full absolute path to the physical file (may be ommited in special cases)
+ file: return a file object
+ """
+ file_type = 'unknown'
+ folder = models.ForeignKey(Folder, related_name='files', null=True, blank=True)
+
+ original_filename = models.CharField(max_length=255, blank=True, null=True)
+ name = models.CharField(max_length=255, null=True, blank=True)
+
+ owner = models.ForeignKey(auth_models.User, related_name='owned_%(class)ss', null=True, blank=True)
+
+ author = models.CharField(max_length=255, null=True, blank=True)
+
+ uploaded_at = models.DateTimeField(auto_now_add=True)
+ modified_at = models.DateTimeField(auto_now=True)
+
+ must_always_publish_author_credit = models.BooleanField(default=False)
+ must_always_publish_copyright = models.BooleanField(default=False)
+
+ notes = models.TextField(null=True, blank=True)
+
+ _file_fallback = models.FileField(upload_to='catalogue', null=True, blank=True)
+
+ @property
+ def icon(self):
+ return "%s/image_filer/icon_file.gif" % settings.MEDIA_URL
+ def has_edit_permission(self, request):
+ return self.has_generic_permission(request, 'edit')
+ def has_read_permission(self, request):
+ return self.has_generic_permission(request, 'read')
+ def has_add_children_permission(self, request):
+ return self.has_generic_permission(request, 'add_children')
+ def has_generic_permission(self, request, type):
+ """
+ Return true if the current user has permission on this
+ image. Return the string 'ALL' if the user has all rights.
+ """
+ user = request.user
+ if not user.is_authenticated() or not user.is_staff:
+ return False
+ elif user.is_superuser:
+ return True
+ elif user == self.owner:
+ return True
+ elif self.folder:
+ return self.folder.has_generic_permission(request, type)
+ else:
+ return False
+ @property
+ def label(self):
+ if self.name in ['',None]:
+ return self.original_filename or 'unnamed file'
+ else:
+ return self.name
+ def __unicode__(self):
+ return self.label
+
+class ImageFile(File):
+ _file = ImageWithThumbnailsField(
+ upload_to='catalogue',
+ #storage=uuid_file_system_storage,
+ height_field='_height_field', width_field='_width_field',
+ thumbnail={'size': (50, 50)},
+ extra_thumbnails={
+ 'admin_clipboard_icon': {'size': (32,32), 'options': ['crop','upscale']},
+ 'admin_sidebar_preview': {'size': (210,210), 'options': ['crop',]},
+ 'admin_directory_listing_icon': {'size': (48,48), 'options': ['crop','upscale']},
+ 'admin_tiny_icon': {'size': (32,32), 'options': ['crop','upscale']},
+ },
+ null=True, blank=True)
+
+ _height_field = models.IntegerField(null=True, blank=True)
+ _width_field = models.IntegerField(null=True, blank=True)
+ date_taken = models.DateTimeField(_('date taken'), null=True, blank=True, editable=False)
+
+ default_alt_text = models.CharField(max_length=255, blank=True, null=True)
+ default_caption = models.CharField(max_length=255, blank=True, null=True)
+
class Image(AbstractFile):
file_type = 'image'
file = ImageWithThumbnailsField(
@@ -194,8 +264,7 @@ class Image(AbstractFile):
_width_field = models.IntegerField(null=True, blank=True)
date_taken = models.DateTimeField(_('date taken'), null=True, blank=True, editable=False)
-
- contact = models.ForeignKey(auth_models.User, related_name='contact_of_files', null=True, blank=True)
+
default_alt_text = models.CharField(max_length=255, blank=True, null=True)
default_caption = models.CharField(max_length=255, blank=True, null=True)
@@ -205,16 +274,6 @@ class Image(AbstractFile):
must_always_publish_author_credit = models.BooleanField(default=False)
must_always_publish_copyright = models.BooleanField(default=False)
- # TODO: Factor out customer specific fields... maybe a m2m?
- can_use_for_web = models.BooleanField(default=True)
- can_use_for_print = models.BooleanField(default=True)
- can_use_for_teaching = models.BooleanField(default=True)
- can_use_for_research = models.BooleanField(default=True)
- can_use_for_private_use = models.BooleanField(default=True)
-
- usage_restriction_notes = models.TextField(null=True, blank=True)
- notes = models.TextField(null=True, blank=True)
-
has_all_mandatory_data = models.BooleanField(default=False, editable=False)
def _check_validity(self):
View
43 image_filer/templates/admin/image_filer/app_index.html
@@ -1,43 +0,0 @@
-{% extends "admin/app_index.html" %}
-{% load i18n %}
-
-{% block content %}
-<div id="content-main">
-
-{% if app_list %}
- {% for app in app_list %}
- <div class="module">
- <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}">
- <caption><a href="{{ app.app_url }}" class="section">{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</a></caption>
- {% for model in app.models %}
- <tr>
- {% if model.perms.change %}
- <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
- {% else %}
- <th scope="row">{{ model.name }}</th>
- {% endif %}
-
- {% if model.perms.add %}
- <td><a href="{{ model.admin_url }}add/" class="addlink">{% trans 'Add' %}</a></td>
- {% else %}
- <td>&nbsp;</td>
- {% endif %}
-
- {% if model.perms.change %}
- <td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
- {% else %}
- <td>&nbsp;</td>
- {% endif %}
- </tr>
- {% endfor %}
- </table>
- </div>
- {% endfor %}
-{% else %}
- <p>{% trans "You don't have permission to edit anything." %}</p>
-{% endif %}
-</div>
-{% endblock %}
-
-{% block sidebar %}
-{% endblock %}
View
2 image_filer/views.py
@@ -249,7 +249,7 @@ def ajax_upload(request, folder_id=None):
#sprint image
else:
pass#print imageform.errors
-
+ print "going to respond"
return render_to_response('image_filer/include/clipboard_item_rows.html', {'items': file_items }, context_instance=RequestContext(request))
@login_required

0 comments on commit de67847

Please sign in to comment.