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()
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)
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()
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
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)
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
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)
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)
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)
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
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)]
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)
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)
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)
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)
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__() print "Number of titles that don't display: ", titles_that_dont_display.__len__() print "Number of titles that display: ", titles_that_display print "Titles that don't display are: ", titles_that_dont_display print "Titles that don't fetch are: ", titles_that_dont_even_fetch diagnostic_dict={} for t in titles_that_dont_display: t_rec=Title.get(t) rm_dirty=False if not list(t_rec.books): book_list=diagnostic_dict.get('book', []) book_list.append(t) diagnostic_dict['book']=book_list rm_dirty=True if not list(t_rec.author): author_list=diagnostic_dict.get('author', []) author_list.append(t) diagnostic_dict['author']=author_list rm_dirty=True if not list(t_rec.categorys): result_list=diagnostic_dict.get('category', []) result_list.append(t) diagnostic_dict['category']=result_list
def confirm(self, title, book, **kw): book = Book.get(book) title = Title.get(title) book.set_tag(category="inventory", key="confirmation11", value="stock") return self.title(title.id)
def updateItem(id): title = Title.get(id) title_info = lookup_by_isbn(title.orig_isbn, forceUpdate=True)
def reordertag(self,title_id): title=Title.get(title_id) title.set_tag(category="inventory",key="reorder",value=identity.current.user_name) return "1"
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__())) print(("Number of titles that don't display: ", titles_that_dont_display.__len__())) print(("Number of titles that display: ", titles_that_display)) print(("Titles that don't display are: ", titles_that_dont_display)) print(("Titles that don't fetch are: ", titles_that_dont_even_fetch)) diagnostic_dict = {} for t in titles_that_dont_display: t_rec = Title.get(t) rm_dirty = False if not list(t_rec.books): book_list = diagnostic_dict.get("book", []) book_list.append(t) diagnostic_dict["book"] = book_list rm_dirty = True if hasattr(t_rec, "author") and not t_rec.authors_as_string(): author_list = diagnostic_dict.get("authors_as_string", []) author_list.append(t) diagnostic_dict["authors_as_string"] = author_list rm_dirty = True if not list(t_rec.categorys): result_list = diagnostic_dict.get("category", []) result_list.append(t) diagnostic_dict["category"] = result_list
def reordertag(self, title_id): title = Title.get(title_id) title.set_tag(category="inventory", key="reorder", value=identity.current.user_name) return "1"
def confirm(self,title,book,**kw): book=Book.get(book) title=Title.get(title) book.set_tag(category="inventory",key="confirmation11",value="stock") return self.title(title.id)