from django.core.files.storage import FileSystemStorage
import os
import random,string

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 uploadTheStoreLogo(image):
    fullPath='media/storeLogo'
    fs = FileSystemStorage(location=fullPath)
    fullPath2='media/storeLogo'
    filetype = os.path.splitext(image.name)[1]
    theName=randomStringFunctionForImage()
    theImageName=str(theName)+str(filetype)
    filename = fs.save(theImageName, image)
    return str(fullPath2)+'/'+filename

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

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