当前位置: 首页>>代码示例>>Python>>正文


Python APIPermissions.get_file_by_key方法代码示例

本文整理汇总了Python中API.APIPermissions.get_file_by_key方法的典型用法代码示例。如果您正苦于以下问题:Python APIPermissions.get_file_by_key方法的具体用法?Python APIPermissions.get_file_by_key怎么用?Python APIPermissions.get_file_by_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在API.APIPermissions的用法示例。


在下文中一共展示了APIPermissions.get_file_by_key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_file_rename_file_by_key_success

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import get_file_by_key [as 别名]
	def test_file_rename_file_by_key_success(self):
		key = ps.add_file( FileInfo("testFilernfks",ndb.Key("someKey","rnfks") ) )

		self.assertTrue(ps.rename_file_by_key(key,"testFilernfks2"))

		fileobj = ps.get_file_by_key(key)

		self.assertEqual(fileobj.file_name,"testFilernfks2")
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:10,代码来源:TestAPIPermissions.py

示例2: file_list_json

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import get_file_by_key [as 别名]
def file_list_json(request):
	app_access = __check_app_access()
	if app_access is not None:
		return app_access
	
	authed_user = auth.get_current_user()
	user_key = ps.get_user_key_by_id(authed_user.user_id())
	#TODO: This shouldn't be here - a generic method in APIPermissions would be nice.


	# 'your files'
	file_list = []

	lst = ps.get_user_permissions_list(user_key)
	temp_group = []
	if lst is not None:
		for perm in lst:
			list_entry = {}
			file_entry = ps.get_file_by_key(perm.file_key)
			if file_entry is not None:
				
				temp_file = ds.get_file_info(file_entry.file_name)
				if temp_file is None:
					continue
				
				list_entry.update({ 'permissions' 	: 'yes',
									'friendlyName'	: file_entry.friendly_name,
									'colour'		: perm.colour,
									'starred'		: perm.starred
								} )
		
				temp_file.filename = temp_file.filename.rpartition('/')[2]
				list_entry.update( {	'filename' 		: temp_file.filename,
										'size' 			: temp_file.st_size,
								  		'hash' 			: temp_file.etag,
								  		'timestamp' 	: temp_file.st_ctime
								  })
				temp_group.append(list_entry)


	if len(temp_group) > 0:
		file_list.append({	'catagory' 	: 'owned',
							'heading' 	: 'Your Files',
						 	'type'		: 'files',
							'data' 		: temp_group })
						
	if len(file_list) == 0:
		file_list.append({	'catagory' 	: 'notice',
						 	'type'		: 'html',
						 
						 	# TODO: move this line out
						 	'data'		: '<a data-toggle="modal" data-target="#uploadModal" class="list-group-item">No files - Click here to upload one</a>'
							})


	return HttpResponse(json.dumps(file_list), content_type="application/json")
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:58,代码来源:views.py

示例3: test_file_get_file_by_key_success

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import get_file_by_key [as 别名]
	def test_file_get_file_by_key_success(self):
		key = ps.add_file( FileInfo( "testFilegfks",ndb.Key("someKey","gfks") ) )
		fileobj = ps.get_file_by_key(key)

		self.assertEqual(fileobj.file_name,"testFilegfks")
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:7,代码来源:TestAPIPermissions.py

示例4: file_preview

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import get_file_by_key [as 别名]
def file_preview(request, file = None):
	app_access = __check_app_access()
	if app_access is not None:
		return app_access

	## Authentication.
	authed_user = auth.get_current_user()
	if authed_user is None:
		authed_user_nick = 'Guest'
	else:
		authed_user_nick = authed_user.nickname()
	## Graph visualisation.
	# Replaced by a spinning canvas on the clientside
	# if not ds.check_exists(GRAPH_BUCKET + '/' + file_name_without_extension + '.png', None):
	# 	file_name_without_extension = None

	#TODO: Might need to be simplified or moved to a function in fileinfo
	# TODO the folowing should be replaced by a method in the APIDatastore
	file_info = ps.get_file_by_name(DATA_BUCKET + '/' + file)

	undo_uri = None
	if file_info is not None:
		prev_file = ps.get_file_by_key(file_info.prev_file_key)
		if prev_file is not None:
			undo_uri = prev_file.file_name.rpartition(DATA_BUCKET + '/')[2]

	lst = ds.list(DATA_BUCKET)
	current_file = None
	for temp_file in lst:
		temp_file.filename = temp_file.filename.rpartition('/')[2]
		if temp_file.filename == file:
			current_file = temp_file;


	# Check whether graph exists yet.
	graph_exists = ds.check_exists(GRAPH_BUCKET + '/' + file.partition('.')[0] + '.png', None)

	# Get permissions for file.
	permissions = None
	if file_info is not None:
		user_key = ps.get_user_key_by_id(authed_user.user_id())
		permissions = ps.get_user_file_permissions(file_info.key, user_key)

	template_dict = {'current_file' : current_file,
									 'name' : file,
									 'authed_user_nick': authed_user_nick,
									 'file_info' : file_info,
									 'graph_ready' : graph_exists,
									 'undo_link' : undo_uri,
									 'permissions' : permissions }

	## Get gating information.
	info_path = INFO_BUCKET + '/' + file.partition('.')[0] + '.txt'
	if ds.check_exists(info_path, None):
		buffer = ds.open(info_path)
		if buffer:
			file_text = buffer.read()
			stats = file_text.split(' ')
			if len(stats)>=3:
				template_dict.update( { 'gating_stats' : { 'selection' : stats[0],
										'total' : stats[1],
										'percent' : float(stats[2])*100 } } )

	## Get different axis
	axis_path = INFO_BUCKET + '/' + file.partition('.')[0] + 'info.txt'
	if ds.check_exists(axis_path, None):
		buffer = ds.open(axis_path)
		if buffer:
			file_text = buffer.read()
			axis = file_text.split('\n')
			if len(axis)>0:
				while '' in axis:
					axis.remove('')
				template_dict.update( { 'available_axes' : axis } )

	return render(request, 'file_preview.html', template_dict)
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:78,代码来源:views.py


注:本文中的API.APIPermissions.get_file_by_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。