def dropbox_view_file(path, node_addon, auth, **kwargs): """Web view for the file detail page.""" if not path: raise HTTPError(http.NOT_FOUND) # check that current user has access to the path if not is_authorizer(auth, node_addon): abort_if_not_subdir(path, node_addon.folder) node = node_addon.owner client = get_node_addon_client(node_addon) # Lazily create a file GUID record file_obj, created = DropboxFile.get_or_create(node=node, path=path) redirect_url = check_file_guid(file_obj) if redirect_url: return redirect(redirect_url) rev = request.args.get('rev') or '' rendered = render_dropbox_file(file_obj, client=client, rev=rev) cleaned_path = clean_path(path) response = { 'revisions_url': node.api_url_for('dropbox_get_revisions', path=cleaned_path, rev=rev), # Append current revision as a query param 'file_name': get_file_name(path), 'render_url': node.api_url_for('dropbox_render_file', path=cleaned_path), 'download_url': file_obj.download_url(guid=True, rev=rev), 'rendered': rendered, } response.update(serialize_node(node, auth, primary=True)) return response, http.OK
def test_metadata_to_hgrid(self): metadata = { u'bytes': 123, u'icon': u'file', u'is_dir': False, u'modified': u'Sat, 22 Mar 2014 05:40:29 +0000', u'path': u'/foo/bar/baz.mp3', u'rev': u'3fed51f002c12fc', u'revision': 67032351, u'root': u'dropbox', u'size': u'0 bytes', u'thumb_exists': False, u'mime_type': u'audio/mpeg', } node = ProjectFactory() permissions = {'view': True, 'edit': False} result = utils.metadata_to_hgrid(metadata, node, permissions) assert_equal(result['addon'], 'dropbox') assert_equal(result['permissions'], permissions) filename = utils.get_file_name(metadata['path']) assert_equal(result['name'], filename) assert_equal(result['path'], metadata['path']) assert_equal(result['ext'], os.path.splitext(filename)[1])
def test_get_file_name(): assert_equal(utils.get_file_name('foo/bar/baz.txt'), 'baz.txt') assert_equal(utils.get_file_name('/foo/bar/baz.txt'), 'baz.txt') assert_equal(utils.get_file_name('/foo/bar/baz.txt/'), 'baz.txt')