Exemple #1
0
def getSubFolders(folder_key):
    logging.info('getSubfolders(): Start')

    #temporary class to save folder details temporarily before saving it in to folder dictionary.
    class folderclass:
        pass

    #declare alist to store subfolders. Lists needs to be declared before using it
    subfolders_list = []

    #get subfolders in this folder
    #create query to find folders with filter parent_folder = folder_key - folder key retrieved  from the GUI interface
    subfolders = Folder.query(Folder.parent_folder == folder_key).order(
        Folder.name).fetch()

    #iterate through folder contents retrieved by above query
    for folder in subfolders:
        folder_temp = folderclass(
        )  #create instance of folderclass to temporarily store folder details before writing to dictionary.

        #assign folder details of datastore to temporary folder class

        folder_temp.key = folder.key.urlsafe()
        folder_temp.name = folder.name

        #append this folder details to the list. ___dict__ will return the dictionary format of the object
        subfolders_list.append(folder_temp.__dict__)

    #subfolders to json format
    subfolders_json = json.dumps(subfolders_list)

    #return json object
    return subfolders_json
Exemple #2
0
def copyAllSubFolders(folder, target_folder):
    #TODO Need to copy subfolders tree contents

    logging.info('copyAllSubFolder(): Start')

    #Create new folder element to copy the folder
    new_folder = Folder(parent=genFolderParentKey())

    #Copy the folder to new folder
    logging.info('copyAllSubFolders: copying folder |' + folder.name +
                 '| to: |' + target_folder.name)
    new_folder.populate(
        **folder.to_dict()
    )  #to_dict returns the dictionary of 'folder' and '.populate()' will save the value pairs to new folder

    #change necessary parameters
    new_folder.parent_folder = target_folder.key  #parent of new folder should be the target folder
    new_folder.date_c = datetime.datetime.now()
    new_folder.date_m = datetime.datetime.now()
    new_folder.path = target_folder.path + new_folder.name + '/'  #path is calcuated from the give target folder's path

    #save new folder
    new_folder.put()

    #find and copy files in this folder
    subLinks = Link.query(Link.parent_folder == folder.key).fetch()
    for subLink in subLinks:
        logging.info("Copying Link: " + subLink.name)

        #Create new link
        new_link = Link(parent=genLinkParentKey())

        #Copy the links to new folder
        logging.info('copyAllSubFolders: copying file |' + subLink.name +
                     '| to: |' + target_folder.name)
        new_link.populate(
            **subLink.to_dict()
        )  #to_dict returns the dictionary of 'subLink' and '.populate()' will save the value pairs to new link

        new_link.parent_folder = new_folder.key  #parent of new folder should be the one provided by the user
        new_link.date_c = datetime.datetime.now()
        new_link.date_m = datetime.datetime.now()
        new_link.path = new_folder.path

        #save new link
        new_link.put()

    #find and copy the subfolders in this folder
    subfolders = Folder.query(Folder.parent_folder == folder.key).fetch()
    for subfolder in subfolders:
        copyAllSubFolders(subfolder, new_folder)

    return "success"
Exemple #3
0
def deleteAllSubFolders(folder):
    logging.info("deleteAllSubFolder() : start")

    logging.info(folder.name)

    #get subfolders
    subfolders = Folder.query(Folder.parent_folder == folder.key).fetch()

    #delete all sub folders
    for subfolder in subfolders:
        deleteAllSubFolders(subfolder)

    #find and delete the links in this folder
    subLinks = Link.query(Link.parent_folder == folder.key).fetch()
    for subLink in subLinks:
        logging.info("deleting Link: " + subLink.name)
        subLink.key.delete()

    logging.info("deleting Folder: " + folder.name)
    folder.key.delete()

    return 'Success'
Exemple #4
0
def getFolderContents(params):
    logging.info('getFolderContents(): Start')

    folder_key = params['folder_key']

    #temporary class to save folder details temporarily before saving it in to folder dictionary.
    class linkclass:
        pass

    #temporary class to save folder details temporarily before saving it in to folder dictionary.
    class folderclass:
        pass

    #declare dictionary to store retrieved folders and links. dictionaries needs to be declared before using it
    folder_contents_dict = {'folder': [], 'link': []}

    #get links in this folder
    #create query to find links with filter parent_folder = (params["folder_key"]) - folder key retrieved from the GUI interface
    links = Link.query(Link.parent_folder == params['folder_key']).order(
        Link.name).fetch()

    #iterate through links retrieved by above query
    for link in links:
        link_temp = linkclass()

        link_temp.date_c = link.date_c.isoformat()
        link_temp.date_m = link.date_m.isoformat()
        link_temp.description = link.description
        link_temp.file_type = link.file_type
        link_temp.key = link.key.urlsafe()
        link_temp.name = link.name
        link_temp.path = link.path
        link_temp.url = link.url
        link_temp.website = link.website

        folder_contents_dict['link'].append(link_temp.__dict__)

    #get subfolders in this folder
    #create query to find folders with filter parent_folder = (params["folder_key"]) - folder key retrieved  from the GUI interface
    subfolders = Folder.query(
        Folder.parent_folder == params['folder_key']).order(
            Folder.name).fetch()

    #iterate through folder contents retrieved by above query
    for folder in subfolders:
        folder_temp = folderclass(
        )  #create instance of folderclass to temporarily store folder details before writing to dictionary.

        #assign folder details of datastore to temporary folder class

        folder_temp.date_c = folder.date_c.isoformat(
        )  #isoformat() is to convert the python date format to json serializable format
        folder_temp.date_m = folder.date_m.isoformat()
        folder_temp.icon = folder.icon
        folder_temp.key = folder.key.urlsafe()
        folder_temp.name = folder.name

        #append this folder details to the dictionary. ___dict__ will return the dictionary format of the object
        folder_contents_dict['folder'].append(folder_temp.__dict__)

    #construct current folder's details as well to send back. This might be required by GUI for various purpose.

    current_folder = params['folder_key'].get()  #get current folder object

    current_folder_temp = folderclass()  #temporary folder object

    current_folder_temp.date_c = current_folder.date_c.isoformat(
    )  #isoformat() is to convert the python date format to json serializable format
    current_folder_temp.date_m = current_folder.date_m.isoformat()
    current_folder_temp.icon = current_folder.icon
    current_folder_temp.key = current_folder.key.urlsafe()
    current_folder_temp.name = current_folder.name

    #add current folder details to the dictionary
    folder_contents_dict['current_folder'] = current_folder_temp.__dict__

    folder_contents_dict['folder_path'] = getFolderPath(folder_key)

    #convert python dictionary in to json format
    folder_contents_json = json.dumps(folder_contents_dict)

    #return json object
    return folder_contents_json