예제 #1
0
 def display_collection(self, id):
     collection = Collection.get_by_id(self.db, id);
     if collection == None:
         raise Exception("No collection with id {}!".format(id))
     Collection.print_table_header()
     collection.print_for_table()
     items = Item.get_by_collection(self.db, collection.id)
     print("ITEMS")
     Item.print_table_header()
     for item in items:
         item.print_for_table()
예제 #2
0
def process_staging(functions):
    #Get all files in staging directory
    files = [ f for f in listdir(functions.stage) if isfile(join(functions.stage,f)) ]
    for file in files:
        collection_id = -1
        collection_path = ""
        
        #List collections for user
        functions.list_collections()
        print("N.  New Collection")
        print("File: {}".format(file))
        val = input("Select collection to use (id): ")
        
        #Get or create selected collection
        if val == "N":
            coll = create_collection(functions.library, functions.db)
            collection_id = coll.id 
            collection_path = coll.path
        else:
            coll = Collection.get_by_id(functions.db, int(val))
            collection_id = coll.id 
            collection_path = coll.path
        
        #Assign name and move file
        val = input("Enter a name for {} (if blank filename will be used): ".format(file)) 
        item_name = val
        if item_name == "":
            item_name = file
        item = Item(None, collection_id, item_name, file)
        
        rename(join(functions.stage, file), join(functions.library, collection_path, file))
        
        #Persist
        item.insert(functions.db)

    print("Staging processed!")
예제 #3
0
 def delete_collection(self, id):
     collection = Collection.get_by_id(self.db, id);
     collection.delete();