예제 #1
0
    def addToInventory(self,title="",status="STOCK",authors=[],publisher="",price="",isbn="",categories=[],distributor="",owner="",notes="",quantity=1,known_title=False,kind_name="",extra_prices={}):
        if not(known_title):
	    #add a title
            the_kinds=list(Kind.select(Kind.q.kindName==kind_name))
            kind_id = None
            if the_kinds:
                kind_id = the_kinds[0].id
	    known_title=Title(isbn=isbn, booktitle=title.encode("ascii", "backslashreplace"), publisher=publisher.encode("ascii", "backslashreplace"),tag=" ",kindID=kind_id)
            for rawAuthor in authors:
	    	author = rawAuthor.encode("ascii", "backslashreplace")
		theAuthors = Author.selectBy(author_name=author)
		theAuthorsList = list(theAuthors)
		if len(theAuthorsList) == 1:
		    known_title.addAuthor(theAuthorsList[0])
		elif len(theAuthorsList) == 0:
		    a = Author(author_name=author)
		    known_title.addAuthor(a)
		else:
		    # We should SQLDataCoherenceLost here
		    print "mmm... looks like you have multiple author of the sama name in your database..."
            for category in categories:
                Category(categoryName=category.encode("ascii", "backslashreplace"),title=known_title)

        for i in range(int(quantity)): 
            print distributor.encode('ascii', "backslashreplace")
            
            wholesale=0
            try:
                wholesale=extra_prices['wholesale']
            except:
                pass

	    b=Book(title=known_title,status=status.encode("ascii", "backslashreplace"), distributor=distributor.encode('ascii', "backslashreplace"),listprice=price,owner=owner.encode("ascii", "backslashreplace"),notes=notes.encode("ascii", "backslashreplace"),consignmentStatus="",wholesale=wholesale)
            b.extracolumns()
            for mp in extra_prices.keys():
                setattr(b,string.replace(mp," ",""),extra_prices[mp])
예제 #2
0
    def addToInventory(self,
                       title="",
                       status="STOCK",
                       authors=[],
                       publisher="",
                       price="",
                       isbn="",
                       categories=[],
                       distributor="",
                       owner="",
                       notes="",
                       quantity=1,
                       known_title=False,
                       kind_name="",
                       extra_prices={}):
        if not (known_title):
            #add a title
            the_kinds = list(Kind.select(Kind.q.kindName == kind_name))
            kind_id = None
            if the_kinds:
                kind_id = the_kinds[0].id
            known_title = Title(isbn=isbn,
                                booktitle=title.encode("ascii",
                                                       "backslashreplace"),
                                publisher=publisher.encode(
                                    "ascii", "backslashreplace"),
                                tag=" ",
                                kindID=kind_id)
            for rawAuthor in authors:
                author = rawAuthor.encode("ascii", "backslashreplace")
                theAuthors = Author.selectBy(author_name=author)
                theAuthorsList = list(theAuthors)
                if len(theAuthorsList) == 1:
                    known_title.addAuthor(theAuthorsList[0])
                elif len(theAuthorsList) == 0:
                    a = Author(author_name=author)
                    known_title.addAuthor(a)
                else:
                    # We should SQLDataCoherenceLost here
                    print "mmm... looks like you have multiple author of the sama name in your database..."
            for category in categories:
                Category(categoryName=category.encode("ascii",
                                                      "backslashreplace"),
                         title=known_title)

        for i in range(int(quantity)):
            print distributor.encode('ascii', "backslashreplace")

            wholesale = 0
            try:
                wholesale = extra_prices['wholesale']
            except:
                pass

            b = Book(title=known_title,
                     status=status.encode("ascii", "backslashreplace"),
                     distributor=distributor.encode('ascii',
                                                    "backslashreplace"),
                     listprice=price,
                     owner=owner.encode("ascii", "backslashreplace"),
                     notes=notes.encode("ascii", "backslashreplace"),
                     consignmentStatus="",
                     wholesale=wholesale)
            b.extracolumns()
            for mp in extra_prices.keys():
                setattr(b, string.replace(mp, " ", ""), extra_prices[mp])