def post(self):
		self.response.headers['Content-Type'] = 'text/html'
		url = ''
		url_string = ''
		welcome = 'Welcome back'
		directory = ' '
		user = users.get_current_user()
		logout = users.create_logout_url('/')
		directory=''
		logout = logout = users.create_logout_url('/')
		if self.request.get('button') == 'Add a Directory' :
			directory_id = self.request.get('directory_id')
			user = users.get_current_user()
			template_values = {
			'directory_id' : directory_id,
			'user' : user,
			'logout' : logout
			}

			template = JINJA_ENVIRONMENT.get_template('adddirectory.html')
			self.response.write(template.render(template_values))

		if self.request.get('button') == 'Submit' :
			
			directory_id = self.request.get('directory_id')
			directory_key = ndb.Key(Directory,directory_id)
			directory = directory_key.get()
	
			directory_path = directory.directory_path
			directory_name = self.request.get('unique_directory_name')

			checking_unique_directory_name = 0;
			for each in directory.list_of_directories :
					preprocess = each.replace('u','').replace(' ','').replace('\'','')
					sub_directory_key = ndb.Key(Directory,preprocess)
					sub_directory = sub_directory_key.get()
					if sub_directory.directory_name == directory_name :
						checking_unique_directory_name = checking_unique_directory_name + 1
						break
			if checking_unique_directory_name == 0 :
				random_id = str(random.randint(000000,999999))

				random_key = ndb.Key(Directory,random_id)
				random_value = random_key.get()

				if random_value != None :
					while (random_value!=None) :
						random_id = str(random.randint(000000, 999999))

						random_key = ndb.Key(Directory, random_id)
						random_value = random_key.get()


				if random_value == None :
					new_directory = Directory(id=random_id)
					new_directory.directory_name = directory_name
					new_directory.prev_directory = directory_id
					new_path = directory_path + directory_name + '/'
					new_directory.directory_path = new_path
					new_directory.put()

			#search = Directory.query(Directory.directory_name == directory_name).fetch()
					directory.list_of_directories.append(random_id)
					directory.put()
					self.redirect('/main')




			else :
				error_message = "Please enter a unique directory name. The directory name entered exists"
				user = users.get_current_user()
				template_values = {
					'directory_id' : directory_id,
					'error_message' : error_message,
					'user' : user,
					'logout' : logout
				}

				template = JINJA_ENVIRONMENT.get_template('adddirectory.html')
				self.response.write(template.render(template_values))
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        directory = ' '
        user = users.get_current_user()
        logout = users.create_logout_url('/')
        directory_key = ''
        list_directories = []
        previous_directory_id = ''
        previous_directory_name = ''
        list_files = []
        SharedFiles = []
        SharedFileOwner = []
        if user:
            url = users.create_logout_url(self.request.uri)
            url_string = 'logout'
            myuser_key = ndb.Key(User, user.user_id())
            myuser = myuser_key.get()

            if myuser == None:
                welcome = 'Welcome to the application'
                myuser = User(id=user.user_id())
                myuser.email = user.email()
                myuser.put()
                id_of_root_directory = user.email() + "/"
                directory = Directory(id=id_of_root_directory)
                directory.directory_path = '/'
                directory.directory_name = '/'
                directory.put()

            else:
                id_of_root_directory = user.email() + "/"

                directory_key = ndb.Key(Directory, id_of_root_directory)
                directory = directory_key.get()
                for each in directory.list_of_directories:
                    preprocess = each.replace('u', '').replace(' ',
                                                               '').replace(
                                                                   '\'', '')
                    sub_directory_key = ndb.Key(Directory, preprocess)
                    sub_directory = sub_directory_key.get()
                    list_directories.append(sub_directory.directory_name)

                for each in directory.list_of_files:
                    list_files.append(each)

                for index, each in enumerate(directory.shared_files):
                    SharedFiles.append(each)
                    owner = directory.shared_file_owner[index]
                    SharedFileOwner.append(owner)
        path = directory.directory_path
        template_values = {
            'id_of_root_directory': id_of_root_directory,
            'list_directories': list_directories,
            'user': user,
            'logout': logout,
            'previous_directory_id': directory.prev_directory,
            'previous_directory_name': previous_directory_name,
            'list_files': list_files,
            'shared_files': SharedFiles,
            'shared_file_owner': SharedFileOwner,
            'path': path
        }

        template = JINJA_ENVIRONMENT.get_template('main.html')
        self.response.write(template.render(template_values))