Beispiel #1
0
def weblogbulk(apikey, tablename, loglist):
	result = {}
	if db_interface.getProjectFromKey(apikey) is None:
		result['error'] = "incorrect api key"
	else:
		project_name = db_interface.getProjectFromKey(apikey)
		if db_interface.checkTableExists(project_name, tablename) is False:
			result['error'] = "incorrect table name"
		else:
			status = db_interface.getProjectStatus(project_name)
			if status == "overdrawn":
				result['error'] = "project_overdrawn"
			elif status == "stopped":
				result['error'] = "project_stopped"
			elif status == 'running':
				for log in loglist:
					db_interface.log(project_name, tablename, log)

				#Charge the project
				charge = db_interface.chargeProject(project_name, len(loglist))
				if charge == "failure":
					result['error'] = "logged but failed to charge"
				else:
					#Return success
					result['error'] = ""
			else:
				result['error'] = "processing error"

	if result['error'] == "":
		result['log'] = loglist
		result['project_name'] = project_name
		result['table_name'] = tablename
		result['free_logs_left'] = charge
	else:
		result['log'] = ""
		result['project_name'] = ""
		result['table_name'] = ""
		result['free_logs_left'] = ""
	return result
Beispiel #2
0
def createtable_view(request, apikey, tablename):
	result = {}
	if db_interface.getProjectFromKey(apikey) is None:
		result['error'] = "incorrect api key"
	else:
		project_name = db_interface.getProjectFromKey(apikey)
		if db_interface.checkTableExists(project_name, tablename) is True:
			result['error'] = "table name already taken"
		else:
			default_tabletype = db_interface.getTabletypeDefault(project_name)
			db_interface.createTable(project_name, tablename, default_tabletype)
			result['error'] = ""
			result['result'] = "success"
			result['project_name'] = project_name
			result['table_name'] = tablename
			result['table_type'] = default_tabletype
			return JsonResponse(result)

	#Indicates failure
	result['result'] = "failure"
	result['project_name'] = ""
	result['table_name'] = ""
	result['table_type'] = ""
	return JsonResponse(result)
Beispiel #3
0
def status_view(request, apikey):
	result = {}
	project_name = db_interface.getProjectFromKey(apikey)
	if project_name is None:
		result['error'] = "incorrect api key"
		result['project_status'] = ""
		result['server_status'] = ""
	else:
		result['error'] = ""
		project_status = db_interface.getProjectStatus(project_name)
		if project_status == "overdrawn":
			result['project_status'] = "overdrawn"
			result['server_status'] = "on"
		elif project_status == "stopped":
			result['project_status'] = "stopped"
			result['server_status'] = "on"
		elif project_status == 'running':
			result['project_status'] = "running"
			result['server_status'] = "on"
		else:
			result['error'] = "server_error"
	return JsonResponse(result)