Skip to content

Commit

Permalink
Merge branch 'upstream' (WARNING: still needs work) into merge-filebr…
Browse files Browse the repository at this point in the history
…owser-3-1

Conflicts:
	filebrowser/templates/filebrowser/index.html
  • Loading branch information
wardi committed Jun 19, 2010
2 parents 9ca0b36 + 88aecc3 commit 80eec43
Show file tree
Hide file tree
Showing 30 changed files with 681 additions and 479 deletions.
2 changes: 1 addition & 1 deletion filebrowser/LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2009, Patrick Kranzlmueller (vonautomatisch werkstaetten),
Copyright (c) 2010, Patrick Kranzlmueller (vonautomatisch werkstaetten),
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
16 changes: 9 additions & 7 deletions filebrowser/base.py
Expand Up @@ -10,6 +10,7 @@
# filebrowser imports
from filebrowser.settings import *
from filebrowser.functions import get_file_type, url_join, is_selectable, get_version_path
from django.utils.encoding import force_unicode

# PIL import
if STRICT_PIL:
Expand Down Expand Up @@ -40,8 +41,9 @@ def _filesize(self):
"""
Filesize.
"""
if os.path.isfile(os.path.join(MEDIA_ROOT, self.path)) or os.path.isdir(os.path.join(MEDIA_ROOT, self.path)):
return os.path.getsize(os.path.join(MEDIA_ROOT, self.path))
path = force_unicode(self.path)
if os.path.isfile(os.path.join(MEDIA_ROOT, path)) or os.path.isdir(os.path.join(MEDIA_ROOT, path)):
return os.path.getsize(os.path.join(MEDIA_ROOT, path))
return ""
filesize = property(_filesize)

Expand Down Expand Up @@ -81,7 +83,7 @@ def _path_full(self):
"""
Full server PATH including MEDIA_ROOT.
"""
return u"%s" % os.path.join(MEDIA_ROOT, self.path)
return os.path.join(MEDIA_ROOT, self.path)
path_full = property(_path_full)

def _path_relative(self):
Expand All @@ -105,7 +107,7 @@ def _url_full(self):
"""
Full URL including MEDIA_URL.
"""
return u"%s" % url_join(MEDIA_URL, self.url_rel)
return force_unicode(url_join(MEDIA_URL, self.url_rel))
url_full = property(_url_full)

def _url_save(self):
Expand Down Expand Up @@ -191,12 +193,12 @@ def _is_empty(self):
is_empty = property(_is_empty)

def __repr__(self):
return u"%s" % self.url_save
return force_unicode(self.url_save)

def __str__(self):
return u"%s" % self.url_save
return force_unicode(self.url_save)

def __unicode__(self):
return u"%s" % self.url_save
return force_unicode(self.url_save)


6 changes: 5 additions & 1 deletion filebrowser/fields.py
Expand Up @@ -120,4 +120,8 @@ def formfield(self, **kwargs):
defaults.update(kwargs)
return super(FileBrowseField, self).formfield(**defaults)


try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^filebrowser\.fields\.FileBrowseField"])
except:
pass
16 changes: 10 additions & 6 deletions filebrowser/functions.py
Expand Up @@ -10,6 +10,7 @@
from django.utils.safestring import mark_safe
from django.core.files import File
from django.core.files.storage import default_storage
from django.utils.encoding import smart_str

# filebrowser imports
from filebrowser.settings import *
Expand Down Expand Up @@ -73,7 +74,7 @@ def get_version_path(value, version_prefix):
Returns a path relative to MEDIA_ROOT.
"""

if os.path.isfile(os.path.join(MEDIA_ROOT, value)):
if os.path.isfile(smart_str(os.path.join(MEDIA_ROOT, value))):
path, filename = os.path.split(value)
filename, ext = os.path.splitext(filename)

Expand All @@ -85,7 +86,7 @@ def get_version_path(value, version_prefix):
# so we strip the suffix (aka. version_perfix)
new_filename = filename.replace("_" + tmp[len(tmp)-1], "")
# check if the version exists when we use the new_filename
if os.path.isfile(os.path.join(MEDIA_ROOT, path, new_filename + "_" + version_prefix + ext)):
if os.path.isfile(smart_str(os.path.join(MEDIA_ROOT, path, new_filename + "_" + version_prefix + ext))):
# our "original" filename seem to be filename_<version> construct
# so we replace it with the new_filename
filename = new_filename
Expand Down Expand Up @@ -133,7 +134,7 @@ def url_join(*args):
else:
url = "/"
for arg in args:
arg = unicode(arg).replace("\\", "/")
arg = arg.replace("\\", "/")
arg_split = arg.split("/")
for elem in arg_split:
if elem != "" and elem != "http:":
Expand All @@ -159,7 +160,9 @@ def get_file(path, filename):
Get File.
"""

if not os.path.isfile(os.path.join(MEDIA_ROOT, DIRECTORY, path, filename)) and not os.path.isdir(os.path.join(MEDIA_ROOT, DIRECTORY, path, filename)):
converted_path = smart_str(os.path.join(MEDIA_ROOT, DIRECTORY, path, filename))

if not os.path.isfile(converted_path) and not os.path.isdir(converted_path):
return None
return filename

Expand Down Expand Up @@ -220,6 +223,7 @@ def get_settings_var():
settings_var['VERSIONS'] = VERSIONS
settings_var['ADMIN_VERSIONS'] = ADMIN_VERSIONS
settings_var['ADMIN_THUMBNAIL'] = ADMIN_THUMBNAIL
settings_var['PREVIEW_VERSION'] = PREVIEW_VERSION
# FileBrowser Options
settings_var['MAX_UPLOAD_SIZE'] = MAX_UPLOAD_SIZE
# Convert Filenames
Expand Down Expand Up @@ -283,9 +287,9 @@ def version_generator(value, version_prefix, force=None):
ImageFile.MAXBLOCK = IMAGE_MAXBLOCK # default is 64k

try:
im = Image.open(os.path.join(MEDIA_ROOT, value))
im = Image.open(smart_str(os.path.join(MEDIA_ROOT, value)))
version_path = get_version_path(value, version_prefix)
absolute_version_path = os.path.join(MEDIA_ROOT, version_path)
absolute_version_path = smart_str(os.path.join(MEDIA_ROOT, version_path))
version_dir = os.path.split(absolute_version_path)[0]
if not os.path.isdir(version_dir):
os.makedirs(version_dir)
Expand Down
Binary file modified filebrowser/locale/de/LC_MESSAGES/django.mo
Binary file not shown.

0 comments on commit 80eec43

Please sign in to comment.