Beispiel #1
0
def graph_preview(request, file = None):
	lst = ds.list(DATA_BUCKET)
	for temp_file in lst:
		temp_file.filename = temp_file.filename.rpartition('/')[2]
		if temp_file.filename == file:
			file_info = temp_file;

	return render(request, 'graph_preview.html',
		{'current_file' : file_info, 'file_name_without_extension' : file})
Beispiel #2
0
def app(request):
	lst = ds.list(DATA_BUCKET)
	file_info = None
	
	app_access = __check_app_access(True)
	if app_access is not None:
		return app_access
	
	authed_user = auth.get_current_user()
	authed_user_nick = authed_user.nickname()

	request.upload_handlers = [upload_handling.fcsUploadHandler()]
	if request.method == 'POST':
		form = forms.UploadFile(request.POST, request.FILES)
		if form.is_valid():
			cd = form.cleaned_data
			return redirect('#!/preview/' + request.FILES['file'].name)
		else:
			return render(request, 'app.html', {'form': form, 'files' : lst , 'current_file' : file_info, 'authed_user_nick' : authed_user_nick})
	else:
		form = forms.UploadFile()
		return render(request, 'app.html', {'form': form, 'files' : lst , 'current_file' : file_info, 'authed_user_nick' : authed_user_nick})
Beispiel #3
0
def file_list(request):
	app_access = __check_app_access()
	if app_access is not None:
		return app_access
	
	lst = ds.list(DATA_BUCKET)

	file_list = []
	
	for temp_file in lst:
		list_entry = {}
		file_entry = permissions.get_file_by_name(temp_file.filename)
		if file_entry is not None:
			list_entry.update({ 'permissions' : 'yes' })
		else:
			list_entry.update({ 'permissions' : 'no'  })
		
		temp_file.filename = temp_file.filename.rpartition('/')[2]
		list_entry.update( { 'filestat' : temp_file } )

		file_list.append(list_entry)

	return render(request, 'file_list.html', {'files' : file_list})
Beispiel #4
0
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)