def get_authors_from_amazon(auth_missing=None):
    if not auth_missing:
        auth_missing = []
    for t in auth_missing:
        t1 = Title.get(t)
        try:
            amazonIter = ItemLookup(t1.isbn, ResponseGroup="ItemAttributes")
            amazonResults = next(amazonIter)
            if isinstance(getattr(amazonResults, "Author", False), type("")):
                auth = [getattr(amazonResuts, "Author", None)]
            else:
                auth = getattr(amazonResults, "Author", [])
            print(auth)
            if isinstance(getattr(amazonResults, "Creator", False), type("")):
                auth.extend([getattr(amazonResuts, "Creator", None)])
            else:
                auth.extend(getattr(amazonResults, "Creator", []))
            au_rec = ""
            for au in auth:
                try:
                    Author(authorName=au)
                except Exception:
                    pass
                au_rec = Author.selectBy(authorName=au)[0]
                print(au_rec)
                t1.addAuthor(au_rec)
                print((t1.author))
        except Exception as e:
            print(e)
示例#2
0
 def OnGetAuthors(self, authors):
     authorstring = Author.get(
         authors.pop(0)).author_name.decode("string_escape")
     for author in authors:
         # we make a string !
         authorstring = authorstring + "," + Author.get(
             author).author_name.decode("string_escape")
     self.author.SetValue(authorstring)
示例#3
0
    def OnAdd(self,event):
   	a = Author.selectBy(author_name = self.author_name.GetValue().encode("ascii", "backslashreplace"))
	if len(list(a)) != 0:
	    a = wxMessageDialog(self, "This author is already in the list", "Error", wxOK + wxICON_ERROR)
	    a.ShowModal()
	else:
	    a = Author(author_name = self.author_name.GetValue().encode("ascii", "backslashreplace"))
	    # This call deleteallitems on the author list. This is bad if there is a large amount of
	    # authors, we should simply add the new one.
	    self.loadAllAuthors() 
def get_authors_from_amazon(auth_missing=[]):
    for t in auth_missing:
        t1=Title.get(t)
        try:
            amazonIter=ItemLookup(t1.isbn, ResponseGroup="ItemAttributes")
            amazonResults=amazonIter.next()
            if type( getattr(amazonResults, 'Author', False)) == type(u''):
                auth= [ getattr(amazonResuts, 'Author', None) ]
            else:
                auth=getattr( amazonResults, 'Author', [])
            print auth
            if type( getattr(amazonResults,'Creator', False)) == type(u''):
                auth.extend([ getattr(amazonResuts, 'Creator', None) ])
            else:
                auth.extend(getattr( amazonResults, 'Creator', []))
            au_rec=''                
            for au in auth:
                try:
                    Author(authorName=au)           
                except Exception: 
                    pass
                au_rec=Author.selectBy(authorName=au)[0]
                print au_rec
                t1.addAuthor(au_rec)
                print t1.author
        except Exception as e:
            print e
示例#5
0
    def OnSave(self,event):
    	# Here we need to translate the list of author that are
	# currently selected to a list of author_id
	if self.currentAuthorList.GetItemCount() == 0:
	    a = wxMessageDialog(self, "Can't save an empty author list, create an anonymous author and set him at least as the author", "Error", wxOK + wxICON_ERROR)
	    a.ShowModal()
	else:
	    list_of_author = []
            item = -1
	    # For all the authors in the list of authors
	    for i in range(0,self.allAuthorList.GetSelectedItemCount()):
	        item = self.allAuthorList.GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	        # Get the name of the author
		his_name = self.allAuthorList.GetItemText(item).encode("ascii", "backslashreplace")
		# and try to find the name in the database. if there is
		# multiple, we just don't care
		#try: 
	        a = Author.selectBy(author_name = his_name)
		b = list(a)
		print b
		print b[0]
		list_of_author.append(b[0].id)
	        #except:
	        #    print his_name
	        #    print "Something real weird happened"
	    print list_of_author 
            self.parent.list_of_author = list_of_author
	    self.execWhenSelected(list_of_author)
	    self.parent.OnCancel(event)
示例#6
0
 def OnSearch(self,event):
     self.list.DeleteAllItems()
     self.authorString=self.author.GetValue()
     self.titleString=self.title.GetValue()
     self.firstnameString=self.firstname.GetStringSelection()
     self.lastnameString=self.lastname.GetStringSelection()
     i = 0
     bookcondition={}
     usercondition={}
     bookcondition["author"]=self.authorString
     bookcondition["title"]=self.titleString
     usercondition["fn"]=self.firstnameString
     usercondition["ln"]=self.lastnameString
         
     for x in Emprunt.select("return_date is null"):
         print x.date
         isGood=1
         item = x.getItem()
         member = x.getBorrower()
         titres = item.title # titres = title in french... 
         title = titres.booktitle
         a = Author.select("title_id=\'%d\'" % titres.id)
         a = list(a)
         print "6..."
         if len(a) > 1 or len(a) == 0:
             print "Shit !"
         author = a[0].authorName
         print author
         if len(usercondition) >= 1:
             if len(usercondition["fn"]) > 0 and not(member.first_name.find(usercondition['fn'])):
                 isGood=0
             else:
                 print "f n matches"
             if len(usercondition["ln"]) > 0 and not(member.last_name.find(usercondition['ln'])):
                 isGood=0
             else:
                 print "l n matches"
         if len(bookcondition) >= 1:
             if len(bookcondition["title"]) > 0 and not(title.find(bookcondition['title'])):
                 isGood=0
             else:
                 print "title matches"
             if len(bookcondition["author"]) > 0 and not(author.find(bookcondition["author"])):
                 isGood=0
             else:
                 print "author matches"
         if isGood == 1:
             self.list.InsertStringItem(i,title)
             self.list.SetStringItem(i,1,author)
             self.list.SetStringItem(i,2,member.first_name)
             self.list.SetStringItem(i,3,member.last_name)
             self.list.SetStringItem(i,4,x.date.isoformat())
             self.list.SetStringItem(i,5, "%d" % x.id)
             self.list.SetItemData(i,i)
             i=i+1
     if i>0:
         for x in range(6):
             self.list.SetColumnWidth(x, wxLIST_AUTOSIZE)
     EVT_LIST_ITEM_ACTIVATED(self,self.list.GetId(), self.onSelectItem)
示例#7
0
    def loadAllAuthors(self):
	self.allAuthorList.DeleteAllItems()
	theAuthors = list(Author.select())
	i = 0
	for author in theAuthors:
	    print author
            self.allAuthorList.InsertStringItem(i,author.author_name.decode("string_escape"))
	    i = i + 1
	self.allAuthorList.SetColumnWidth(0, wxLIST_AUTOSIZE)
示例#8
0
    def author(self,id):
    	the_author=Author.get(id)
	the_titles=Title.select("""
	    book.title_id=title.id AND
            book.status ='STOCK' AND
            author.id=author_title.author_id AND
            author_title.title_id=title.id AND author.author_name='%s'
            """ % (escape_string(the_author.author_name)),orderBy="booktitle",clauseTables=['book','author','author_title'],distinct=True)
	return dict(the_titles=the_titles,the_author=the_author,authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget())
示例#9
0
 def test_authoredit_functional(self):
     random_item = random.sample(list(Author.select()), 1)[0]
     response = self._my_app.get("/authoredit", {"id": random_item.id})
     code, error = tidylib.tidy_document(response.body,
                                         options={
                                             "show-errors": 1,
                                             "show-warnings": 0
                                         })
     self.assertFalse(error, "/authoredit did not return valid html page")
示例#10
0
 def authors(self, letter=None):
     alphabet = [
         "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
         "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
     ]
     the_authors = False
     if letter != None:
         if letter in alphabet:
             the_authors = Author.select(
                 """
             author.author_name RLIKE " %s[^ ]*$" AND
                book.title_id=title.id AND
                book.status ='STOCK' AND
                author.id= author_title.author_id AND
                author_title.title_id=title.id""" % (escape_string(letter)),
                 orderBy="author_name",
                 clauseTables=['book', 'title', 'author_title'],
                 distinct=True)
         else:
             the_authors = Author.select("""
             author.author_name NOT RLIKE "^[:alpha:]" AND
                book.title_id=title.id AND
                book.status ='STOCK' AND
                author.id=author_title.author_id AND
                author_title.title_id=title.id""",
                                         orderBy="author_name",
                                         clauseTables=['book', 'title'],
                                         distinct=True)
         authors_for_letter = list(unique(the_authors))
         authors_for_letter.sort(sort_by_last_name)
         return dict(authorswidget=AuthorsWidget(),
                     titlelistwidget=TitleListWidget(),
                     the_authors=authors_for_letter,
                     the_letter=letter,
                     alphabet=alphabet)
     else:
         return dict(authorswidget=AuthorsWidget(),
                     titlelistwidget=TitleListWidget(),
                     the_authors=False,
                     the_letter=letter,
                     alphabet=alphabet)
示例#11
0
 def authors(self,letter=None):
     alphabet=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]      
     the_authors=False
     if letter != None:
         if letter in alphabet:
             the_authors=Author.select("""
             author.author_name RLIKE " %s[^ ]*$" AND
                book.title_id=title.id AND
                book.status ='STOCK' AND
                author.id= author_title.author_id AND
                author_title.title_id=title.id""" % (escape_string(letter)),orderBy="author_name",clauseTables=['book','title','author_title'],distinct=True)
         else:
             the_authors=Author.select("""
             author.author_name NOT RLIKE "^[:alpha:]" AND
                book.title_id=title.id AND
                book.status ='STOCK' AND
                author.id=author_title.author_id AND
                author_title.title_id=title.id""" ,orderBy="author_name",clauseTables=['book','title'],distinct=True)
         authors_for_letter=list(unique(the_authors))
         authors_for_letter.sort(sort_by_last_name)
         return dict(authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget(),the_authors=authors_for_letter,the_letter=letter,alphabet=alphabet)
     else:
         return dict(authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget(),the_authors=False,the_letter=letter,alphabet=alphabet)
示例#12
0
    def author(self, id):
        the_author = Author.get(id)
        the_titles = Title.select(
            """
	    book.title_id=title.id AND
            book.status ='STOCK' AND
            author.id=author_title.author_id AND
            author_title.title_id=title.id AND author.author_name='%s'
            """ % (escape_string(the_author.author_name)),
            orderBy="booktitle",
            clauseTables=['book', 'author', 'author_title'],
            distinct=True)
        return dict(the_titles=the_titles,
                    the_author=the_author,
                    authorswidget=AuthorsWidget(),
                    titlelistwidget=TitleListWidget())
示例#13
0
    def addToInventory(self,title="",status="STOCK",authors=[],publisher="",listprice="",ourprice='',isbn="",categories=[],distributor="",location="",owner="",notes="",quantity=1,known_title=False,types='',kind_name="",kind=default_kind, extra_prices={}, tag='', num_copies=0, printlabel=False):
        print "GOT to addToInventory"
        if not(known_title):
            print "unknown title"
            #add a title
            the_kinds=list(Kind.select(Kind.q.kindName==kind))
            kind_id = None
            if the_kinds:
                kind_id = the_kinds[0].id
            print 'kind id is', kind_id

            #print title
            
            title=title
            publisher=publisher
            #print title, publisher
            known_title=Title(isbn=isbn, booktitle=title, publisher=publisher,tag=" ",type=types, kindID=kind_id)
            print known_title
            for rawAuthor in authors:
                author = rawAuthor.encode("utf8", "backslashreplace")
            theAuthors = Author.selectBy(authorName=author)
            theAuthorsList = list(theAuthors)
            if len(theAuthorsList) == 1:
                known_title.addAuthor(theAuthorsList[0])
            elif len(theAuthorsList) == 0:
                a = Author(authorName=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("utf8", "backslashreplace"),title=known_title)
        the_locations=list(Location.select(Location.q.locationName==location))
        location_id=1
        if the_locations:
            location_id = the_locations[0].id
        if not ourprice:
            ourprice=listprice
        for i in range(int(quantity)): 
            #print "book loop"
            b=Book(title=known_title,status=status.encode("utf8", "backslashreplace"), distributor=distributor.encode('ascii', "backslashreplace"),listprice=listprice, ourprice=ourprice, location=location_id,owner=owner.encode("utf8", "backslashreplace"),notes=notes.encode("utf8", "backslashreplace"),consignmentStatus="")
示例#14
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])
示例#15
0
 def authoredit(self, **args):
     self.common()
     self._authoredittemplate.author = Author.form_to_object(Author, args)
     return self._authoredittemplate.respond()
示例#16
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])
示例#17
0
def addToInventory(
    title="",
    status="STOCK",
    authors=None,
    publisher="",
    listprice="",
    ourprice="",
    isbn="",
    orig_isbn="",
    categories=[],
    distributor="",
    location="",
    location_id="",
    large_url="",
    med_url="",
    small_url="",
    owner="",
    notes="",
    quantity=1,
    known_title=False,
    types="",
    kind_name="",
    kind=default_kind,
    extra_prices={},
    tag="",
    labels_per_copy=1,
    printlabel=False,
    special_orders=0,
):
    print("GOT to addToInventory", file=sys.stderr)
    if not authors:
        authors = []
    if known_title:
        print("known_title ", known_title, file=sys.stderr)
        if not known_title.booktitle:
            known_title.booktitle = title
        if not known_title.publisher:
            known_title.publisher = publisher
        if not known_title.type:
            known_title.type = types
    elif not (known_title):
        print("unknown title", file=sys.stderr)
        # add a title
        the_kinds = list(Kind.select(Kind.q.kindName == kind))
        kind_id = None
        if the_kinds:
            kind_id = the_kinds[0].id
        print("kind id is", kind_id, file=sys.stderr)

        # print>>sys.stderr, title

        title = title
        publisher = publisher
        # print>>sys.stderr, title, publisher
        known_title = Title(
            isbn=isbn,
            origIsbn=orig_isbn,
            booktitle=title,
            publisher=publisher,
            tag=" ",
            type=types,
            kindID=kind_id,
        )
        print(known_title, file=sys.stderr)

        im = Images(
            titleID=known_title.id,
            largeUrl=large_url,
            medUrl=med_url,
            smallUrl=small_url,
        )
        print(im, file=sys.stderr)

        for rawAuthor in authors:
            author = rawAuthor
            theAuthors = Author.selectBy(authorName=author)
            theAuthorsList = list(theAuthors)
            if len(theAuthorsList) == 1:
                known_title.addAuthor(theAuthorsList[0])
            elif len(theAuthorsList) == 0:
                a = Author(authorName=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...",
                    file=sys.stderr,
                )
        for category in categories:
            Category(categoryName=category, title=known_title)
    # the_locations=list(Location.select(Location.q.locationName==location))
    # location_id=1
    # if the_locations:
    #    location_id = the_locations[0].id
    if not ourprice:
        ourprice = listprice
    print("about to enter book loop", file=sys.stderr)
    print("location is", location, file=sys.stderr)
    print("location_id is", location_id, file=sys.stderr)
    for i in range(int(quantity)):
        print("book loop", file=sys.stderr)
        b = Book(
            title=known_title,
            status=status,
            distributor=distributor,
            listprice=listprice,
            ourprice=ourprice,
            location=int(location_id),
            owner=owner,
            notes=notes,
            consignmentStatus="",
        )
示例#18
0
 def test_authoredit_functional(self):
     random_item=random.sample(list(Author.select()), 1)[0]
     response=self._my_app.get('/authoredit', {'id':random_item.id})
     code, error=tidylib.tidy_document(response.body, options={'show-errors':1, 'show-warnings':0})
     self.assertFalse(error, '/authoredit did not return valid html page')
示例#19
0
    def OnGetAuthors(self, authors):
    	authorstring=Author.get(authors.pop(0)).author_name.decode("string_escape")
	for author in authors:
	    # we make a string !
	    authorstring = authorstring + "," + Author.get(author).author_name.decode("string_escape")
	self.author.SetValue(authorstring)
示例#20
0
 def authoredit(self,**args):
     self.common()
     self._authoredittemplate.author=Author.form_to_object(Author,args)
     return self._authoredittemplate.respond()