Esempio n. 1
0
def create_new_command(query):
	if len(query) > 2: # Check that both command name and URI were provided.
		enteredCommandString = ' '.join(query)
		commands = db.GqlQuery("SELECT * FROM Command")
		commandAlreadyExists = False
		for command in commands:
			if command.name == query[1]:
				commandAlreadyExists = True
		if not commandAlreadyExists:
			# make sure something usable was entered for command name and search string.
			if len(query[1]) > 0 and len(query[2]) > 5: 
				if (query[2][0:7] == "http://") or (query[2][0:8] == "https://"):
					command = Command(
						name=query[1],
						searchString=query[2],
						description='',
						usage='',
						builtin='no')
					command.put()
					return ('<p>Created command: ' + query[1] +
											' => ' + query[2] + "</p>" +
											'<a href="/">Home</a>')
				else: # Command URI did not begin with 'http://'' or 'https://'.
					return ('<a href="/?try_again=' + 
								enteredCommandString + 
								'">Try again</a>: Command URI must begin with http:// or https://.')
			else: # Command name and/or URI too short.
				return ('<a href="/?try_again=' + 
								enteredCommandString + 
								'">Try again</a>: You must enter a valid command name followed by a URI.')
		else: # Command already exists.
			return ('<a href="/?try_again=' + 
								enteredCommandString + 
								'">Try again</a>: Command "' + 
								query[1] + 
								'" already exists, please use a unique command name.')
	else: # Command name and/or URI missing.
		return ('<a href="/?try_again=' + 
								enteredCommandString + 
								'">Try again</a>: You must enter at least a command name followed by a URI.')