Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

minor code-cleanup (esp. import-comments)

  • Loading branch information...
commit 4ee98bf15c2d7f91a0d4c705904601b0cdbc38f1 1 parent 67039d8
Patrick Kranzlmueller authored
16 filebrowser/actions.py
View
@@ -1,16 +1,15 @@
# coding: utf-8
-##
-##
-##
-
+# PYTHON IMPORTS
from tempfile import NamedTemporaryFile
+# DJANGO IMPORTS
from django.utils.translation import ugettext as _
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.core.files import File
+# FILEBROWSER IMPORTS
from filebrowser.settings import *
# PIL import
@@ -22,9 +21,11 @@
except ImportError:
import Image
+
def applies_to_all_images(fileobject):
return fileobject.filetype == 'Image'
+
def transpose_image(request, fileobjects, operation):
for fileobject in fileobjects:
root, ext = os.path.splitext(fileobject.filename)
@@ -55,22 +56,27 @@ def flip_horizontal(request, fileobjects):
flip_horizontal.short_description = _(u'Flip horizontal')
flip_horizontal.applies_to = applies_to_all_images
+
def flip_vertical(request, fileobjects):
transpose_image(request, fileobjects, 1)
flip_vertical.short_description = _(u'Flip vertical')
flip_vertical.applies_to = applies_to_all_images
+
def rotate_90_clockwise(request, fileobjects):
transpose_image(request, fileobjects, 4)
rotate_90_clockwise.short_description = _(u'Rotate 90° CW')
rotate_90_clockwise.applies_to = applies_to_all_images
+
def rotate_90_counterclockwise(request, fileobjects):
transpose_image(request, fileobjects, 2)
rotate_90_counterclockwise.short_description = _(u'Rotate 90° CCW')
rotate_90_counterclockwise.applies_to = applies_to_all_images
+
def rotate_180(request, fileobjects):
transpose_image(request, fileobjects, 3)
rotate_180.short_description = _(u'Rotate 180°')
-rotate_180.applies_to = applies_to_all_images
+rotate_180.applies_to = applies_to_all_images
+
8 filebrowser/base.py
View
@@ -1,13 +1,13 @@
# coding: utf-8
-# imports
+# PYTHON IMPORTS
import os, shutil, re, datetime, time
import mimetypes
-# django imports
+# DJANGO IMPORTS
from django.utils.translation import ugettext as _
-# filebrowser imports
+# FILEBROWSER IMPORTS
from filebrowser.settings import *
from filebrowser.functions import get_file_type, url_join, get_version_path, get_original_path, sort_by_attr, version_generator, path_strip, url_strip
from django.utils.encoding import smart_str, smart_unicode
@@ -21,6 +21,7 @@
except ImportError:
import Image
+
class FileListing():
"""
The FileListing represents a group of FileObjects/FileDirObjects.
@@ -162,6 +163,7 @@ def results_walk_filtered(self):
return self._results_walk_filtered
return len(self.files_walk_filtered())
+
class FileObject():
"""
The FileObject represents a file (or directory) on the server.
4 filebrowser/decorators.py
View
@@ -1,13 +1,13 @@
# coding: utf-8
-# django imports
+# DJANGO IMPORTS
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from django.contrib import messages
from django.core.exceptions import ImproperlyConfigured
-# filebrowser imports
+# FILEBROWSER IMPORTS
from filebrowser.functions import get_path, get_file
from filebrowser.templatetags.fb_tags import query_helper
4 filebrowser/fields.py
View
@@ -18,6 +18,7 @@
from filebrowser.base import FileObject
from filebrowser.sites import site
+
class FileBrowseWidget(Input):
input_type = 'text'
@@ -127,8 +128,11 @@ def formfield(self, **kwargs):
}
return super(FileBrowseField, self).formfield(**defaults)
+
try:
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^filebrowser\.fields\.FileBrowseField"])
except:
pass
+
+
10 filebrowser/forms.py
View
@@ -1,19 +1,20 @@
# coding: utf-8
-# imports
+# PYTHON IMPORTS
import re, os
-# django imports
+# DJANGO IMPORTS
from django import forms
from django.forms.formsets import BaseFormSet
from django.utils.translation import ugettext as _
-# filebrowser imports
+# FILEBROWSER IMPORTS
from filebrowser.settings import MAX_UPLOAD_SIZE, FOLDER_REGEX
from filebrowser.functions import convert_filename
alnum_name_re = re.compile(FOLDER_REGEX, re.U)
+
# CHOICES
TRANSPOSE_CHOICES = (
("", u"-----"),
@@ -47,6 +48,7 @@ def clean_name(self):
raise forms.ValidationError(_(u'The Folder already exists.'))
return convert_filename(self.cleaned_data['name'])
+
class ChangeForm(forms.Form):
"""
Form for renaming a file/folder.
@@ -81,3 +83,5 @@ def clean_name(self):
elif self.site.storage.isfile(os.path.join(self.path, convert_filename(self.cleaned_data['name']))) and os.path.join(self.path, convert_filename(self.cleaned_data['name'])) != self.fileobject.path:
raise forms.ValidationError(_(u'The File already exists.'))
return convert_filename(self.cleaned_data['name'])
+
+
12 filebrowser/sites.py
View
@@ -1,10 +1,10 @@
# coding: utf-8
-# general imports
+# PYTHON IMPORTS
import os, re
from types import MethodType
-# django imports
+# DJANGO IMPORTS
from django.shortcuts import render_to_response, HttpResponse
from django.template import RequestContext as Context
from django.http import HttpResponseRedirect
@@ -22,7 +22,7 @@
from django.core.files.storage import default_storage, FileSystemStorage
from django.core.exceptions import ImproperlyConfigured
-# filebrowser imports
+# FILEBROWSER IMPORTS
from filebrowser.settings import *
from filebrowser.functions import get_breadcrumbs, get_filterdate, get_settings_var, handle_file_upload, convert_filename
from filebrowser.templatetags.fb_tags import query_helper
@@ -51,6 +51,7 @@
# This cache contains all *instantiated* FileBrowser sites
_sites_cache = {}
+
def get_site_dict(app_name='filebrowser'):
"""
Return a dict with all *deployed* FileBrowser sites that have
@@ -63,6 +64,7 @@ def get_site_dict(app_name='filebrowser'):
# Get the deployed subset from the cache
return dict((k,v) for k, v in _sites_cache[app_name].iteritems() if k in deployed)
+
def register_site(app_name, site_name, site):
"""
Add a site into the site dict.
@@ -71,6 +73,7 @@ def register_site(app_name, site_name, site):
_sites_cache[app_name] = {}
_sites_cache[app_name][site_name] = site
+
class FileBrowserSite(object):
def __init__(self, name=None, app_name='filebrowser', storage=default_storage):
@@ -99,7 +102,6 @@ def _directory_set(self, val):
directory = property(_directory_get, _directory_set)
-
def filebrowser_view(self, view):
return staff_member_required(never_cache(view))
@@ -511,3 +513,5 @@ def _upload_file(self, request):
site.add_action(rotate_90_clockwise)
site.add_action(rotate_90_counterclockwise)
site.add_action(rotate_180)
+
+
5 filebrowser/storage.py
View
@@ -1,10 +1,14 @@
# coding: utf-8
+
+# PYTHON IMPORTS
import os, shutil
+# DJANGO IMPORTS
from django.core.files.move import file_move_safe
from django.core.files.storage import FileSystemStorage, DefaultStorage
from django.core.files.base import ContentFile
+
class StorageMixin(object):
"""
Adds some useful methods to the Storage class.
@@ -48,6 +52,7 @@ def rmtree(self, name):
"""
raise NotImplementedError()
+
class FileSystemStorageMixin(StorageMixin):
def isdir(self, name):
5 filebrowser/templatetags/fb_csrf.py
View
@@ -1,10 +1,9 @@
# coding: utf-8
-# django imports
+# DJANGO IMPORTS
from django.template import Node
from django.template import Library
from django.utils.safestring import mark_safe
-
register = Library()
@@ -28,3 +27,5 @@ def render(self, context):
def fb_csrf_token(parser, token):
return CsrfTokenNode()
register.tag(fb_csrf_token)
+
+
4 filebrowser/templatetags/fb_pagination.py
View
@@ -1,13 +1,14 @@
# coding: utf-8
+# DJANGO IMPORTS
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.template import Library
register = Library()
-
DOT = '.'
+
@register.inclusion_tag('filebrowser/include/paginator.html', takes_context=True)
def pagination(context):
page_num = context['page'].number-1
@@ -49,3 +50,4 @@ def pagination(context):
}
+
6 filebrowser/templatetags/fb_tags.py
View
@@ -1,12 +1,12 @@
# coding: utf-8
-# django imports
+# DJANGO IMPORTS
from django import template
from django.utils.encoding import smart_unicode
from django.utils.safestring import mark_safe
from django.utils.http import urlquote
-# filebrowser imports
+# FILEBROWSER IMPORTS
from filebrowser.settings import SELECT_FORMATS
register = template.Library()
@@ -139,3 +139,5 @@ def selectable(parser, token):
return SelectableNode(filetype, format)
register.tag(selectable)
+
+
7 filebrowser/templatetags/fb_versions.py
View
@@ -1,15 +1,15 @@
# coding: utf-8
-# imports
+# PYTHON IMPORTS
import os, re
from time import gmtime
-# django imports
+# DJANGO IMPORTS
from django.template import Library, Node, Variable, VariableDoesNotExist, TemplateSyntaxError
from django.conf import settings
from django.utils.encoding import force_unicode, smart_str
-# filebrowser imports
+# FILEBROWSER IMPORTS
from filebrowser.settings import DIRECTORY, VERSIONS
from filebrowser.functions import get_version_path, version_generator
from filebrowser.base import FileObject
@@ -177,4 +177,3 @@ def version_setting(parser, token):
register.tag(version_object)
register.tag(version_setting)
-
2  filebrowser/tests/base.py
View
@@ -10,7 +10,7 @@
from django.contrib.auth.models import User
from django.utils.encoding import filepath_to_uri
-# PYTHON IMPORTS
+# FILEBROWSER IMPORTS
from filebrowser.settings import *
import filebrowser
from filebrowser.base import FileObject
2  filebrowser/tests/settings.py
View
@@ -7,7 +7,7 @@
from django.test import TestCase
from django.contrib.auth.models import User
-# PYTHON IMPORTS
+# FILEBROWSER IMPORTS
from filebrowser.settings import *
6 filebrowser/tests/sites.py
View
@@ -8,19 +8,19 @@
instance methods from functions.
"""
-# Python imports
+# PYTHON IMPORTS
import os
import sys
import shutil
from urllib import urlencode
from types import MethodType
-# Django imports
+# DJANGO IMPORTS
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import get_resolver, get_urlconf, resolve, reverse
-# FileBrowser imports
+# FILEBROWSER IMPORTS
from filebrowser.settings import *
from filebrowser.base import FileObject
from filebrowser.sites import get_site_dict
Please sign in to comment.
Something went wrong with that request. Please try again.