コード例 #1
0
ファイル: server.py プロジェクト: aliceriot/infoshopkeeper
    def titlelist(self,**args):
        self.common()
        self._titlelisttemplate.titles=[]
        try:
            if type(args['titles']) == type("string"):
                self._titlelisttemplate.titles.append(Title.get(args['titles']))
            else:
                for id in args['titles']:
                    self._titlelisttemplate.titles.append(Title.get(id))
        except KeyError:
            pass

        try: 
            if (args['delete']):
            #delete the titles
                for title in self._titlelisttemplate.titles:
#                    for author in title.author:
#                        Author.delete(author.id)
                    for book in title.books:
                        Book.delete(book.id)
                    for category in title.categorys:
                        Category.delete(category.id)
                    
                    Title.delete(title.id)

            #and back to the search
                from cherrypy.lib import httptools
                httptools.redirect(cherrypy.session['lastsearch'])	
        except:
            return self._titlelisttemplate.respond()
コード例 #2
0
    def unconfirmed(self, letter=""):
        all_titles = []
        if letter == "":
            all_titles = Title.select("kind_id=1", orderBy='booktitle')
        else:
            all_titles = Title.select(
                """kind_id=1 and booktitle LIKE '%s%%'""" %
                (escape_string(letter)),
                orderBy='booktitle')
        unconfirmed_titles = []
        for t in all_titles:
            if t.copies_in_status(
                    'STOCK') > 0:  # or t.copies_in_status('UNKNOWN')>0:
                t.unconfirmed_books = []
                for b in [
                        b for b in t.books
                        if (b.status == 'STOCK' or b.status == 'UNKNOWN')
                ]:
                    tags = b.get_tags(
                        'inventory',
                        'confirmation11')  #needs a date eventually!
                    if len(tags) == 0:
                        t.unconfirmed_books.append(b)
                if len(t.unconfirmed_books) > 0:
                    unconfirmed_titles.append(t)

        return dict(titles=unconfirmed_titles)
コード例 #3
0
 def titles(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_titles = False
     if letter != None:
         if letter in alphabet:
             the_titles = Title.select("""
                title.booktitle LIKE "%s%%" AND
                book.title_id=title.id AND
                book.status ='STOCK' """ % (escape_string(letter)),
                                       orderBy="booktitle",
                                       clauseTables=['book'],
                                       distinct=True)
         else:
             the_titles = Title.select("""
                title.booktitle RLIKE "^[0-9]" AND
                book.title_id=title.id AND
                book.status ='STOCK' """,
                                       orderBy="booktitle",
                                       clauseTables=['book'],
                                       distinct=True)
         return dict(authorswidget=AuthorsWidget(),
                     titlelistwidget=TitleListWidget(),
                     the_titles=the_titles,
                     the_letter=letter,
                     alphabet=alphabet)
     else:
         return dict(authorswidget=AuthorsWidget(),
                     titlelistwidget=TitleListWidget(),
                     the_titles=False,
                     the_letter=letter,
                     alphabet=alphabet)
コード例 #4
0
ファイル: server.py プロジェクト: truonghn/infoshopkeeper
    def titlelist(self, **args):
        self.common()
        self._titlelisttemplate.titles = []
        try:
            if type(args['titles']) == type("string"):
                self._titlelisttemplate.titles.append(Title.get(
                    args['titles']))
            else:
                for id in args['titles']:
                    self._titlelisttemplate.titles.append(Title.get(id))
        except KeyError:
            pass

        try:
            if (args['delete']):
                #delete the titles
                for title in self._titlelisttemplate.titles:
                    #                    for author in title.author:
                    #                        Author.delete(author.id)
                    for book in title.books:
                        Book.delete(book.id)
                    for category in title.categorys:
                        Category.delete(category.id)

                    Title.delete(title.id)

            #and back to the search
                from cherrypy.lib import httptools
                httptools.redirect(cherrypy.session['lastsearch'])
        except:
            return self._titlelisttemplate.respond()
コード例 #5
0
    def storefront(self):
        searchform = widgets.TableForm(fields=SearchFields(),
                                       submit_text="Search!")
        conn = db.connect()
        cursor = conn.cursor()
        cursor.execute("""
        select booktitle,count(book.id) as blah,title_id   from book,title where book.title_id=title.id and book.status='SOLD' and title.kind_id=1 group by title_id order by blah desc limit 30
        """)
        results = cursor.fetchall()
        cursor.close()

        best_sellers = [
            Title.get(x[2]) for x in results
            if Title.get(x[2]).copies_in_status("STOCK") > 0
        ]

        new_titles = Title.select("""
            book.title_id=title.id AND
            book.status ='STOCK'
            """,
                                  orderBy="-title.id",
                                  clauseTables=['book'],
                                  distinct=True)
        return dict(authorswidget=AuthorsWidget(),
                    titlelistwidget=TitleListWidget(),
                    searchform=searchform,
                    new_titles=new_titles[:10],
                    best_sellers=best_sellers)
コード例 #6
0
    def title(self, id):
        ratingsform = widgets.RemoteForm(fields=RatingFields(),
                                         submit_text="Rate it!")
        #        Title.sqlmeta.addJoin(MultipleJoin('Rating',joinMethodName='ratings'))
        thetitle = Title.get(id)
        thetitle.ratings = []
        same_author = []
        for author in thetitle.author:
            titles = Title.select(
                """
            title.id!=%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 AND author.author_name='%s'
            """ % (escape_string(
                    "%s" % thetitle.id), escape_string(author.author_name)),
                orderBy="booktitle",
                clauseTables=['book', 'author', 'author_title'],
                distinct=True)
            for title in titles:
                same_author.append(title)
        if thetitle.copies_in_status("STOCK") == 0:
            raise HTTPError(404)

        return dict(thetitle=thetitle,
                    authorswidget=AuthorsWidget(),
                    ratingsform=ratingsform,
                    titlelistwidget=TitleListWidget(),
                    same_author=same_author)
コード例 #7
0
 def uncategorized(self,letter=""):
     all_titles=[]
     if letter=="":
         all_titles=Title.select("kind_id=1",orderBy='booktitle')
     else:
         all_titles=Title.select("""kind_id=1 and booktitle LIKE '%s%%'""" % (escape_string(letter)),orderBy='booktitle')
                 
     return dict(titles=[t for t in all_titles if len(list(t.sections))==0])
コード例 #8
0
 def outofstock(self,letter=""):
     all_titles=[]
     if letter=="":
         all_titles=Title.select("kind_id=1",orderBy='booktitle')
     else:
         all_titles=Title.select("""kind_id=1 and booktitle LIKE '%s%%'""" % (escape_string(letter)),orderBy='booktitle')
                 
     return dict(titles=[t for t in all_titles if t.copies_in_status("STOCK")==0])
コード例 #9
0
    def outofstock(self, letter=""):
        all_titles = []
        if letter == "":
            all_titles = Title.select("kind_id=1", orderBy='booktitle')
        else:
            all_titles = Title.select(
                """kind_id=1 and booktitle LIKE '%s%%'""" %
                (escape_string(letter)),
                orderBy='booktitle')

        return dict(
            titles=[t for t in all_titles if t.copies_in_status("STOCK") == 0])
コード例 #10
0
    def uncategorized(self, letter=""):
        all_titles = []
        if letter == "":
            all_titles = Title.select("kind_id=1", orderBy='booktitle')
        else:
            all_titles = Title.select(
                """kind_id=1 and booktitle LIKE '%s%%'""" %
                (escape_string(letter)),
                orderBy='booktitle')

        return dict(
            titles=[t for t in all_titles if len(list(t.sections)) == 0])
コード例 #11
0
    def _read_inp_file(self):
        '''
        Reads the SWMM .inp file and records the sections

        Returns
        -------
        None.
        '''

        # list of swmm elements
        swmm_elements = [Title(),
                        Options(),
                        Files()]

        # create a new attribute when a section has been located
        with open(self.inp_file, 'r') as inp_file:
            for line in inp_file:
                for element in swmm_elements:
                    if element.has_reached_section(line):
                        line = element.temp_read_params(inp_file)

                        # use the element type to designate the new attribute
                        if isinstance(element, Title) = 'Title':
                            self.title = element
                        elif isinstance(element, Options) = 'Options':
                            self.options = element
                        elif isinstance(element, Files) = 'Files':
                            self.files = element

                        self._to_write.append(element)
                    else:
コード例 #12
0
def get_categories_from_amazon( category_missing=[]):
    for t in auth_missing:
        t1=Title.get(t)
        try:
            amazonIter=ItemLookup(t1.isbn, ResponseGroup="ItemAttributes, BrowseNodes")
            amazonResults=amazonIter.next()
            def parseBrowseNodes(bNodes):
                def parseBrowseNodesInner(item):
                    bn=set()
                    if hasattr(item, 'Name'):
                        bn.add(item.Name)
                    if hasattr(item, 'Ancestors'):
                        #print "hasansc"   
                        for i in item.Ancestors:
                            bn.update(parseBrowseNodesInner(i))
                    if hasattr(item, 'Children'):
                        for i in item.Children:
                            bn.update(parseBrowseNodesInner(i))
                            #print "bn ", bn
                    if not (hasattr(item, 'Ancestors') or hasattr(item, 'Children')):            
                        if hasattr(item, 'Name'):
                            return set([item.Name])
                        else:
                            return set()
                    return bn
                nodeslist=[parseBrowseNodesInner(i) for i in bNodes ]
                nodes=set()
                for n in nodeslist:
                    nodes = nodes.union(n)
                return nodes
            
            categories=parseBrowseNodes(b.BrowseNodes)
        except Exception as e:
            print e
コード例 #13
0
    def title(self, id, searchvalues=None):
        thetitle = Title.get(id)
        searchform = widgets.TableForm(fields=PrivateSearchFields(),
                                       submit_text="Search!")
        titleform = widgets.TableForm(
            name="titleform",
            fields=PrivateTitleFields(),
            submit_text="modify this title's sections and distributor")
        titlepersistenceform = widgets.TableForm(
            fields=PrivateTitlePersistenceFields(), submit_text="")
        persisting_sections = []
        #       try:
        #           persisting_sections=session['persisting_sections']
        #       except:
        #           session['persisting_sections']=[]
        #       print persisting_sections
        #        sections=list(set(thetitle.get_tag_collection(category='inventory',key='section')))
        #        sections=thetitle.sections
        #      sections.extend(persisting_sections)
        print[s.id for s in list(thetitle.sections)]

        return dict(thetitle=thetitle,
                    authorswidget=PrivateAuthorsWidget(),
                    searchform=searchform,
                    searchvalues=searchvalues,
                    titleform=titleform,
                    today=strftime("%Y-%m-%d", gmtime()),
                    titlepersistenceform=titlepersistenceform,
                    titlesections=[s.id for s in list(thetitle.sections)],
                    persisting_sections=persisting_sections)
コード例 #14
0
    def reinventory(self, isbn="", author="", title=""):
        searchform = widgets.TableForm(fields=PrivateSearchFields(),
                                       submit_text="Search!")
        if author == "" and title == "" and isbn == "":
            the_titles = False
        else:
            the_titles = Title.select("""
            title.isbn LIKE '%%%s%%' AND
            author.id=author_title.author_id AND
            author_title.title_id=title.id AND author.author_name LIKE '%%%s%%' AND title.booktitle LIKE '%%%s%%'
            """ % (escape_string(isbn), escape_string(author),
                   escape_string(title)),
                                      orderBy="booktitle",
                                      clauseTables=['author', 'author_title'],
                                      distinct=True)

        title_count = 0
        try:
            title_count = the_titles.count()
        except:
            pass
        if title_count > 0:
            if the_titles.count() == 1:
                return self.title(the_titles[0].id,
                                  searchvalues=dict(author=author,
                                                    title=title,
                                                    isbn=isbn))

        return dict(the_titles=the_titles,
                    authorswidget=PrivateAuthorsWidget(),
                    titlelistwidget=PrivateTitleListWidget(),
                    searchform=searchform,
                    values=dict(author=author, title=title, isbn=isbn))
コード例 #15
0
def do_easyselect_wizard(frame_object, event, label):
    wizard = EasySelectWizard(None, -1, label)
    wizard.label = label
    wizard.parent = frame_object
    if Kind.select(Kind.q.kindName == label).count() < 1:
        print "you probably need to add a kind to correspond to the label %s" % label

    title_list = Title.select(
        """
    title.kind_id= kind.id AND
    kind.kind_name='%s'
    """
        % (label),
        orderBy=Title.q.booktitle,
        clauseTables=["kind"],
        distinct=True,
    )

    # wizard.title_list=[t for t in title_list if len([b for b in t.books if b.status=="STOCK"])>0]
    wizard.title_list = title_list

    wizard.title_page = ChooseItemPage(wizard)
    wizard.GetPageAreaSizer().Add(wizard.title_page)
    wizard.action_page = ChooseActionPage(wizard)
    EVT_WIZARD_FINISHED(wizard, wizard.GetId(), wizard.finish)
    wizard.RunWizard(wizard.title_page)
    wizard.Destroy()
コード例 #16
0
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
コード例 #17
0
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)
コード例 #18
0
 def storefront(self):
     searchform = widgets.TableForm(fields=SearchFields(), submit_text="Search!")
     conn=db.connect()
     cursor=conn.cursor()
     cursor.execute("""
     select booktitle,count(book.id) as blah,title_id   from book,title where book.title_id=title.id and book.status='SOLD' and title.kind_id=1 group by title_id order by blah desc limit 30
     """)
     results= cursor.fetchall()
     cursor.close()
     
     best_sellers = [Title.get(x[2]) for x in results if Title.get(x[2]).copies_in_status("STOCK")>0]
     
     new_titles=Title.select("""
         book.title_id=title.id AND
         book.status ='STOCK'
         """ ,orderBy="-title.id",clauseTables=['book'],distinct=True)
     return dict(authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget(),searchform=searchform,new_titles=new_titles[:10],best_sellers=best_sellers)
コード例 #19
0
 def test_search_isbn_that_we_have_unit(self):
     random_item = random.sample(list(Title.select()), 1)[0]
     result = self._my_class.search_isbn(**{"isbn": random_item.isbn})[0]
     self.assertEqual(
         result["isbn"],
         random_item.isbn,
         "method search_isbn doesn't return proper item for isbn10",
     )
コード例 #20
0
 def test_lookup_by_orig_isbn_is_invalid(self):
     random_item = random.sample(list(Title.select("isbn RLIKE '^[0-9]{13}$'")), 1)[
         0
     ]
     wrong_isbn = random_item.isbn[0:12] + str((int(random_item.isbn[12]) + 1) % 10)
     print(random_item.isbn, wrong_isbn)
     with self.assertRaises((isbnlib.NotValidISBNError, isbnlib._exceptions.NotValidISBNError)):
         inventory.lookup_by_isbn(wrong_isbn)
コード例 #21
0
 def titles(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_titles=False
     if letter != None:
         if letter in alphabet:
             the_titles=Title.select("""
                title.booktitle LIKE "%s%%" AND
                book.title_id=title.id AND
                book.status ='STOCK' """ % (escape_string(letter)),orderBy="booktitle",clauseTables=['book'],distinct=True)
         else:
             the_titles=Title.select("""
                title.booktitle RLIKE "^[0-9]" AND
                book.title_id=title.id AND
                book.status ='STOCK' """ ,orderBy="booktitle",clauseTables=['book'],distinct=True)
         return dict(authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget(),the_titles=the_titles,the_letter=letter,alphabet=alphabet)
     else:
         return dict(authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget(),the_titles=False,the_letter=letter,alphabet=alphabet)
コード例 #22
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())
コード例 #23
0
 def unconfirmed(self,letter=""):
     all_titles=[]
     if letter=="":
         all_titles=Title.select("kind_id=1",orderBy='booktitle')
     else:
         all_titles=Title.select("""kind_id=1 and booktitle LIKE '%s%%'""" % (escape_string(letter)),orderBy='booktitle')
     unconfirmed_titles=[]
     for t in all_titles:
         if t.copies_in_status('STOCK')>0:# or t.copies_in_status('UNKNOWN')>0:
             t.unconfirmed_books=[]
             for b in [b for b in t.books if (b.status=='STOCK' or b.status=='UNKNOWN')]:
                 tags=b.get_tags('inventory','confirmation11')  #needs a date eventually!
                 if len(tags)==0:
                     t.unconfirmed_books.append(b)
             if len(t.unconfirmed_books)>0:
                 unconfirmed_titles.append(t)
                 
     return dict(titles=unconfirmed_titles)
コード例 #24
0
 def test_titleedit_functional(self):
     random_item = random.sample(list(Title.select()), 1)[0]
     response = self._my_app.get("/titleedit", {"id": random_item.id})
     code, error = tidylib.tidy_document(response.body,
                                         options={
                                             "show-errors": 1,
                                             "show-warnings": 0
                                         })
     self.assertFalse(error, "/titleedit did not return valid html page")
コード例 #25
0
 def test_print_label_unit(self):
     random_item = random.sample(
         list(Title.select('WHERE title.isbn RLIKE "^978"')), 1)[0]
     result = self._my_class.print_label(
         isbn=random_item.isbn,
         booktitle=random_item.booktitle,
         authorstring=random_item.authors_as_string(),
     )
     self.assertIsNone(result, "print_label doesn't return")
コード例 #26
0
 def test_search_isbn_that_we_dont_have_functional(self):
     random_item = random.sample(list(Title.select()), 1)[0]
     response = self._my_app.get("/admin/search_isbn", {
         "isbn": random_item.isbn
     }).json[0]
     self.assertEqual(
         response["isbn"],
         random_item.isbn,
         "/admin/search_isbn doesn't return proper item for isbn10",
     )
コード例 #27
0
 def test_lookup_by_orig_isbn_is_valid(self):
     random_item = random.sample(list(Title.select("isbn RLIKE '^[0-9]{13}$'")), 1)[
         0
     ]
     result = inventory.lookup_by_isbn(random_item.isbn)
     self.assertEqual(
         random_item.isbn,
         result["isbn"],
         "inventory.lookup_by_isbn returned wrong isbn for random isbn in database",
     )
コード例 #28
0
 def test_lookup_by_isbn_is_wsr(self):
     random_item = random.sample(
         list(Title.select("isbn RLIKE 'wsr [0-9]{3,5}'")), 1
     )[0]
     result = inventory.lookup_by_isbn(random_item.isbn)
     self.assertEqual(
         random_item.isbn,
         result["isbn"],
         "inventory.lookup_by_isbn returned wrong isbn for random isbn (wsr) in database",
     )
コード例 #29
0
    def title(self,id):
        ratingsform = widgets.RemoteForm(fields=RatingFields(), submit_text="Rate it!")
#        Title.sqlmeta.addJoin(MultipleJoin('Rating',joinMethodName='ratings'))
        thetitle=Title.get(id)
        thetitle.ratings=[]
        same_author=[]
        for author in thetitle.author:
            titles=Title.select("""
            title.id!=%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 AND author.author_name='%s'
            """ % (escape_string("%s" % thetitle.id),escape_string(author.author_name)),orderBy="booktitle",clauseTables=['book','author','author_title'],distinct=True)
            for title in titles:
	    	same_author.append(title)
        if thetitle.copies_in_status("STOCK")==0:
            raise HTTPError(404)
        
        return dict(thetitle=thetitle,authorswidget=AuthorsWidget(),ratingsform=ratingsform,titlelistwidget=TitleListWidget(),same_author=same_author)
コード例 #30
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="")
コード例 #31
0
    def search(self,author="",title=""):
        searchform = widgets.TableForm(fields=SearchFields(), submit_text="Search!")
        if author == "" and title=="":
            the_titles=False
        else:
            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 LIKE '%%%s%%' AND title.booktitle LIKE '%%%s%%'
            """ % (escape_string(author),escape_string(title)),orderBy="booktitle",clauseTables=['book','author','author_title'],distinct=True)
	return dict(the_titles=the_titles,authorswidget=AuthorsWidget(),titlelistwidget=TitleListWidget(),searchform=searchform,values=dict(author=author,title=title))
コード例 #32
0
 def test_select_item_for_isbn_search_functional(self):
     random_item = random.sample(list(Title.select()), 1)[0]
     response = self._my_app.get("/admin/select_item_for_isbn_search",
                                 {"isbn": random_item.isbn})
     code, error = tidylib.tidy_document(response.body,
                                         options={
                                             "show-errors": 1,
                                             "show-warnings": 0
                                         })
     self.assertFalse(
         error,
         "/admin/select_item_for_isbn_search did not return proper response"
     )
コード例 #33
0
 def test_print_label_functional(self):
     random_item = random.sample(
         list(Title.select('WHERE title.isbn RLIKE "^978"')), 1)[0]
     response = self._my_app.post(
         "/admin/print_label",
         {
             "isbn": random_item.isbn,
             "booktitle": random_item.booktitle,
             "authorstring": random_item.authors_as_string(),
         },
     )
     print(response)
     self.assertIsNone(response, "print_label doesn't return")
コード例 #34
0
ファイル: inventory.py プロジェクト: aliceriot/infoshopkeeper
    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])
コード例 #35
0
 def title(self,id,searchvalues=None):
     thetitle=Title.get(id)
     searchform = widgets.TableForm(fields=PrivateSearchFields(), submit_text="Search!")
     titleform = widgets.TableForm(name="titleform",fields=PrivateTitleFields(), submit_text="modify this title's sections and distributor")
     titlepersistenceform = widgets.TableForm(fields=PrivateTitlePersistenceFields(), submit_text="")
     persisting_sections=[]
     #       try:
     #           persisting_sections=session['persisting_sections']
     #       except:
     #           session['persisting_sections']=[]
     #       print persisting_sections 
     #        sections=list(set(thetitle.get_tag_collection(category='inventory',key='section')))
     #        sections=thetitle.sections
     #      sections.extend(persisting_sections)
     print [s.id for s in list(thetitle.sections)]
コード例 #36
0
    def query(self,args):
        self.cursor=self.conn.cursor()
        self.cursor.execute("""
        select booktitle,count(book.id) as blah,publisher,title.id  from book,title where book.title_id=title.id and book.status='SOLD' and title.kind_id=%s group by title_id order by blah desc limit 500
        """,(args['kind']))
        results_pre_distributor= self.cursor.fetchall()
        self.cursor.close()
	results=[]
	for r in results_pre_distributor:
	    title=Title.get(r[3])
	    rl=list(r)
	    rl.append(title.distributors_as_string())
	    results.append(rl)	    

        return results
コード例 #37
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())
コード例 #38
0
 def test_lookup_by_orig_isbn_has_extra_hyphens(self):
     random_item = random.sample(list(Title.select("isbn RLIKE '^[0-9]{13}$'")), 1)[
         0
     ]
     prepared_isbn = (
         random_item.isbn[0:3]
         + "-"
         + random_item.isbn[3:8]
         + "-"
         + random_item.isbn[8:]
     )
     result = inventory.lookup_by_isbn(prepared_isbn)
     self.assertEqual(
         random_item.isbn,
         result["isbn"],
         "inventory.lookup_by_isbn returned wrong isbn for random isbn in database",
     )
コード例 #39
0
 def edit_title(self,title_id,**kw):
     title=Title.get(title_id)
     if kw['preferred_distributor']:
         title.set_unique_tag(category='distribution',key='preferred',value=kw['preferred_distributor'])
     if kw.has_key('sections'):
         the_sections=kw['sections']
         if type(the_sections) != type([0,1]):
             the_sections=[the_sections]
         #title.set_tag_collection(category='inventory',key='section',values=the_sections)
         for s in title.sections:
             print "Removing %s" % s 
             title.removeSection(s)
         for s in the_sections:
             print "Adding %s" % s 
             title.addSection(Section.get(s))
         
     return self.title(title_id)
コード例 #40
0
 def test_lookup_by_isbn10_is_invalid(self):
     # translation table of checkdigits to wrong ones (digit plus 1)
     tr_table = dict(
         list(
             zip(
                 ["x", "X"] + list(map(str, list(range(9, -1, -1)))),
                 ["0", "0", "x"] + list(map(str, list(range(9, 0, -1)))),
             )
         )
     )
     random_item = random.sample(list(Title.select("isbn RLIKE '^[0-9]{13}$'")), 1)[
         0
     ]
     wrong_isbn = isbnlib.to_isbn10(random_item.isbn)
     wrong_isbn = wrong_isbn[0:9] + tr_table[wrong_isbn[9]]
     with self.assertRaises((isbnlib.NotValidISBNError, isbnlib._exceptions.NotValidISBNError)):
         result = inventory.lookup_by_isbn(wrong_isbn)
コード例 #41
0
 def test_select_item_for_isbn_search_unit(self):
     random_item = random.sample(list(Title.select()), 1)[0]
     code, error = tidylib.tidy_document(
         self._my_class.select_item_for_isbn_search(
             isbn=random_item.isbn,
             title=random_item.booktitle,
             author=random_item.authors_as_string(),
         ),
         options={
             "show-errors": 1,
             "show-warnings": 0
         },
     )
     self.assertEqual(
         error,
         "",
         "InventoryServer.select_item_for_isbn_search did not return proper response",
     )
コード例 #42
0
    def edit_title(self, title_id, **kw):
        title = Title.get(title_id)
        if kw['preferred_distributor']:
            title.set_unique_tag(category='distribution',
                                 key='preferred',
                                 value=kw['preferred_distributor'])
        if kw.has_key('sections'):
            the_sections = kw['sections']
            if type(the_sections) != type([0, 1]):
                the_sections = [the_sections]
            #title.set_tag_collection(category='inventory',key='section',values=the_sections)
            for s in title.sections:
                print "Removing %s" % s
                title.removeSection(s)
            for s in the_sections:
                print "Adding %s" % s
                title.addSection(Section.get(s))

        return self.title(title_id)
コード例 #43
0
ファイル: wizards.py プロジェクト: aliceriot/infoshopkeeper
 def do_edition_wizard(self, frame_object,event,label):
     wizard = EditionWizard (None, -1, label)
     wizard.label=label
     wizard.parent=frame_object
     if Kind.select(Kind.q.kindName==label).count()<1:
         print 'you probably need to add a kind to correspond to the label %s' % label
     wizard.editions=[]
     wizard.title_list=Title.select("""
     title.kind_id= kind.id AND
     kind.kind_name='%s'
     """ % (label),orderBy=Title.q.booktitle,clauseTables=['kind'],distinct=True)
 
     wizard.title_page = ChooseItemPage ( wizard )
     wizard.GetPageAreaSizer().Add(wizard.title_page)
     wizard.edition_page=ChooseEditionPage(wizard)
     wizard.action_page=ChooseActionPage(wizard)
     EVT_WIZARD_FINISHED(wizard,wizard.GetId(), wizard.finish)
     wizard.RunWizard ( wizard.title_page )
     wizard.Destroy()
コード例 #44
0
    def search(self, author="", title=""):
        searchform = widgets.TableForm(fields=SearchFields(),
                                       submit_text="Search!")
        if author == "" and title == "":
            the_titles = False
        else:
            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 LIKE '%%%s%%' AND title.booktitle LIKE '%%%s%%'
            """ % (escape_string(author), escape_string(title)),
                orderBy="booktitle",
                clauseTables=['book', 'author', 'author_title'],
                distinct=True)
        return dict(the_titles=the_titles,
                    authorswidget=AuthorsWidget(),
                    titlelistwidget=TitleListWidget(),
                    searchform=searchform,
                    values=dict(author=author, title=title))
コード例 #45
0
    def reinventory(self,isbn="",author="",title=""):
        searchform = widgets.TableForm(fields=PrivateSearchFields(), submit_text="Search!")
        if author == "" and title=="" and isbn=="":
            the_titles=False
        else:
            the_titles=Title.select("""
            title.isbn LIKE '%%%s%%' AND
            author.id=author_title.author_id AND
            author_title.title_id=title.id AND author.author_name LIKE '%%%s%%' AND title.booktitle LIKE '%%%s%%'
            """ % (escape_string(isbn),escape_string(author),escape_string(title)),orderBy="booktitle",clauseTables=['author','author_title'],distinct=True)
		
	title_count=0
	try:
		title_count=the_titles.count()
	except:
		pass
        if title_count>0:
            if the_titles.count()==1:
                return self.title(the_titles[0].id,searchvalues=dict(author=author,title=title,isbn=isbn))

        return dict(the_titles=the_titles,authorswidget=PrivateAuthorsWidget(),titlelistwidget=PrivateTitleListWidget(),searchform=searchform,values=dict(author=author,title=title,isbn=isbn))
コード例 #46
0
def get_categories_from_amazon(category_missing=None):
    if not category_missing:
        category_missing = []
    for t in auth_missing:
        t1 = Title.get(t)
        try:
            amazonIter = ItemLookup(
                t1.isbn, ResponseGroup="ItemAttributes, BrowseNodes")
            amazonResults = next(amazonIter)

            def parseBrowseNodes(bNodes):
                def parseBrowseNodesInner(item):
                    bn = set()
                    if hasattr(item, "Name"):
                        bn.add(item.Name)
                    if hasattr(item, "Ancestors"):
                        # print "hasansc"
                        for i in item.Ancestors:
                            bn.update(parseBrowseNodesInner(i))
                    if hasattr(item, "Children"):
                        for i in item.Children:
                            bn.update(parseBrowseNodesInner(i))
                            # print "bn ", bn
                    if not (hasattr(item, "Ancestors")
                            or hasattr(item, "Children")):
                        if hasattr(item, "Name"):
                            return set([item.Name])
                        else:
                            return set()
                    return bn

                nodeslist = [parseBrowseNodesInner(i) for i in bNodes]
                nodes = set()
                for n in nodeslist:
                    nodes = nodes.union(n)
                return nodes

            categories = parseBrowseNodes(b.BrowseNodes)
        except Exception as e:
            print(e)
コード例 #47
0
    def do_edition_wizard(self, frame_object, event, label):
        wizard = EditionWizard(None, -1, label)
        wizard.label = label
        wizard.parent = frame_object
        if Kind.select(Kind.q.kindName == label).count() < 1:
            print 'you probably need to add a kind to correspond to the label %s' % label
        wizard.editions = []
        wizard.title_list = Title.select("""
        title.kind_id= kind.id AND
        kind.kind_name='%s'
        """ % (label),
                                         orderBy=Title.q.booktitle,
                                         clauseTables=['kind'],
                                         distinct=True)

        wizard.title_page = ChooseItemPage(wizard)
        wizard.GetPageAreaSizer().Add(wizard.title_page)
        wizard.edition_page = ChooseEditionPage(wizard)
        wizard.action_page = ChooseActionPage(wizard)
        EVT_WIZARD_FINISHED(wizard, wizard.GetId(), wizard.finish)
        wizard.RunWizard(wizard.title_page)
        wizard.Destroy()
コード例 #48
0
    def database_gen(authorOrTitle=""):
        titles = []

        # start out with the join clauses in the where clause list
        where_clause_list = []
        clause_tables = ["book", "author", "author_title"]
        join_list = [
            LEFTJOINOn("title", "book", "book.title_id=title.id"),
            LEFTJOINOn(None, "author_title", "title.id=author_title.title_id"),
            LEFTJOINOn(None, "author", "author.id=author_title.author_id"),
        ]

        # add filter clauses if they are called for
        where_clause_list.append(
            "(author.author_name RLIKE '%s' OR title.booktitle RLIKE '%s')"
            % (authorOrTitle.strip(), authorOrTitle.strip())
        )
        # AND all where clauses together
        where_clause = AND(where_clause_list)
        titles = []

        # do search.
        titles = Title.select(
            where_clause, join=join_list, clauseTables=clause_tables, distinct=True
        )
        for t1 in titles:
            yield {
                "title": t1.booktitle,
                "authors": t1.author,
                "authors_as_string": t1.authors_as_string(),
                "categories_as_string": t1.categories_as_string(),
                "list_price": t1.highest_price_book().ourprice,
                "publisher": t1.publisher,
                "isbn": t1.isbn,
                "format": t1.type,
                "kind": t1.kind.kindName,
                "known_title": t1,
            }
コード例 #49
0
    def lookup_by_isbn(self,number):
        isbn=""
        number=re.sub("^([\'\"])(.*)\\1$", '\\2', number)
        #print "number is now: ", number
        if len(number)>=9:
            number=re.sub("[-\s]", '', number)
        #print "number is now: ", number
        if len(number)==10 and isbnlib.isValid(number):
            isbn=isbnlib.convert(number)

        else:
            isbn=number
        #print "NUMBER was " +number+ ",ISBN was "+isbn
        if (len(isbn)>0 and not re.match('^n(\s|/){0,1}a|none', isbn, re.I)):
            #first we check our database
            titles =  Title.select(Title.q.isbn==isbn)
            #print titles #debug
            self.known_title= False
            the_titles=list(titles)
            if len(the_titles) > 0:
                #print "in titles"
                self.known_title= the_titles[0]
                ProductName = the_titles[0].booktitle.format()
                authors=[]
                if len(the_titles[0].author) > 0:
                    authors = [x.authorName.format() for x in the_titles[0].author]
                authors_as_string = string.join(authors,',')
                categories=[]
                if len(the_titles[0].categorys) > 0:
                    #print len(the_titles[0].categorys)
                    #print the_titles[0].categorys
                    categories = [x.categoryName.format() for x in the_titles[0].categorys] 
                categories_as_string = string.join(categories,',')
                if len(the_titles[0].books) > 0:
                    ListPrice = the_titles[0].books[0].listprice
                else:
                    ListPrice = 0
                Manufacturer = the_titles[0].publisher.format()
                Format=the_titles[0].type.format()
                Kind=the_titles[0].kind.kindName
                return {"title":ProductName,
                    "authors":authors,
                    "authors_as_string":authors_as_string,
                    "categories_as_string":categories_as_string,
                    "list_price":ListPrice,
                    "publisher":Manufacturer,
                    "isbn":isbn,
                    "format":Format,
                    "kind":Kind,
                    "known_title": self.known_title}
            else: #we don't have it yet
                #print "in isbn"
                sleep(1) # so amazon doesn't get huffy 
                ecs.setLicenseKey(amazon_license_key)
                ecs.setSecretAccessKey(amazon_secret_key)
                ecs.setAssociateTag(amazon_associate_tag)
                
                #print "about to search", isbn, isbn[0]
                pythonBooks=[]
                try:
                    pythonBooks = ecs.ItemLookup(isbn,IdType="ISBN",SearchIndex="Books",ResponseGroup="ItemAttributes,BrowseNodes")
                except ecs.InvalidParameterValue:
                    pass
                #print pythonBooks
                if pythonBooks:
                    result={}
                    authors=[]
                    categories=[]
                    b=pythonBooks[0]

                    for x in ['Author','Creator']:
                        if hasattr(b,x):
                            if type(getattr(b,x))==type([]):
                                authors.extend(getattr(b,x))
                            else:
                                authors.append(getattr(b,x))
                    

                    authors_as_string = string.join(authors,',')
 
                    categories_as_string =""
                    
                    # a bit more complicated of a tree walk than it needs be.
                    # set up to still have the option of category strings like "history -- us"
                    # switched to sets to quickly remove redundancies.
                    def parseBrowseNodes(bNodes):
                        def parseBrowseNodesInner(item):
                            bn=set()
                            if hasattr(item, 'Name'):
                                bn.add(item.Name)
                            if hasattr(item, 'Ancestors'):
                                #print "hasansc"   
                                for i in item.Ancestors:
                                    bn.update(parseBrowseNodesInner(i))
                            if hasattr(item, 'Children'):
                                for i in item.Children:
                                    bn.update(parseBrowseNodesInner(i))
                                    #print "bn ", bn
                            if not (hasattr(item, 'Ancestors') or hasattr(item, 'Children')):            
                                if hasattr(item, 'Name'):
                                    return set([item.Name])
                                else:
                                    return set()
                            return bn
                        nodeslist=[parseBrowseNodesInner(i) for i in bNodes ]
                        nodes=set()
                        for n in nodeslist:
                            nodes = nodes.union(n)
                        return nodes

                    categories=parseBrowseNodes(b.BrowseNodes)
                    categories_as_string = string.join(categories,',')                   

                    categories=parseBrowseNodes(b.BrowseNodes)
                    categories_as_string = string.join(categories,',')
                    #print categories, categories_as_string


                    ProductName=""
                    if hasattr(b,'Title'):
                        ProductName=b.Title

                        
                    Manufacturer=""
                    if hasattr(b,'Manufacturer'):
                        Manufacturer=b.Manufacturer

                    ListPrice=""
                    if hasattr(b,'ListPrice'):
                        ListPrice=b.ListPrice.FormattedPrice.replace("$",'')

                    Format=''
                    if hasattr(b, "Binding"):
                        Format=b.Binding
                    
                    Kind='books'
                    
                    return {"title":ProductName,
                        "authors":authors,
                        "authors_as_string":authors_as_string,
                        "categories_as_string":categories_as_string,
                        "list_price":ListPrice,
                        "publisher":Manufacturer,
                        "isbn":isbn,
                        "format":Format,
                        "kind":Kind,
                        "known_title": self.known_title}
                else:
                    return []
                
       
        else:
            return []
コード例 #50
0
 def test_lookup_by_isbn13_has_extra_hyphens(self):
     random_item=random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 1)[0]
     converted_isbn=isbn.convert(random_item.isbn)
     converted_isbn=converted_isbn[0:3]+'-'+converted_isbn[3:8]+'-'+converted_isbn[8:]
     result=inventory.lookup_by_isbn(converted_isbn)
     self.assertEqual(random_item.isbn, result['isbn'], 'inventory.lookup_by_isbn returned wrong isbn for random isbn in database')
コード例 #51
0
from sqlobject.sqlbuilder import RLIKE
from objects.title import Title

import lxml
from lxml import html, cssselect

import webtest
from wsgiapp_local import application


try:
    theapp=webtest.TestApp(application)
except:
    pass

titles=Title.select(RLIKE(Title.q.isbn, '^[0-9]{9}[0-9xX]$'))
titles_that_display, titles_that_dont_display, titles_that_dont_even_fetch=(0,[],[])

for title in titles:
    try:
        response=theapp.get('/search', {'id':title.id})
        lx_htm=lxml.html.fromstring(response.text)        
        if lx_htm.cssselect('tbody tr td').__len__() > 1:
            titles_that_display += 1
        else:
            titles_that_dont_display.append(title.id)
        
    except Exception as e:
        print e
        titles_that_dont_even_fetch.append(title.id)
print "Number of titles that don't fetch: ", titles_that_dont_even_fetch.__len__()
コード例 #52
0
    def lookup_by_upc(self,upc):

        if len(upc)>0:
            #first we check our database
            titles =  Title.select(Title.q.isbn==upc)
            #print titles #debug
            self.known_title= False
            the_titles=list(titles)
            if len(the_titles) > 0:
                self.known_title= the_titles[0]
                ProductName = the_titles[0].booktitle
                authors = [x.authorName for x in the_titles[0].authors]
                authors_as_string = string.join(authors,',')
                categories = [x.categoryName for x in the_titles[0].categorys]
                categories_as_string = string.join(categories,',')
                if len(the_titles[0].books) > 0:
                    ListPrice = the_titles[0].books[0].listprice
                else:
                    ListPrice = 0
                Manufacturer = the_titles[0].publisher
                
            else: #we don't have it yet
                sleep(1) # so amazon doesn't get huffy 
                ecs.setLicenseKey(amazon_license_key)
                ecs.setSecretAccessKey(amazon_secret_key)
                ecs.setAssociatTag(amazon_associate_tag)
                pythonItems = ecs.searchByUPC(upc)
                if pythonItems:
                    result={}
                    authors=[]
                    author_object="none"
                    categories=[]
                    b=pythonItems[0]
                    try:
                        author_object=b.Artists.Artist
                    except AttributeError:
                        author_object="none"
                    if type(author_object) in types.StringTypes:
                        authors.append(author_object)
                    else: 
                        authors=author_object
                    authors_as_string = string.join(authors,',')

                    for category in b.BrowseNode:
                        categories.append(category.BrowseName)

                    categories_as_string = string.join(categories,',')
                 
                    ProductName=""
                    try:
                        if b.ProductName:
                            ProductName=b.ProductName
                    except AttributeError:
                        x=1
                        
                    Manufacturer=""
                    try:
                        if b.Manufacturer:
                            Manufacturer=b.Manufacturer
                    except AttributeError:
                        x=1

                    ListPrice=""
                    try:
                        if b.ListPrice:
                            ListPrice=b.ListPrice
                    except AttributeError:
                        x=1

                    ReleaseDate=""
                    try:
                        if b.ReleaseDate:
                            ReleaseDate=b.ReleaseDate
                    except AttributeError:
                        x=1
                    
            return {"title":ProductName,
                    "authors":authors,
                    "authors_as_string":authors_as_string,
                    "categories_as_string":categories_as_string,
                    "list_price":ListPrice,
                    "publisher":Manufacturer,
                    "isbn":upc,
                    "known_title": self.known_title}
コード例 #53
0
 def test_lookup_by_isbn10_have_it(self):
     random_item= random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 1)[0]
     result= inventory.lookup_by_isbn( random_item.isbn )
     self.assertEqual(random_item.isbn, result['isbn'], 'inventory.lookup_by_isbn returned wrong isbn for random isbn10 in database')
コード例 #54
0
 def test_titleedit_functional(self):
     random_item=random.sample(list(Title.select()), 1)[0]
     response=self._my_app.get('/titleedit', {'id':random_item.id})
     code, error=tidylib.tidy_document(response.body, options={'show-errors':1, 'show-warnings':0})
     self.assertFalse(error, '/titleedit did not return valid html page')
コード例 #55
0
 def test_lookup_by_isbn10_is_invalid(self):
     #translation table of checkdigits to wrong ones (digit plus 1)
     tr_table=dict(zip( ['x', 'X'] + map(str, range(9, -1, -1)), ['0', '0', 'x'] + map(str, range(9, 0, -1)) ))
     random_item=random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 1)[0]
     wrong_isbn=random_item.isbn[0:9] + tr_table[random_item.isbn[9]]
     self.assertRaises(InvalidParameterValue, inventory.lookup_by_isbn, wrong_isbn)
コード例 #56
0
 def test_lookup_by_isbn13_is_valid(self):
     random_item=random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 1)[0]
     converted_isbn=isbn.convert(random_item.isbn)
     result=inventory.lookup_by_isbn(converted_isbn)
     self.assertEqual(random_item.isbn, result['isbn'], 'inventory.lookup_by_isbn returned wrong isbn for random isbn in database')
コード例 #57
0
 def test_lookup_by_isbn13_is_invalid(self):
     random_item=random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 1)[0]
     converted_isbn=isbn.convert(random_item.isbn)
     wrong_isbn=converted_isbn[0:12] + str((int(converted_isbn[12]) + 1) % 10)
     result=inventory.lookup_by_isbn(wrong_isbn)
     self.assertEqual(random_item.isbn, result['isbn'], 'inventory.lookup_by_isbn returned wrong isbn for invalid isbn13')
コード例 #58
0
 def test_lookup_by_isbn_is_wsr(self):
     random_item=random.sample(list(Title.select('isbn RLIKE \'wsr [0-9]{3,5}\'')), 1)[0]
     result=inventory.lookup_by_isbn(random_item.isbn)
     self.assertEqual(random_item.isbn, result['isbn'], 'inventory.lookup_by_isbn returned wrong isbn for random isbn (wsr) in database')
コード例 #59
0
from objects.title import Title
from objects.author import Author
from objects.category import Category

setLicenseKey(amazon_license_key)
setSecretAccessKey(amazon_secret_key)
setAssociateTag(amazon_associate_tag)

#make sure we're in production database
dbname='infoshopkeeper'
try:
    theapp=webtest.TestApp(application)
except:
    pass

titles=Title.select(RLIKE(Title.q.isbn, '^[0-9]{10}[0-9xX]$|^[0-9]{13}$'))
titles_that_display, titles_that_dont_display, titles_that_dont_even_fetch=(0,[],[])

for title in titles:
    try:
        response=theapp.get('/search', {'id':title.id})
        lx_htm=lxml.html.fromstring(response.text)        
        if lx_htm.cssselect('tbody tr td').__len__() > 1:
            titles_that_display += 1
        else:
            titles_that_dont_display.append(title.id)
        
    except Exception as e:
        print e
        titles_that_dont_even_fetch.append(title.id)
print "Number of titles that don't fetch: ", titles_that_dont_even_fetch.__len__()