from django.core.files.storage import FileSystemStorage
import os





def gernateToken():
	import random
	import array
	MAX_LEN = 66
	DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] 
	LOCASE_CHARACTERS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h','i', 'j', 'k', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y','z']
	COMBINED_LIST = DIGITS + LOCASE_CHARACTERS
	rand_digit = random.choice(DIGITS)
	rand_lower = random.choice(LOCASE_CHARACTERS)
	temp_pass = rand_digit + rand_lower
	for x in range(MAX_LEN - 4):
		temp_pass = temp_pass + random.choice(COMBINED_LIST)
		temp_pass_list = array.array('u', temp_pass)
		random.shuffle(temp_pass_list)
	token = ""
	for x in temp_pass_list:
			token = token + x
	return token



def randomStringFunctionForImage():
	import random,string
	str1 = ''.join((random.choice(string.ascii_letters) for x in range(8)))
	str1 += ''.join((random.choice(string.digits) for x in range(4)))
	sam_list = list(str1)
	random.shuffle(sam_list)
	finalString = ''.join(sam_list)
	return finalString

def uploadTheProfile(image):
	fullPath='media/admin_profile'
	fs = FileSystemStorage(location=fullPath)
	fullPath2='media/admin_profile'
	filetype = os.path.splitext(image.name)[1]
	theName=randomStringFunctionForImage()
	theImageName=str(theName)+str(filetype)
	filename = fs.save(theImageName, image)
	return str(fullPath2)+'/'+filename


def uploadThecategory(image):
	fullPath='media/category'
	fs = FileSystemStorage(location=fullPath)
	fullPath2='media/category'
	filetype = os.path.splitext(image.name)[1]
	theName=randomStringFunctionForImage()
	theImageName=str(theName)+str(filetype)
	filename = fs.save(theImageName, image)
	return str(fullPath2)+'/'+filename

