Example #1
0
def analysis_status_json(request):
	authed_user = auth.get_current_user()
	if authed_user is None:
		return __unauthed_response()

	user_key = ps.get_user_key_by_id(authed_user.user_id())

	response_part = {
		'backoff' 	: 0,		#tells the client to back off for a given amount of time (milliseconds) (This is added to the client's constant poll interval)
		'giveup'	: True,		#True instructs the client to stop polling - useful for situations such as unauthed requests where polling will never result in the user being shown a graph
		'done'		: False		#True indicates that the analysis has finished and that the user can be redirected to the new image
	}
	
	try:
		file_req = json.loads(request.raw_post_data)
	except ValueError:
		response_part.update({'error' : 'Invalid request payload.'})
		return HttpResponse(json.dumps(response_part), content_type="application/json")

	if 'filename' not in file_req:
		response_part.update({'error' : 'Incomplete request.'})
		return HttpResponse(json.dumps(response_part), content_type="application/json")

	chk_file_name = DATA_BUCKET + '/' + file_req['filename']
	file_entry = ps.get_file_by_name(chk_file_name)
	logging.info(file_entry)
	if file_entry is None:
		response_part.update( { 'error' : 'File or gate not recognised.', 'giveup' : False } )
		return HttpResponse(json.dumps(response_part), content_type="application/json")
	else:
		fp_entry = ps.get_user_file_permissions(file_entry.key, user_key)
		if fp_entry is None:
			response_part.update( { 'error' : 'Permission denied.' } )
			return HttpResponse(json.dumps(response_part), content_type="application/json")

	name = file_req['filename']
	is_done =  ds.check_exists(GRAPH_BUCKET + '/' + name + '.png', None)

	#Prevent redirecting before the view is ready
	is_done &= ds.check_exists(DATA_BUCKET  + '/' + name, None)

	#Prevent redirecting before gating info is ready
	is_done &= ds.check_exists(INFO_BUCKET + '/' + name + '.txt', None)

	response_part.update( { 'done' : is_done, 'giveup' : False } )
	return HttpResponse(json.dumps(response_part), content_type="application/json")
Example #2
0
def generate_gating_feedback(status, message, new_graph_name = None, existing_name = None, new_axis_a = "FSC-A", new_axis_b = "SSC-A"):
	if new_graph_name is not None:
		## Authenticate and get user 
		authed_user = auth.get_current_user()
		user_key = ps.get_user_key_by_id(authed_user.user_id())

		## Get previous file permissions.
		previous_file = ps.get_file_by_name(DATA_BUCKET + existing_name)
		previous_permissions = ps.get_user_file_permissions(previous_file.key, user_key)

		if isinstance(new_graph_name, list):
			new_graph_names = new_graph_name
		else:
			new_graph_names = [new_graph_name]
		
		# Overwrite new_graph_name for return dictionary
		new_graph_name = new_graph_names[0]
		logging.info(new_graph_name)
		logging.info(new_graph_names)
							
		for new_name in new_graph_names:
			new_file = FileInfo(file_name = DATA_BUCKET + new_name,
								owner_key = user_key,
								friendly_name = previous_file.friendly_name + '-gate',
								prev_file_key = previous_file.key,
								axis_a = new_axis_a,
								axis_b = new_axis_b )
			file_key = ps.add_file(new_file)
			ps.add_file_permissions(file_key,
									user_key,
									Permissions (
										previous_permissions.read,
										previous_permissions.write,
										previous_permissions.full_control
									),
									previous_permissions.colour,
									False)

	return {
		'status': status,
		'message': message,
		'url': reverse('get_graph', args=[new_graph_name]),
		'graphName' : new_graph_name
	}
Example #3
0
def no_such_tool(gate_params):

	## \todo Do we really need to log the entire tool list? It's defined literally.
	logging.error('The tool "'+ gate_params['tool'] +'" is unknown. The known tools are: {' +
		', '.join(list(AVAILABLE_TOOLS.keys())) + '}' )
	return generate_gating_feedback("fail","The tool you selected is not reconized by the server", None)