Beispiel #1
0
    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()
Beispiel #2
0
    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()
Beispiel #3
0
    def __init__(self):
        nfl_json = get_nfl_json()

        categories = Category()

        stats = []
        for team_json in nfl_json.values():
            team_json = team_json.get("stats")
            team_json = team_json.get("page").get("content")
            team_json = team_json.get("stats").get("dictionary")
            for stat_json in team_json.values():
                stat_abbr = stat_json.get("abbrev")
                stat_name = stat_json.get("statName")
                stat_shortdesc = stat_json.get("shortDesc")
                stat_fulldesc = stat_json.get("desc")
                _stat_category = stat_json.get("group").title()
                stat_category = categories.find(_stat_category)
                stat = (stat_abbr, stat_name, stat_shortdesc, stat_fulldesc,
                        stat_category)
                stats.append(stat)
            break

        self.values = tuple(stats)
        self.keys = ("abbr", "name", "shortdesc", "fulldesc", "category")
        self.model = "app.stat"
        self.key = "name"
Beispiel #4
0
def build_fixtures():
    cache_dir = __file__.replace("loader.py", "cache")

    obj_map = {
        "division": list(Division()),
        "position": list(Position()),
        "category": list(Category()),
        "team": list(Team()),
        "record": list(Record()),
        "profile": list(Profile()),
        "color": list(Color()),
        "teamnav": list(TeamNav()),
        "player": list(Player()),
        "playernav": list(PlayerNav()),
        "stat": list(Stat()),
        "teamstat": list(TeamStat()),
        "oppstat": list(OppStat()),
        "playerstat": list(PlayerStat())
    }

    fixture_dir = f"{cache_dir}/fixtures"
    os.makedirs(fixture_dir, exist_ok=True)

    fixtures = []
    for key, value in obj_map.items():
        filename = f"{fixture_dir}/{key}.json"
        with open(filename, "w") as f:
            json.dump(value, f)
        fixtures += value

    with open(f"{fixture_dir}/all.json", "w") as f:
        json.dump(fixtures, f)
Beispiel #5
0
 def test_categoryedit_functional(self):
     random_item = random.sample(list(Category.select()), 1)[0]
     response = self._my_app.get("/categoryedit", {"id": random_item.id})
     code, error = tidylib.tidy_document(response.body,
                                         options={
                                             "show-errors": 1,
                                             "show-warnings": 0
                                         })
     self.assertFalse(error, "/categoryedit did not return valid html page")
Beispiel #6
0
 def categoryedit(self, **args):
     self.common()
     self._categoryedittemplate.category = Category.form_to_object(
         Category, args)
     return self._categoryedittemplate.respond()
Beispiel #7
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])
 def test_categoryedit_functional(self):
     random_item=random.sample(list(Category.select()), 1)[0]
     response=self._my_app.get('/categoryedit', {'id':random_item.id})
     code, error=tidylib.tidy_document(response.body, options={'show-errors':1, 'show-warnings':0})
     self.assertFalse(error, '/categoryedit did not return valid html page')
Beispiel #9
0
 def categoryedit(self,**args):
     self.common()
     self._categoryedittemplate.category=Category.form_to_object(Category,args)
     return self._categoryedittemplate.respond()
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="",
        )