diff options
author | therazer <devnull@localhost> | 2010-11-09 21:30:54 +0100 |
---|---|---|
committer | therazer <devnull@localhost> | 2010-11-09 21:30:54 +0100 |
commit | fa078c84b81f891aa800ca602fbc7d7ec3d02753 (patch) | |
tree | 8431575a6a27dab13700b538ccc4e94cba2e9c87 /module/web/pyload | |
parent | account reloadData fix (diff) | |
download | pyload-fa078c84b81f891aa800ca602fbc7d7ec3d02753.tar.xz |
added browser for files, too + little patches
Diffstat (limited to 'module/web/pyload')
-rw-r--r-- | module/web/pyload/urls.py | 6 | ||||
-rw-r--r-- | module/web/pyload/views.py | 33 |
2 files changed, 25 insertions, 14 deletions
diff --git a/module/web/pyload/urls.py b/module/web/pyload/urls.py index 6523d711a..fe85c1096 100644 --- a/module/web/pyload/urls.py +++ b/module/web/pyload/urls.py @@ -17,8 +17,10 @@ urlpatterns = patterns('pyload', (r'^logs/(?P<item>\d+)$', 'views.logs',{}, 'logs'), (r'^package_ui.js$', 'views.package_ui', {}, 'package_ui'), (r'^$', 'views.home',{}, 'home'), - url(r'^pathchooser/(?P<path>.*)', 'views.path', name='path'), - url(r'^pathchooser/$', 'views.root', name='root'), + url(r'^pathchooser/(?P<path>.*)', 'views.path', {'type':'folder'}, name='path'), + url(r'^pathchooser/$', 'views.root', {'type':'folder'}, name='pathroot'), + url(r'^filechooser/(?P<path>.*)', 'views.path', {'type':'file'}, name='file'), + url(r'^filechooser/$', 'views.root', {'type':'file'}, name='fileroot'), ) urlpatterns += patterns('django.contrib.auth', diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index a9d3830ed..09bb72704 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -379,21 +379,26 @@ def package_ui(request): @login_required @permission('pyload.can_change_status') @check_server -def root(request): +def root(request, type): cwd = os.getcwd() - return HttpResponseRedirect(reverse('path', args=[cwd[1:]])) + return HttpResponseRedirect(reverse('path', args=[cwd[1:], type])) @login_required @permission('pyload.can_change_status') @check_server -def path(request, path): +def path(request, path, type): - files = [] + if os.path.isfile(path): + oldfile = path + path = os.path.dirname(path) + else: + oldfile = '' + if os.path.isdir(path): cwd = path else: cwd = os.getcwd() - + if cwd[-1] == '/': parentdir = os.path.split(cwd[:-1])[0] else: @@ -403,19 +408,21 @@ def path(request, path): folders = os.listdir(cwd) except: folders = [] - + + files = [] + for f in folders: - data = {'name': f[:50], - 'size': '', - 'modified': '', - 'type': 'file', - 'fullpath': ''} + data = {} + data['name']: f data['fullpath'] = os.path.join(cwd, f) data['sort'] = data['fullpath'].lower() data['modified'] = datetime.fromtimestamp(int(os.path.getmtime(os.path.join(cwd, f)))) data['ext'] = os.path.splitext(f)[1] + if os.path.isdir(os.path.join(cwd, f)): data['type'] = 'dir' + else: + data['type'] = 'file' if os.path.isfile(os.path.join(cwd, f)): data['size'] = os.path.getsize(os.path.join(cwd, f)) @@ -426,11 +433,13 @@ def path(request, path): data['size'] = data['size'] / 1024. units = ('', 'K','M','G','T') data['unit'] = units[power]+'Byte' + else: + data['size'] = '' files.append(data) files = sorted(files, key=itemgetter('type', 'sort')) - return render_to_response(join(settings.TEMPLATE, 'pathchooser.html'), {'cwd': cwd, 'files': files, 'parentdir': parentdir}, RequestContext(request)) + return render_to_response(join(settings.TEMPLATE, 'pathchooser.html'), {'cwd': cwd, 'files': files, 'parentdir': parentdir, 'type': type, 'oldfile': oldfile}, RequestContext(request)) |