Skip to content

Commit

Permalink
Merge tag '3.5.5'
Browse files Browse the repository at this point in the history
version 3.5.5
  • Loading branch information
smacker committed Aug 15, 2014
2 parents 72109bb + 5147880 commit 6de55ac
Show file tree
Hide file tree
Showing 22 changed files with 151 additions and 97 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ https://www.transifex.com/projects/p/django-filebrowser/
Releases
--------

* FileBrowser 3.5.5 (Development Version, not yet released, see Branch Stable/3.5.x)
* FileBrowser 3.5.4 (February 21st, 2014): Compatible with Django 1.4/1.5/1.6
* FileBrowser 3.5.6 (Development Version, not yet released, see Branch Stable/3.5.x)
* FileBrowser 3.5.5 (April 13th, 2014): Compatible with Django 1.4/1.5/1.6

Older versions are availabe at GitHub, but are not supported anymore.
8 changes: 4 additions & 4 deletions docs/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FileBrowser Site

.. py:class:: FileBrowserSite(name=None, app_name='filebrowser', storage=default_storage)
Respresens the FileBrowser admin application (similar to Django's admin site).
Respresents the FileBrowser admin application (similar to Django's admin site).

:param name: A name for the site, defaults to None.
:param app_name: Defaults to 'filebrowser'.
Expand All @@ -41,7 +41,7 @@ Now you are able to browse the location defined with the storage engine associat
.. code-block:: python
from django.core.files.storage import DefaultStorage
from filebrowser.sites import import FileBrowserSite
from filebrowser.sites import FileBrowserSite
# Default FileBrowser site
site = FileBrowserSite(name='filebrowser', storage=DefaultStorage())
Expand Down Expand Up @@ -182,7 +182,7 @@ All views use the ``staff_member_requird`` and ``path_exists`` decorator in orde
* Upload, ``fb_upload``
Multiple upload.

* Optional query string args: ``dir``
* Optional query string args: ``dir``, ``type``
* Signals: `filebrowser_pre_upload`, `filebrowser_post_upload`

* Edit, ``fb_edit``
Expand Down Expand Up @@ -285,4 +285,4 @@ Here's a small example for using the above Signals::
print "Filesize:", kwargs['file'].filesize
print "Orientation:", kwargs['file'].orientation
print "Extension:", kwargs['file'].extension
signals.filebrowser_post_upload.connect(post_upload_callback)
signals.filebrowser_post_upload.connect(post_upload_callback)
17 changes: 11 additions & 6 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
Changelog
=========

3.5.5 (not yet released)
3.5.6 (not yet released)
------------------------

* Improved tests with convert/normalize (removed special chars from test filename).
* Fixed file selection after using search box (CKEditor).
* Removed encoding of file URIs with CKEditor.
3.5.5 (April 13th, 2014)
------------------------

* New: Added client-side (JavaScript) file extension validation to the AJAX uploader.
* New: Added experimental Python 3.3 support.
* Improved: Tests with convert/normalize (removed special chars from test filename).
* Fixed: File selection after using search box (CKEditor).
* Fixed: Removed encoding of file URIs with CKEditor.

3.5.4 (February 21st, 2014)
---------------------------
Expand Down Expand Up @@ -87,7 +92,7 @@ Changelog
-----------------

* Fixed security bug: added staff_member_required decorator to the upload-function.
* Fixed a XSS vulnerability with fb_tags.
* Fixed a XSS vulnerability with fb_tags.

3.4.1 (7.3.2012)
----------------
Expand All @@ -108,4 +113,4 @@ Changelog
3.4.0 (15/11/2011)
------------------

* Final release of 3.4, see :ref:`releasenotes`
* Final release of 3.4, see :ref:`releasenotes`
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Use the `FileBrowser Google Group <http://groups.google.com/group/django-filebro
Versions and Compatibility
--------------------------

* FileBrowser 3.5.5 (Development Version, not yet released, see Branch Stable/3.5.x)
* FileBrowser 3.5.4 (February 21st, 2014): Compatible with Django 1.4/1.5/1.6
* FileBrowser 3.5.6 (Development Version, not yet released, see Branch Stable/3.5.x)
* FileBrowser 3.5.5 (April 13th, 2014): Compatible with Django 1.4/1.5/1.6

Older versions are availabe at GitHub, but are not supported anymore.
16 changes: 7 additions & 9 deletions filebrowser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# FILEBROWSER IMPORTS
from filebrowser.settings import EXTENSIONS, VERSIONS, ADMIN_VERSIONS, VERSIONS_BASEDIR, VERSION_QUALITY, PLACEHOLDER, FORCE_PLACEHOLDER, SHOW_PLACEHOLDER, STRICT_PIL, IMAGE_MAXBLOCK
from filebrowser.utils import path_strip, scale_and_crop
from django.utils.encoding import smart_str, smart_text
from django.utils.encoding import python_2_unicode_compatible, smart_str

# PIL import
if STRICT_PIL:
Expand Down Expand Up @@ -86,7 +86,7 @@ def sort_by_attr(self, seq, attr):
# only to provide stable sorting, but mainly to eliminate comparison of objects
# (which can be expensive or prohibited) in case of equal attribute values.
intermed = sorted(zip(map(getattr, seq, (attr,)*len(seq)), range(len(seq)), seq))
return map(operator.getitem, intermed, (-1,) * len(intermed))
return list(map(operator.getitem, intermed, (-1,) * len(intermed)))

_is_folder_stored = None
@property
Expand Down Expand Up @@ -165,7 +165,7 @@ def files_walk_total(self):
def files_listing_filtered(self):
"Returns FileObjects for filtered files in listing"
if self.filter_func:
listing = filter(self.filter_func, self.files_listing_total())
listing = list(filter(self.filter_func, self.files_listing_total()))
else:
listing = self.files_listing_total()
self._results_listing_filtered = len(listing)
Expand All @@ -174,7 +174,7 @@ def files_listing_filtered(self):
def files_walk_filtered(self):
"Returns FileObjects for filtered files in walk"
if self.filter_func:
listing = filter(self.filter_func, self.files_walk_total())
listing = list(filter(self.filter_func, self.files_walk_total()))
else:
listing = self.files_walk_total()
self._results_walk_filtered = len(listing)
Expand Down Expand Up @@ -205,6 +205,7 @@ def results_walk_filtered(self):
return len(self.files_walk_filtered())


@python_2_unicode_compatible
class FileObject():
"""
The FileObject represents a file (or directory) on the server.
Expand Down Expand Up @@ -235,9 +236,6 @@ def __init__(self, path, site=None):
def __str__(self):
return smart_str(self.path)

def __unicode__(self):
return smart_text(self.path)

@property
def name(self):
return self.path
Expand All @@ -254,7 +252,7 @@ def __len__(self):
def _get_file_type(self):
"Get file type as defined in EXTENSIONS."
file_type = ''
for k, v in EXTENSIONS.iteritems():
for k, v in EXTENSIONS.items():
for extension in v:
if self.extension.lower() == extension.lower():
file_type = k
Expand Down Expand Up @@ -482,7 +480,7 @@ def versions(self):
"List of versions (not checking if they actually exist)"
version_list = []
if self.filetype == "Image" and not self.is_version:
for version in VERSIONS:
for version in sorted(VERSIONS):
version_list.append(os.path.join(self.versions_basedir, self.dirname, self.version_name(version)))
return version_list

Expand Down
2 changes: 1 addition & 1 deletion filebrowser/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def path_exists(site, function):
def decorator(request, *args, **kwargs):
if get_path('', site=site) is None:
# The storage location does not exist, raise an error to prevent eternal redirecting.
raise ImproperlyConfigured, _("Error finding Upload-Folder (site.storage.location + site.directory). Maybe it does not exist?")
raise ImproperlyConfigured(_("Error finding Upload-Folder (site.storage.location + site.directory). Maybe it does not exist?"))
if get_path(request.GET.get('dir', ''), site=site) is None:
msg = _('The requested Folder does not exist.')
messages.add_message(request, messages.ERROR, msg)
Expand Down
4 changes: 2 additions & 2 deletions filebrowser/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django import forms
from django.forms.widgets import Input
from django.template.loader import render_to_string
from django.utils.six import with_metaclass
from django.utils.translation import ugettext_lazy as _

# FILEBROWSER IMPORTS
Expand Down Expand Up @@ -83,9 +84,8 @@ def clean(self, value):
return value


class FileBrowseField(CharField):
class FileBrowseField(with_metaclass(models.SubfieldBase, CharField)):
description = "FileBrowseField"
__metaclass__ = models.SubfieldBase

def __init__(self, *args, **kwargs):
self.site = kwargs.pop('filebrowser_site', site)
Expand Down
5 changes: 3 additions & 2 deletions filebrowser/management/commands/fb_version_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# DJANGO IMPORTS
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.utils.six.moves import input

# FILEBROWSER IMPORTS
from filebrowser.settings import EXTENSION_LIST, EXCLUDE, DIRECTORY, VERSIONS, EXTENSIONS
Expand All @@ -16,7 +17,7 @@
filter_re = []
for exp in EXCLUDE:
filter_re.append(re.compile(exp))
for k, v in VERSIONS.iteritems():
for k, v in VERSIONS.items():
exp = (r'_%s(%s)') % (k, '|'.join(EXTENSION_LIST))
filter_re.append(re.compile(exp))

Expand All @@ -43,7 +44,7 @@ def handle(self, *args, **options):
for version in VERSIONS:
self.stdout.write(' * %s\n' % version)

version_name = raw_input('(leave blank to generate all versions): ')
version_name = input('(leave blank to generate all versions): ')

if version_name == "":
selected_version = None
Expand Down
7 changes: 4 additions & 3 deletions filebrowser/management/commands/fb_version_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# DJANGO IMPORTS
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.utils.six.moves import input

# FILEBROWSER IMPORTS
from filebrowser.settings import EXTENSION_LIST, EXCLUDE, DIRECTORY, VERSIONS, EXTENSIONS
Expand Down Expand Up @@ -36,7 +37,7 @@ def handle(self, *args, **options):
while 1:
self.stdout.write('\nOlder versions of the FileBrowser used to prefix the filename with the version name.\n')
self.stdout.write('Current version of the FileBrowser adds the version name as suffix.\n')
prefix_or_suffix = raw_input('"p" for prefix or "s" for suffix (leave blank for "%s"): ' % default_prefix_or_suffix)
prefix_or_suffix = input('"p" for prefix or "s" for suffix (leave blank for "%s"): ' % default_prefix_or_suffix)

if default_prefix_or_suffix and prefix_or_suffix == '':
prefix_or_suffix = default_prefix_or_suffix
Expand All @@ -48,7 +49,7 @@ def handle(self, *args, **options):

# get version name
while 1:
version_name = raw_input('\nversion name as defined with VERSIONS: ')
version_name = input('\nversion name as defined with VERSIONS: ')

if version_name == "":
self.stderr.write('Error: You have to enter a version name.\n')
Expand Down Expand Up @@ -84,7 +85,7 @@ def handle(self, *args, **options):
# ask to make sure
do_remove = ""
self.stdout.write('Are Sure you want to delete these files?\n')
do_remove = raw_input('"y" for Yes or "n" for No (leave blank for "n"): ')
do_remove = input('"y" for Yes or "n" for No (leave blank for "n"): ')

# if "yes" we delete. any different case we finish without removing anything
if do_remove == "y":
Expand Down
2 changes: 1 addition & 1 deletion filebrowser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# Traverse directories when searching
SEARCH_TRAVERSE = getattr(settings, "FILEBROWSER_SEARCH_TRAVERSE", False)
# Default Upload and Version Permissions
DEFAULT_PERMISSIONS = getattr(settings, "FILEBROWSER_DEFAULT_PERMISSIONS", 0755)
DEFAULT_PERMISSIONS = getattr(settings, "FILEBROWSER_DEFAULT_PERMISSIONS", 0o755)
# Overwrite existing files on upload
OVERWRITE_EXISTING = getattr(settings, "FILEBROWSER_OVERWRITE_EXISTING", True)

Expand Down
17 changes: 9 additions & 8 deletions filebrowser/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_site_dict(app_name='filebrowser'):
# Get names of all deployed filebrowser sites with a give app_name
deployed = get_resolver(get_urlconf()).app_dict[app_name]
# Get the deployed subset from the cache
return dict((k, v) for k, v in _sites_cache[app_name].iteritems() if k in deployed)
return dict((k, v) for k, v in _sites_cache[app_name].items() if k in deployed)


def register_site(app_name, site_name, site):
Expand Down Expand Up @@ -165,7 +165,7 @@ def handle_file_upload(path, file, site):
try:
file_path = os.path.join(path, file.name)
uploadedfile = site.storage.save(file_path, file)
except Exception, inst:
except Exception as inst:
raise inst
return uploadedfile

Expand Down Expand Up @@ -269,7 +269,7 @@ def actions(self):
Get all the enabled actions as a list of (name, func). The list
is sorted alphabetically by actions names
"""
res = self._actions.items()
res = list(self._actions.items())
res.sort(key=lambda name_func: name_func[0])
return res

Expand All @@ -283,7 +283,7 @@ def browse(self, request):
filter_re = []
for exp in EXCLUDE:
filter_re.append(re.compile(exp))
for k, v in VERSIONS.iteritems():
for k, v in VERSIONS.items():
exp = (r'_%s(%s)$') % (k, '|'.join(EXTENSION_LIST))
filter_re.append(re.compile(exp, re.IGNORECASE))

Expand Down Expand Up @@ -373,7 +373,8 @@ def createdir(self, request):
messages.add_message(request, messages.SUCCESS, _('The Folder %s was successfully created.') % form.cleaned_data['name'])
redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "ot=desc,o=date", "ot,o,filter_type,filter_date,q,p")
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
except OSError as e:
errno = e.args[0]
if errno == 13:
form.errors['name'] = forms.util.ErrorList([_('Permission denied.')])
else:
Expand Down Expand Up @@ -453,7 +454,7 @@ def delete(self, request):
fileobject.delete()
signals.filebrowser_post_delete.send(sender=request, path=fileobject.path, name=fileobject.filename, site=self)
messages.add_message(request, messages.SUCCESS, _('Successfully deleted %s') % fileobject.filename)
except OSError, (errno, strerror):
except OSError:
# TODO: define error-message
pass
redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "", "filename,filetype")
Expand Down Expand Up @@ -497,7 +498,7 @@ def detail(self, request):
else:
redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "", "filename")
return HttpResponseRedirect(redirect_url)
except OSError, (errno, strerror):
except OSError:
form.errors['name'] = forms.util.ErrorList([_('Error.')])
else:
form = ChangeForm(initial={"name": fileobject.filename}, path=path, fileobject=fileobject, filebrowser_site=self)
Expand Down Expand Up @@ -542,7 +543,7 @@ def _upload_file(self, request):
if len(request.FILES) > 1:
return HttpResponseBadRequest('Invalid request! Multiple files included.')

filedata = request.FILES.values()[0]
filedata = list(request.FILES.values())[0]

fb_uploadurl_re = re.compile(r'^.*(%s)' % reverse("filebrowser:fb_upload", current_app=self.name))
folder = fb_uploadurl_re.sub('', folder)
Expand Down
4 changes: 2 additions & 2 deletions filebrowser/static/filebrowser/js/fileuploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ qq.FileUploaderBasic.prototype = {
return name;
},
_isAllowedExtension: function(fileName){
var ext = (-1 !== fileName.indexOf('.')) ? fileName.replace(/.*[.]/, '').toLowerCase() : '';
var ext = (-1 !== fileName.indexOf('.')) ? fileName.substr(fileName.lastIndexOf('.')).toLowerCase() : '';
var allowed = this._options.allowedExtensions;

if (!allowed.length){return true;}
Expand Down Expand Up @@ -1247,4 +1247,4 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
this._xhrs[id] = null;
}
}
});
});
1 change: 1 addition & 0 deletions filebrowser/templates/filebrowser/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'csrf_xname': 'X-CSRFToken',
'folder': '{{ query.dir|escapejs }}', },

allowedExtensions: {% get_file_extensions request.GET %},
sizeLimit: {{ settings_var.MAX_UPLOAD_SIZE|unlocalize }},
minSizeLimit: 0,
debug: false,
Expand Down
Loading

0 comments on commit 6de55ac

Please sign in to comment.