Пример #1
0
    def _queryForm(self):
        val="<select class='textbox' id='kind' name='kind'>"
        for k in list(Kind.select()):
            val = val+"<option value='%s'>%s</option>" % (k.id,k.kindName)
        val=val+"</select>"
	
        return val
Пример #2
0
    def _queryForm(self):
        val = "<select class='textbox' id='kind' name='kind'>"
        for k in list(Kind.select()):
            val = val + "<option value='%s'>%s</option>" % (k.id, k.kindName)
        val = val + "</select>"

        return val
Пример #3
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()
    def _queryForm(self):
        val = "<select class='textbox' id='kind' name='kind'>"
        for k in list(Kind.select()):
            val = val + "<option value='%s'>%s</option>" % (k.id, k.kindName)
        val = val + "</select>"
        val = (
            val
            + """
                <label class='textbox' for='begin_date'>Begin Date</label><input type='text' class='textbox' name='begin_date' id='begin_date' value='%s'/>
        <label class='textbox' for='end_date'>End Date</label><input type='text' class='textbox' name='end_date' id='end_date' value='%s'/>
        <script type='text/javascript'>
        Calendar.setup({
        inputField     :    'begin_date',   // id of the input field
        ifFormat       :    '%%Y-%%m-%%d',       // format of the input field
        showsTime      :    false,
    });
    Calendar.setup({
        inputField     :    'end_date',   // id of the input field
        ifFormat       :    '%%Y-%%m-%%d',       // format of the input field
        showsTime      :    false,
    });
        </script>
"""
            % (self.args.get("begin_date", ""), self.args.get("end_date", ""))
        )
        return val
    def _queryForm(self):
        val = "<select class='textbox' id='kind' name='kind'>"
        for k in list(Kind.select()):
            val = val + "<option value='%s'>%s</option>" % (k.id, k.kindName)
        val = val + "</select>"
        val = val + """
                <label class='textbox' for='publisher'>Publisher</label><input type='text' class='textbox' name='publisher' id='publisher' value='%s'/>
       
""" % (self.args.get("publisher", ""))
        return val
    def _queryForm(self):
        val="<select class='textbox' id='kind' name='kind'>"
        for k in list(Kind.select()):
            val = val+"<option value='%s'>%s</option>" % (k.id,k.kindName)
        val=val+"</select>"
        val =val+"""
                <label class='textbox' for='publisher'>Publisher</label><input type='text' class='textbox' name='publisher' id='publisher' value='%s'/>
       
""" % (self.args.get("publisher",""))
        return val
Пример #7
0
 def _queryForm(self):
     val = "<label class='textbox' for='kind'>Kind</label><select class='textbox' id='kind' name='kind'>"
     for k in list(Kind.select()):
         val = val + "<option value='%s'>%s</option>" % (k.id, k.kindName)
     val = val + "</select><br>"
     val = (val + """
         <label class='textbox' for='begin_date'>Begin Date</label><input type='text' class='textbox' name='begin_date' id='begin_date' value='%s'/><br>
         <label class='textbox' for='end_date'>End Date</label><input type='text' class='textbox' name='end_date' id='end_date' value='%s'/><br>
         <label class='textbox' for='with_notfound'>Include \"NOT FOUND\" records?</label><input type='checkbox' class='textbox' name='with_notfound' id='with_notfound'/><br>
     """ % (self.args.get("begin_date", ""), self.args.get("end_date", "")))
     return val
 def _queryForm(self):
     val = "<label class='textbox' for='kind'>Kind</label><select class='textbox' id='kind' name='kind'>"
     for k in list(Kind.select()):
         val = val + "<option value='%s'>%s</option>" % (k.id, k.kindName)
     val = val + "</select><br>"
     val = (val + """
         <label class='textbox' for='begin_date'>Begin Date</label><input type='text' class='textbox' name='begin_date' id='begin_date' value='%s'/><br>
         <label class='textbox' for='end_date'>End Date</label><input type='text' class='textbox' name='end_date' id='end_date' value='%s'/><br>
         <script type="text/javascript">                                         
             jQuery(document).ready( function(){
                 jQuery('#begin_date,#end_date').datepicker({dateFormat:'yy-mm-dd'}).blur();
             });
         </script>        
     """ % (self.args.get("begin_date", ""), self.args.get("end_date", "")))
     return val
Пример #9
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()
Пример #10
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="")
Пример #11
0
    def _queryForm(self):
        val = "<select class='textbox' id='kind' name='kind'>"
        for k in list(Kind.select()):
            val = val + "<option value='%s'>%s</option>" % (k.id, k.kindName)
        val = val + "</select>"
        val = (val + """
                <label class='textbox' for='begin_date'>Begin Date</label><input type='text' class='textbox' name='begin_date' id='begin_date' value='%s'/>
        <label class='textbox' for='end_date'>End Date</label><input type='text' class='textbox' name='end_date' id='end_date' value='%s'/>
        <script type='text/javascript'>
        Calendar.setup({
        inputField     :    'begin_date',   // id of the input field
        ifFormat       :    '%%Y-%%m-%%d',       // format of the input field
        showsTime      :    false,
    });
    Calendar.setup({
        inputField     :    'end_date',   // id of the input field
        ifFormat       :    '%%Y-%%m-%%d',       // format of the input field
        showsTime      :    false,
    });
        </script>
""" % (self.args.get("begin_date", ""), self.args.get("end_date", "")))
        return val
Пример #12
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()
Пример #13
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])
Пример #14
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()
Пример #15
0
 def kindlist(self, **args):
     self.common()
     self._kindlisttemplate.kinds = list(Kind.select())
     return self._kindlisttemplate.respond()
Пример #16
0
    def search(self,
               title="",
               sortby="booktitle",
               distributor="",
               owner="",
               publisher="",
               author="",
               category="",
               out_of_stock='no',
               stock_less_than="",
               stock_more_than="",
               sold_more_than="",
               sold_less_than="",
               tag="",
               kind=""):
        cherrypy.session['lastsearch'] = False
        self.common()
        cherrypy.session['lastsearch'] = cherrypy.request.browserUrl

        self._searchtemplate.empty = True
        self._searchtemplate.title = title
        self._searchtemplate.author = author
        self._searchtemplate.category = category
        self._searchtemplate.distributor = distributor
        self._searchtemplate.owner = owner
        self._searchtemplate.publisher = publisher
        self._searchtemplate.out_of_stock = out_of_stock
        self._searchtemplate.stock_less_than = stock_less_than
        self._searchtemplate.stock_more_than = stock_more_than
        self._searchtemplate.sold_more_than = sold_more_than
        self._searchtemplate.sold_less_than = sold_less_than
        self._searchtemplate.tag = tag
        self._searchtemplate.kinds = list(Kind.select())
        self._searchtemplate.kind = kind
        the_kind = kind
        if type(the_kind) == type([1, 2, 3]):
            the_kind = the_kind[0]

        titles = []
        fields = [
            title, author, category, distributor, owner, publisher,
            stock_less_than, stock_more_than, sold_more_than, sold_less_than,
            tag, kind
        ]
        fields_used = [f for f in fields if f != ""]

        if len(fields_used) > 0 or out_of_stock == "yes":
            self._searchtemplate.empty = False
            if len(author) > 0:
                titles = Title.select(
                    """
                title.kind_id = '%s' AND
                title.booktitle LIKE '%%%s%%' AND
                title.publisher LIKE '%%%s%%' AND
                title.tag LIKE '%%%s%%' AND
                book.title_id=title.id AND book.distributor LIKE '%%%s%%' AND
                book.owner LIKE '%%%s%%' AND
                author_title.title_id=title.id AND
                author_title.author_id=author.id AND
                author.author_name LIKE '%%%s%%'        
                """ % (escape_string(the_kind), escape_string(title),
                       escape_string(publisher), escape_string(tag),
                       escape_string(distributor), escape_string(owner),
                       escape_string(author)),
                    orderBy=sortby,
                    clauseTables=['book', 'author', 'author_title'],
                    distinct=True)

            else:
                if len(category) > 0:
                    titles = Title.select("""
                    title.kind_id = '%s' AND
                    title.booktitle LIKE '%%%s%%' AND
                    title.publisher LIKE '%%%s%%' AND
                    title.tag LIKE '%%%s%%' AND
                    book.title_id=title.id AND book.distributor LIKE '%%%s%%' AND
                    book.owner LIKE '%%%s%%' AND
                    category.title_id=title.id AND category.category_name LIKE '%%%s%%'        
                """ % (escape_string(the_kind), escape_string(title),
                       escape_string(publisher), escape_string(tag),
                       escape_string(distributor), escape_string(owner),
                       escape_string(category)),
                                          orderBy=sortby,
                                          clauseTables=['book', 'category'],
                                          distinct=True)
                else:

                    # do a less complicated query
                    titles = Title.select("""
                    title.kind_id = '%s' AND
                    title.booktitle LIKE '%%%s%%' AND
                    title.publisher LIKE '%%%s%%' AND
                    title.tag LIKE '%%%s%%' AND
                    book.title_id=title.id AND book.distributor LIKE '%%%s%%'
                    AND book.owner LIKE '%%%s%%'         
                    """ % (escape_string(the_kind), escape_string(title),
                           escape_string(publisher), escape_string(tag),
                           escape_string(distributor), escape_string(owner)),
                                          orderBy=sortby,
                                          clauseTables=['book'],
                                          distinct=True)

            if out_of_stock == 'yes':
                titles = [
                    t for t in titles if t.copies_in_status("STOCK") == 0
                ]

            if stock_less_than != "":
                titles = [
                    t for t in titles
                    if t.copies_in_status("STOCK") <= int(stock_less_than)
                ]

            if stock_more_than != "":
                titles = [
                    t for t in titles
                    if t.copies_in_status("STOCK") >= int(stock_more_than)
                ]

            if sold_more_than != "":
                titles = [
                    t for t in titles
                    if t.copies_in_status("SOLD") >= int(sold_more_than)
                ]

            if sold_less_than != "":
                titles = [
                    t for t in titles
                    if t.copies_in_status("SOLD") <= int(sold_less_than)
                ]

        self._searchtemplate.titles = titles

        return self._searchtemplate.respond()
Пример #17
0
    def getInventory(self, queryTerms):
        keys = queryTerms.keys()

        isbnSelect = ""
        kindSelect = ""
        statusSelect = ""
        titleSelect = ""
        authorSelect = ""
        categorySelect = ""
        clauseTables = []

        if "kind" in keys:  # joins suck, avoid if possible
            kind_map = {}
            for k in [(x.kindName, x.id) for x in list(Kind.select())]:
                kind_map[k[0]] = k[1]
            try:
                kind_id = kind_map[queryTerms['kind']]
                kindSelect = Book.sqlrepr(
                    AND(
                        Field("book", "title_id") == Field("title", "id"),
                        Field("title", "kind_id") == kind_id))
            except:
                pass

        if 'status' in keys:
            statusSelect = Book.sqlrepr(
                Field("book", "status") == queryTerms["status"])

        if ('title' in keys) or ('authorName' in keys) or ('kind' in keys) or (
                'categoryName' in keys) or ('isbn' in keys):
            clauseTables.append('title')
            #we are going to need to do a join

            if 'title' in keys:
                titleSelect = Book.sqlrepr(
                    AND(
                        Field("book", "title_id") == Field("title", "id"),
                        RLIKE(Field("title", "booktitle"),
                              queryTerms["title"])))

            if 'isbn' in keys:
                titleSelect = Book.sqlrepr(
                    AND(
                        Field("book", "title_id") == Field("title", "id"),
                        Field("title", "isbn") == queryTerms["isbn"]))

            if 'authorName' in keys:
                #~ authorSelect="""book.title_id = title.id AND author.title_id=title.id AND author.author_name RLIKE %s""" % (Book.sqlrepr(queryTerms["authorName"]))
                authorSelect = Book.sqlrepr(
                    AND(
                        Field("book", "title_id") == Field("title", "id"),
                        Field("author", "id") == Field("author_title",
                                                       "author_id"),
                        Field("title", "id") == Field("author_title",
                                                      "title_id"),
                        RLIKE(Field("author", "author_name"),
                              queryTerms["authorName"])))
                clauseTables.append('author')
                clauseTables.append('author_title')

            if 'categoryName' in keys:
                #~ categorySelect="""book.title_id = title.id AND category.title_id=title.id AND category.category_name RLIKE %s""" % (Book.sqlrepr(queryTerms["categoryName"]))
                categorySelect = Book.sqlrepr(
                    AND(
                        Field("book", "title_id") == Field("title", "id"),
                        Field("category", "title_id") == Field("title", "id"),
                        RLIKE(Field("category", "category_name"),
                              queryTerms["categoryName"])))
                clauseTables.append('category')

    # At this time, ubuntu install sqlobject 0.6.1 if apt-get install python2.4-sqlobject,
# which make the search crash, since the distinct attribute is defined somewhere after 0.6.1
        try:
            books = Book.select(string.join([
                term for term in [
                    statusSelect, titleSelect, authorSelect, kindSelect,
                    categorySelect
                ] if term != ""
            ], " AND "),
                                clauseTables=clauseTables,
                                distinct=True)
        except TypeError:
            books = Book.select(string.join([
                term for term in [
                    statusSelect, titleSelect, authorSelect, kindSelect,
                    categorySelect
                ] if term != ""
            ], " AND "),
                                clauseTables=clauseTables)

        results = {}
        i = 1
        for b in books:
            theTitle = b.title.booktitle.decode("unicode_escape")
            if b.notes == None:
                b.notes = ""
            authorString = string.join([
                a.author_name.decode("unicode_escape") for a in b.title.author
            ], ",")
            results[i] = (string.capitalize(theTitle), authorString,
                          b.listprice,
                          b.title.publisher.decode("unicode_escape"),
                          b.status.decode("unicode_escape"), b.title.isbn,
                          b.distributor.decode("unicode_escape"),
                          b.notes.decode("unicode_escape"), b.id,
                          b.title.kind and b.title.kind.kindName or '')
            i = i + 1

        return results
Пример #18
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])
Пример #19
0
    def __init__(self, parent):
        self.known_title = False
        self.parent = parent
        self.trailing_two = False
        self.selected_kind = cfg.get("default_kind")
        if isinstance(bookStatus, tuple):
            self.statuses = bookStatus
        else:
            self.statuses = False
        self.keybuffer = ""
        wxDialog.__init__(self, parent, -1, "Merchandise Details")
        #        self.SetBackgroundColour("FIREBRICK")
        self.SetSize((400, 570))

        self.master_sizer = wxBoxSizer(wxVERTICAL)

        self.toprow = wxBoxSizer(wxHORIZONTAL)
        self.toprow_col1 = wxBoxSizer(wxVERTICAL)
        self.toprow_col2 = wxBoxSizer(wxVERTICAL)
        self.static0 = wxStaticText(self, -1, "Item ID (UPC or ISBN):")
        self.number = wxTextCtrl(id=-1,
                                 name="merchandise_id",
                                 parent=self,
                                 style=wxTE_PROCESS_ENTER)
        EVT_TEXT(self, self.number.GetId(), self.OnText)
        EVT_TEXT_ENTER(self, self.number.GetId(), self.OnTextEnter)
        if ON_LINUX:
            EVT_CHAR(self.number, self.OnKeyDown)

        self.toprow_col1.Add(self.static0, 0, wxEXPAND | wxALL, 5)
        self.toprow_col1.Add(self.number, 0, wxEXPAND | wxALL, 5)

        self.static0a = wxStaticText(self, -1, "Quantity:")
        self.quantity = wxTextCtrl(id=-1,
                                   name="quantity",
                                   parent=self,
                                   style=0)
        self.quantity.SetValue("1")

        self.toprow_col2.Add(self.static0a, 0, wxEXPAND | wxALL, 5)
        self.toprow_col2.Add(self.quantity, 0, wxEXPAND | wxALL, 5)

        self.toprow.Add(self.toprow_col1, 0, wxEXPAND | wxALL, 5)
        self.toprow.Add(self.toprow_col2, 0, wxEXPAND | wxALL, 5)

        self.master_sizer.Add(self.toprow, 0, wxEXPAND | wxALL, 5)
        self.row2 = wxBoxSizer(wxHORIZONTAL)
        self.static1 = wxStaticText(self, -1, "Title:")
        self.description = wxTextCtrl(id=-1,
                                      name="merchandise_description",
                                      parent=self,
                                      style=0)

        self.row2.Add(self.static1, 0, wxGROW, 5)
        self.row2.Add(self.description, 1, wxGROW, 5)
        self.master_sizer.Add(self.row2, 0, wxGROW, 5)

        self.prices = multiplePrices(self)
        self.prices.addPage(page_name="list price", master=True)
        for m in cfg.get("multiple_prices"):
            self.prices.addPage(page_name=m[0], proportion_of_master=m[1])

        self.prices.render()
        self.master_sizer.Add(self.prices.mp_sizer, 1, wxEXPAND | wxALL, 5)

        self.row4 = wxBoxSizer(wxHORIZONTAL)
        self.static3 = wxStaticText(self, -1, "Publisher:")
        self.publisher = wxTextCtrl(id=-1,
                                    name="merchandise_publisher",
                                    parent=self,
                                    style=0)
        self.row4.Add(self.static3, 0, wxEXPAND | wxALL, 5)
        self.row4.Add(self.publisher, 1, wxGROW)
        self.master_sizer.Add(self.row4, 0, wxGROW, 5)

        self.row5 = wxBoxSizer(wxHORIZONTAL)
        self.static4 = wxStaticText(self, -1, "Author:")
        self.moreAuthor = wxButton(self, -1, "More authors", (110, 500))
        EVT_BUTTON(self, self.moreAuthor.GetId(), self.OnMoreAuthor)
        self.author = wxTextCtrl(id=-1,
                                 name="merchandise_author",
                                 parent=self,
                                 style=0)
        self.row5.Add(self.static4, 0, wxEXPAND | wxALL, 5)
        self.row5.Add(self.author, 1, wxGROW, 5, 1)
        self.row5.Add(self.moreAuthor, 0, wxEXPAND | wxALL, 5)
        self.master_sizer.Add(self.row5, 0, wxGROW, 5)

        self.row6 = wxBoxSizer(wxHORIZONTAL)
        self.static5 = wxStaticText(self, -1, "Category:")
        self.category = wxTextCtrl(id=-1,
                                   name="merchandise_category",
                                   parent=self,
                                   style=0)
        self.row6.Add(self.static5, 0, wxEXPAND | wxALL, 5)
        self.row6.Add(self.category, 1, wxGROW, 5, 1)
        self.master_sizer.Add(self.row6, 0, wxGROW, 5)

        self.row7 = wxBoxSizer(wxHORIZONTAL)
        self.static6 = wxStaticText(self, -1, "Distributor:")
        self.distributor = wxTextCtrl(id=-1,
                                      name="merchandise_distributor",
                                      parent=self,
                                      style=0)
        self.row7.Add(self.static6, 0, wxEXPAND | wxALL, 5)
        self.row7.Add(self.distributor, 1, wxGROW, 5, 1)
        self.master_sizer.Add(self.row7, 0, wxEXPAND | wxALL, 5)

        self.static7 = wxStaticText(self, -1, "Owner:")
        self.owner = wxTextCtrl(id=-1,
                                name="merchandise_owner",
                                parent=self,
                                style=0)
        self.owner.SetValue(cfg.get("default_owner"))

        self.master_sizer.Add(self.static7, 0, wxEXPAND | wxALL, 5)
        self.master_sizer.Add(self.owner, 0, wxEXPAND | wxALL, 5)

        if self.statuses:
            self.static8 = wxStaticText(self, -1, "Status:")
            self.status = wxRadioBox(id=-1,
                                     name="Radio box 1",
                                     parent=self,
                                     choices=self.statuses)

            self.master_sizer.Add(self.static8, 0, wxEXPAND | wxALL, 5)
            self.master_sizer.Add(self.status, 0, wxEXPAND | wxALL, 5)

        kinds = ["%s" % k.kindName for k in list(Kind.select())]

        self.static8 = wxStaticText(self, -1, "Kind:")
        self.kind = wxChoice(id=-1,
                             name="merchandise_kind",
                             parent=self,
                             choices=kinds,
                             style=0)

        position = self.kind.FindString(self.selected_kind)
        self.kind.SetSelection(position)

        self.master_sizer.Add(self.static8, 0, wxEXPAND | wxALL, 5)
        self.master_sizer.Add(self.kind, 0, wxEXPAND | wxALL, 5)

        self.static9 = wxStaticText(self, -1, "Notes:")
        self.notes = wxTextCtrl(id=-1,
                                name="merchandise_notes",
                                parent=self,
                                style=0)

        self.master_sizer.Add(self.static9, 0, wxEXPAND | wxALL, 5)
        self.master_sizer.Add(self.notes, 0, wxEXPAND | wxALL, 5)

        self.b = wxButton(self, -1, "Add and continue", (15, 500))
        EVT_BUTTON(self, self.b.GetId(), self.OnAddAndContinue)

        self.b2 = wxButton(self, -1, "Add and quit", (110, 500))
        EVT_BUTTON(self, self.b2.GetId(), self.OnAddAndQuit)
        self.b3 = wxButton(self, -1, "Cancel", (110, 500))
        EVT_BUTTON(self, self.b3.GetId(), self.OnCancel)

        self.bottomrow = wxBoxSizer(wxHORIZONTAL)
        self.bottomrow.Add(self.b, 1, wxGROW, 5)
        self.bottomrow.Add(self.b2, 1, wxGROW, 5)
        self.bottomrow.Add(self.b3, 1, wxGROW, 5)

        self.master_sizer.Add(self.bottomrow, 0, wxEXPAND | wxALL, 5)
        self.statusBar = wxStatusBar(self, -1, name="statusBar")
        self.master_sizer.Add(self.statusBar, 0, wxEXPAND | wxALL, 5)

        self.number.SetFocus()
        self.Fit()
        self.SetSizer(self.master_sizer)
        self.SetAutoLayout(1)
        self.master_sizer.Fit(self)
    def __init__(self, parent, is_dialog=0):
        self.parent = parent
        self.lastSearchModified = False
        self.is_dialog = is_dialog
        if is_dialog:
            self.main_window = parent.parent
        else:
            self.main_window = parent
        self.browser = 0
        self.selected_kind = cfg.get("default_kind")

        wxPanel.__init__(self, parent)
        tID = wxNewId()

        self.master_sizer = wxBoxSizer(wxVERTICAL)
        self.row_1 = wxBoxSizer(wxHORIZONTAL)
        self.row_2 = wxBoxSizer(wxHORIZONTAL)
        self.col_3 = wxBoxSizer(wxVERTICAL)
        self.row_4 = wxBoxSizer(wxHORIZONTAL)
        self.row_5 = wxBoxSizer(wxHORIZONTAL)
        self.row_6 = wxBoxSizer(wxHORIZONTAL)

        self.static1 = wxStaticText(self, -1, "Title:")
        self.static2 = wxStaticText(self, -1, "Author:")
        self.static3 = wxStaticText(self, -1, "Keyword:")
        self.row_1.Add(self.static1, 1, wxEXPAND, 2)
        self.row_1.Add(self.static2, 1, wxEXPAND, 2)
        self.row_1.Add(self.static3, 1, wxEXPAND, 2)

        self.description = wxTextCtrl(id=-1, name="merchandise_description", parent=self, style=0)
        self.author = wxTextCtrl(id=-1, name="merchandise_author", parent=self, style=0)
        self.category = wxTextCtrl(id=-1, name="merchandise_category", parent=self, style=0)

        self.row_2.Add(self.description, 1, wxEXPAND, 2)
        self.row_2.Add(self.author, 1, wxEXPAND, 2)
        self.row_2.Add(self.category, 1, wxEXPAND, 2)

        self.static5 = wxStaticText(self, -1, "Kind:")
        self.col_3.Add(self.static5, 1, wxEXPAND, 2)

        kinds = ["%s" % k.kindName for k in list(Kind.select())]
        self.kind = wxChoice(id=-1, name="merchandise_kind", parent=self, choices=kinds)
        self.col_3.Add(self.kind, 0, wxGROW)
        if bookStatus:
            self.status = wxRadioBox(
                id=-1, name="status", label="Status", parent=self, choices=bookStatus
            )  # bookStatus from etc
        position = self.kind.FindString(self.selected_kind)
        self.kind.SetSelection(position)

        self.row_4.Add(self.col_3, 0)
        if bookStatus:
            self.row_4.Add(self.status, 0)

        self.b2 = wxButton(self, -1, "Search")
        EVT_BUTTON(self, self.b2.GetId(), self.OnSearch)
        self.b2.SetDefault()
        self.row_4.Add(self.b2, 0, wxEXPAND | wxALL, 5)

        if self.is_dialog:
            self.b = wxButton(self, -1, "Cancel")
            EVT_BUTTON(self, self.b.GetId(), self.OnCancel)
            self.row_4.Add(self.b, 0, wxEXPAND | wxALL, 5)

        self.master_sizer.Add(self.row_1, 0, wxEXPAND | wxALL)
        self.master_sizer.Add(self.row_2, 0, wxEXPAND | wxALL)
        self.master_sizer.Add(self.row_4, 0, wxGROW)

        self.list = InventoryListCtrl(
            self,
            tID,
            style=wxLC_REPORT | wxSUNKEN_BORDER | wxLC_EDIT_LABELS
            # | wxLC_NO_HEADER
            # | wxLC_VRULES | wxLC_HRULES
        )
        self.list.InsertColumn(0, "Title")
        self.list.InsertColumn(1, "Author")
        self.list.InsertColumn(2, "Price")
        self.list.InsertColumn(3, "Publisher")
        self.list.InsertColumn(4, "Status")
        self.list.InsertColumn(5, "ISBN")
        self.list.InsertColumn(6, "Distributor")
        self.list.InsertColumn(7, "Location")
        self.list.InsertColumn(8, "Notes")
        self.list.InsertColumn(9, "ID")
        self.list.InsertColumn(10, "Kind")
        self.list.InsertColumn(11, "Format")

        self.master_sizer.Add(self.list, flag=wxGROW, proportion=1)

        self.SetSizer(self.master_sizer)
        self.SetAutoLayout(1)
        self.master_sizer.Fit(self)
Пример #21
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="",
        )
Пример #22
0
def getInventory(queryTerms):
    print(queryTerms, file=sys.stderr)
    keys = list(queryTerms)
    print("keys are ", keys)
    for k in keys:
        if type(queryTerms[k]) == bytes:
            queryTerms[k] = queryTerms[k].decode("utf-8")

    isbnSelect = ""
    kindSelect = ""
    statusSelect = ""
    titleSelect = ""
    authorSelect = ""
    categorySelect = ""
    clauseTables = []

    if "kind" in keys:  # joins suck, avoid if possible
        kind_map = {}
        for k in [(x.kindName, x.id) for x in list(Kind.select())]:
            kind_map[k[0]] = k[1]
        try:
            kind_id = kind_map[queryTerms["kind"]]
            kindSelect = Book.sqlrepr(
                AND(
                    Field("book", "title_id") == Field("title", "id"),
                    Field("title", "kind_id") == kind_id,
                )
            )
        except:
            pass

    if "status" in keys:
        statusSelect = Book.sqlrepr(Field("book", "status") == queryTerms["status"])

    if (
        ("title" in keys)
        or ("authorName" in keys)
        or ("kind" in keys)
        or ("categoryName" in keys)
        or ("isbn" in keys)
    ):
        clauseTables.append("title")
        # we are going to need to do a join

        if "title" in keys:
            titleSelect = Book.sqlrepr(
                AND(
                    Field("book", "title_id") == Field("title", "id"),
                    RLIKE(Field("title", "booktitle"), queryTerms["title"]),
                )
            )

        if "isbn" in keys:
            isbn, price = _process_isbn(queryTerms["isbn"])
            print("isbn and price are ", isbn, price)
            titleSelect = Book.sqlrepr(
                AND(
                    Field("book", "title_id") == Field("title", "id"),
                    Field("title", "isbn") == isbn,
                )
            )

        if "authorName" in keys:
            # authorSelect="""book.title_id = title.id AND author.title_id=title.id AND author.author_name RLIKE %s""" % (Book.sqlrepr(queryTerms["authorName"]))
            authorSelect = Book.sqlrepr(
                AND(
                    Field("book", "title_id") == Field("title", "id"),
                    Field("author", "id") == Field("author_title", "author_id"),
                    Field("title", "id") == Field("author_title", "title_id"),
                    RLIKE(Field("author", "author_name"), queryTerms["authorName"]),
                )
            )
            clauseTables.append("author")
            clauseTables.append("author_title")

        if "categoryName" in keys:
            categorySelect = (
                """book.title_id = title.id AND category.title_id=title.id AND category.category_name RLIKE %s"""
                % (Book.sqlrepr(queryTerms["categoryName"]))
            )
            clauseTables.append("category")
    try:
        books = Book.select(
            " AND ".join(
                [
                    term
                    for term in [
                        statusSelect,
                        titleSelect,
                        authorSelect,
                        kindSelect,
                        categorySelect,
                    ]
                    if term != ""
                ]
            ),
            clauseTables=clauseTables,
            distinct=True,
        )
    except TypeError:
        books = Book.select(
            " AND ".join(
                [
                    term
                    for term in [
                        statusSelect,
                        titleSelect,
                        authorSelect,
                        kindSelect,
                        categorySelect,
                    ]
                    if term != ""
                ]
            ),
            clauseTables=clauseTables,
        )

    results = {}
    i = 1
    for book_for_info in books:
        theTitle = book_for_info.title.booktitle
        authorString = ", ".join([a.authorName for a in book_for_info.title.author])
        categoryString = ", ".join(
            [c.categoryName for c in book_for_info.title.categorys]
        )
        results[i] = (
            theTitle.capitalize(),
            authorString,
            book_for_info.listprice if book_for_info.listprice is not None else "",
            book_for_info.title.publisher
            if book_for_info.title.publisher is not None
            else "",
            book_for_info.status if book_for_info.status is not None else "",
            book_for_info.title.isbn,
            book_for_info.distributor if book_for_info.distributor is not None else "",
            book_for_info.location.locationName
            if book_for_info.location is not None
            else "",
            book_for_info.notes if book_for_info.notes is not None else "",
            book_for_info.id,
            book_for_info.title.kind and book_for_info.title.kind.kindName
            if book_for_info.title.kind is not None
            else "",
            categoryString,
            book_for_info.title.type if book_for_info.title.type is not None else "",
        )
    return results
Пример #23
0
    def search(self,title="",sortby="booktitle",distributor="",owner="",publisher="",author="",category="",out_of_stock='no',stock_less_than="",stock_more_than="",sold_more_than="",sold_less_than="",tag="",kind=""):
        cherrypy.session['lastsearch']=False
        self.common()
        cherrypy.session['lastsearch']=cherrypy.request.browserUrl
        
        self._searchtemplate.empty=True
        self._searchtemplate.title=title
        self._searchtemplate.author=author
        self._searchtemplate.category=category
        self._searchtemplate.distributor=distributor
        self._searchtemplate.owner=owner
        self._searchtemplate.publisher=publisher
        self._searchtemplate.out_of_stock=out_of_stock
        self._searchtemplate.stock_less_than=stock_less_than
        self._searchtemplate.stock_more_than=stock_more_than
        self._searchtemplate.sold_more_than=sold_more_than
        self._searchtemplate.sold_less_than=sold_less_than
        self._searchtemplate.tag=tag
        self._searchtemplate.kinds=list(Kind.select())
        self._searchtemplate.kind=kind
        the_kind=kind
        if type(the_kind) == type([1,2,3]):
            the_kind=the_kind[0]
        
        titles=[]
        fields=[title,author,category,distributor,owner,publisher,stock_less_than,stock_more_than,sold_more_than,sold_less_than,tag,kind]
        fields_used = [f for f in fields if f != ""]
        
        if len(fields_used)>0 or out_of_stock=="yes":
            self._searchtemplate.empty=False
            if len(author)>0:
                titles=Title.select("""
                title.kind_id = '%s' AND
                title.booktitle LIKE '%%%s%%' AND
                title.publisher LIKE '%%%s%%' AND
                title.tag LIKE '%%%s%%' AND
                book.title_id=title.id AND book.distributor LIKE '%%%s%%' AND
                book.owner LIKE '%%%s%%' AND
                author_title.title_id=title.id AND
                author_title.author_id=author.id AND
                author.author_name LIKE '%%%s%%'        
                """ % (escape_string(the_kind),escape_string(title),escape_string(publisher),escape_string(tag),escape_string(distributor),escape_string(owner),escape_string(author)),orderBy=sortby,clauseTables=['book','author','author_title'],distinct=True)

            else:
                if len(category)>0:
                    titles=Title.select("""
                    title.kind_id = '%s' AND
                    title.booktitle LIKE '%%%s%%' AND
                    title.publisher LIKE '%%%s%%' AND
                    title.tag LIKE '%%%s%%' AND
                    book.title_id=title.id AND book.distributor LIKE '%%%s%%' AND
                    book.owner LIKE '%%%s%%' AND
                    category.title_id=title.id AND category.category_name LIKE '%%%s%%'        
                """ % (escape_string(the_kind),escape_string(title),escape_string(publisher),escape_string(tag),escape_string(distributor),escape_string(owner),escape_string(category)),orderBy=sortby,clauseTables=['book','category'],distinct=True)
                else:
                
                    # do a less complicated query
                    titles=Title.select("""
                    title.kind_id = '%s' AND
                    title.booktitle LIKE '%%%s%%' AND
                    title.publisher LIKE '%%%s%%' AND
                    title.tag LIKE '%%%s%%' AND
                    book.title_id=title.id AND book.distributor LIKE '%%%s%%'
                    AND book.owner LIKE '%%%s%%'         
                    """ % (escape_string(the_kind),escape_string(title),escape_string(publisher),escape_string(tag),escape_string(distributor),escape_string(owner)),orderBy=sortby,clauseTables=['book'],distinct=True)
                
            if out_of_stock == 'yes':
                titles = [t for t in titles if t.copies_in_status("STOCK") == 0]

            if stock_less_than != "":
                titles = [t for t in titles if t.copies_in_status("STOCK") <= int(stock_less_than)]

            if stock_more_than != "":
                titles = [t for t in titles if t.copies_in_status("STOCK") >= int(stock_more_than)]
                        
            if sold_more_than != "":
                titles = [t for t in titles if t.copies_in_status("SOLD") >= int(sold_more_than)]

            if sold_less_than != "":
                titles = [t for t in titles if t.copies_in_status("SOLD") <= int(sold_less_than)]
            

        self._searchtemplate.titles=titles


        
        
        
        return  self._searchtemplate.respond()
Пример #24
0
    def __init__(self,parent):
        self.known_title=False
        self.parent=parent
        try:
            self.selected_kind=etc.default_kind
        except:
            self.selected_kind="book"
            

	self.parent=parent
	self.selected_kind = cfg.get("default_kind")
        if isinstance(bookStatus, tuple):
            self.statuses=bookStatus
	else:
	    self.statuses = False
        self.keybuffer=""
        wxDialog.__init__(self, parent,-1,"Merchandise Details")
#        self.SetBackgroundColour("FIREBRICK")
        self.SetSize((400, 570))

        self.master_sizer=wxBoxSizer(wxVERTICAL)

        self.toprow=wxBoxSizer(wxHORIZONTAL)
        self.toprow_col1=wxBoxSizer(wxVERTICAL)
        self.toprow_col2=wxBoxSizer(wxVERTICAL)
        self.static0=wxStaticText(self, -1, "Item ID (UPC or ISBN):")
	self.isbn_dirty=False
        self.number=wxTextCtrl(id=-1,name="merchandise_id", parent=self, style=wxTE_PROCESS_ENTER)
        EVT_TEXT(self,self.number.GetId(), self.OnText)
        EVT_TEXT_ENTER(self,self.number.GetId(), self.OnTextEnter)
        #if ON_LINUX:
        EVT_CHAR(self.number, self.OnKeyDown)

        self.toprow_col1.Add(self.static0,0,wxEXPAND|wxALL,1)
        self.toprow_col1.Add(self.number,0,wxEXPAND|wxALL,1)
        

        self.static0a=wxStaticText(self, -1, "Quantity:")
        self.quantity=wxTextCtrl(id=-1,name="quantity", parent=self, style=0)
        self.quantity.SetValue("1")

        self.toprow_col2.Add(self.static0a,0,wxEXPAND|wxALL,1)
        self.toprow_col2.Add(self.quantity,0,wxEXPAND|wxALL,1)
        
        self.toprow.Add(self.toprow_col1,0,wxEXPAND|wxALL,1)
        self.toprow.Add(self.toprow_col2,0,wxEXPAND|wxALL,1)

        self.master_sizer.Add(self.toprow,0,wxEXPAND|wxALL,1)

        self.static1=wxStaticText(self, -1, "Title:")
        self.description=wxTextCtrl(id=-1,name="merchandise_description", parent=self, style=0)

        self.master_sizer.Add(self.static1,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.description,0,wxEXPAND|wxALL,1)


        self.prices=multiplePrices(self)
        self.prices.addPage(page_name="list price",master=True)
        for m in cfg.get("multiple_prices"):
            self.prices.addPage(page_name=m[0],proportion_of_master=m[1])

        self.prices.render()
        self.master_sizer.Add(self.prices.mp_sizer,1,wxEXPAND|wxALL,1)

        
        self.static3=wxStaticText(self, -1, "Publisher:")
        self.publisher=wxTextCtrl(id=-1,name="merchandise_publisher", parent=self, style=0)

        self.master_sizer.Add(self.static3,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.publisher,0,wxEXPAND|wxALL,1)

        self.static4=wxStaticText(self, -1, "Author:")
        self.author=wxTextCtrl(id=-1,name="merchandise_author", parent=self, style=0)

        self.master_sizer.Add(self.static4,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.author,0,wxEXPAND|wxALL,1)
        

        self.static5=wxStaticText(self, -1, "Keyword:")
        self.category=wxTextCtrl(id=-1,name="merchandise_category", parent=self, style=0)

        self.master_sizer.Add(self.static5,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.category,0,wxEXPAND|wxALL,1)

        conn=Book._connection
        query=Select( Book.q.distributor, groupBy=Book.q.distributor)
        results=conn.queryAll( conn.sqlrepr(query))
        distributors=[t[0] for t in results]

        self.static6=wxStaticText(self, -1, "Distributor:")
        self.distributor=wxComboBox(id=-1,name="merchandise_distributor", parent=self,choices=distributors, style=wx.CB_SORT|wx.CB_DROPDOWN)
        #self.distributor=wxTextCtrl(id=-1,name="merchandise_distributor", parent=self, style=0)
        self.master_sizer.Add(self.static6,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.distributor,0,wxEXPAND|wxALL,1)
 
        query=Select( Location.q.locationName, groupBy=Location.q.locationName)
        results=conn.queryAll( conn.sqlrepr(query))
        locations=[t[0] for t in results]
     
        self.static7=wxStaticText(self, -1, "Location:")
        self.location=wxComboBox(id=-1,name="merchandise_location", parent=self,choices=locations, style=wx.CB_SORT|wx.CB_DROPDOWN|wx.CB_READONLY)
        #self.location=wxTextCtrl(id=-1,name="location", parent=self, style=0)

        self.master_sizer.Add(self.static7,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.location,0,wxEXPAND|wxALL,1)

        self.static8=wxStaticText(self, -1, "Owner:")
        self.owner=wxTextCtrl(id=-1,name="merchandise_owner", parent=self, style=0)
        self.owner.SetValue(cfg.get("default_owner"))
        
        self.master_sizer.Add(self.static8,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.owner,0,wxEXPAND|wxALL,1)

        if self.statuses:
            self.static9=wxStaticText(self, -1, "Status:")
            self.status=wxRadioBox(id=-1,name="Radio box 1", parent=self, choices = self.statuses )

            self.master_sizer.Add(self.static9,0,wxEXPAND|wxALL,1)
            self.master_sizer.Add(self.status,0,wxEXPAND|wxALL,1)
        
        conn=Title._connection
        query=Select( Title.q.type, groupBy=Title.q.type)
        results=conn.queryAll( conn.sqlrepr(query))
        typelist=[t[0] for t in results] 
        print "TypeList: ", typelist
        
	self.static10=wxStaticText(self, -1, "Format:")
        self.types=wxChoice(id=-1,name="merchandise_type", parent=self,choices=typelist, style=0)
	self.master_sizer.Add(self.static10,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.types,0,wxEXPAND|wxALL,1)


        kinds=["%s" % k.kindName for k in list(Kind.select())]
                
        self.static8=wxStaticText(self, -1, "Kind:")
        self.kind=wxChoice(id=-1,name="merchandise_kind", parent=self,choices=kinds,style=0)

        position = self.kind.FindString(self.selected_kind)
    	self.kind.SetSelection(position)

        self.master_sizer.Add(self.static8,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.kind,0,wxEXPAND|wxALL,1)


        self.static9=wxStaticText(self, -1, "Notes:")
        self.notes=wxTextCtrl(id=-1,name="merchandise_notes", parent=self, style=0)
        
        self.master_sizer.Add(self.static9,0,wxEXPAND|wxALL,1)
        self.master_sizer.Add(self.notes,0,wxEXPAND|wxALL,1)


        self.b = wxButton(self, -1, "Cancel", (15, 500))
        EVT_BUTTON(self, self.b.GetId(), self.OnCancel)

        self.b2 = wxButton(self, -1, "Inventory Item", (110, 500))
        EVT_BUTTON(self, self.b2.GetId(), self.OnAdd)

        self.bottomrow=wxBoxSizer(wxHORIZONTAL)
        self.bottomrow.Add(self.b,0,wxEXPAND|wxALL)
        self.bottomrow.Add(self.b2,0,wxEXPAND|wxALL)
        
        self.master_sizer.Add(self.bottomrow,0,wxEXPAND|wxALL,1)
        
	self.statusBar = wxStatusBar(self, -1, name="statusBar")
        self.master_sizer.Add(self.statusBar,0,wxEXPAND|wxALL)
        
        self.number.SetFocus()  
        self.SetSizer(self.master_sizer)
        self.SetAutoLayout(1)
        self.master_sizer.Fit(self)
Пример #25
0
 def kindlist(self,**args):
     self.common()
     self._kindlisttemplate.kinds=list(Kind.select())
     return self._kindlisttemplate.respond()
Пример #26
0
    def __init__(self,parent):
        self.known_title=False
	self.parent=parent
        self.trailing_two=False
	self.selected_kind = cfg.get("default_kind")
        if isinstance(bookStatus, tuple):
            self.statuses=bookStatus
	else:
	    self.statuses = False
        self.keybuffer=""
        wxDialog.__init__(self, parent,-1,"Merchandise Details")
#        self.SetBackgroundColour("FIREBRICK")
        self.SetSize((400, 570))

        self.master_sizer=wxBoxSizer(wxVERTICAL)

        self.toprow=wxBoxSizer(wxHORIZONTAL)
        self.toprow_col1=wxBoxSizer(wxVERTICAL)
        self.toprow_col2=wxBoxSizer(wxVERTICAL)
        self.static0=wxStaticText(self, -1, "Item ID (UPC or ISBN):")
        self.number=wxTextCtrl(id=-1,name="merchandise_id", parent=self, style=wxTE_PROCESS_ENTER)
        EVT_TEXT(self,self.number.GetId(), self.OnText)
        EVT_TEXT_ENTER(self,self.number.GetId(), self.OnTextEnter)
        if ON_LINUX:
            EVT_CHAR(self.number, self.OnKeyDown)

        self.toprow_col1.Add(self.static0,0,wxEXPAND|wxALL,5)
        self.toprow_col1.Add(self.number,0,wxEXPAND|wxALL,5)
        
        self.static0a=wxStaticText(self, -1, "Quantity:")
        self.quantity=wxTextCtrl(id=-1,name="quantity", parent=self, style=0)
        self.quantity.SetValue("1")

        self.toprow_col2.Add(self.static0a,0,wxEXPAND|wxALL,5)
        self.toprow_col2.Add(self.quantity,0,wxEXPAND|wxALL,5)
        
        self.toprow.Add(self.toprow_col1,0,wxEXPAND|wxALL,5)
        self.toprow.Add(self.toprow_col2,0,wxEXPAND|wxALL,5)

        self.master_sizer.Add(self.toprow,0,wxEXPAND|wxALL,5)
        self.row2=wxBoxSizer(wxHORIZONTAL)
        self.static1=wxStaticText(self, -1, "Title:")
        self.description=wxTextCtrl(id=-1,name="merchandise_description", parent=self, style=0)

        self.row2.Add(self.static1,0,wxGROW,5)
        self.row2.Add(self.description,1,wxGROW,5)
	self.master_sizer.Add(self.row2,0, wxGROW,5)

        self.prices=multiplePrices(self)
        self.prices.addPage(page_name="list price",master=True)
        for m in cfg.get("multiple_prices"):
            self.prices.addPage(page_name=m[0],proportion_of_master=m[1])

        self.prices.render()
        self.master_sizer.Add(self.prices.mp_sizer,1,wxEXPAND|wxALL, 5)
        
        self.row4=wxBoxSizer(wxHORIZONTAL)
        self.static3=wxStaticText(self, -1, "Publisher:")
        self.publisher=wxTextCtrl(id=-1,name="merchandise_publisher", parent=self, style=0)
        self.row4.Add(self.static3,0,wxEXPAND|wxALL,5)
        self.row4.Add(self.publisher,1,wxGROW)
	self.master_sizer.Add(self.row4, 0, wxGROW,5)

        self.row5 = wxBoxSizer(wxHORIZONTAL)
	self.static4=wxStaticText(self, -1, "Author:")
        self.moreAuthor = wxButton(self, -1, "More authors", (110, 500))
        EVT_BUTTON(self, self.moreAuthor.GetId(), self.OnMoreAuthor)
        self.author=wxTextCtrl(id=-1,name="merchandise_author", parent=self, style=0)
	self.row5.Add(self.static4,0,wxEXPAND|wxALL,5)
        self.row5.Add(self.author,1,wxGROW,5,1)
	self.row5.Add(self.moreAuthor,0,wxEXPAND|wxALL,5)
	self.master_sizer.Add(self.row5, 0, wxGROW,5)

	self.row6 = wxBoxSizer(wxHORIZONTAL)
        self.static5=wxStaticText(self, -1, "Category:")
        self.category=wxTextCtrl(id=-1,name="merchandise_category", parent=self, style=0)
        self.row6.Add(self.static5,0,wxEXPAND|wxALL,5)
        self.row6.Add(self.category,1,wxGROW,5,1)
	self.master_sizer.Add(self.row6,0,wxGROW,5)

        self.row7 = wxBoxSizer(wxHORIZONTAL)
	self.static6=wxStaticText(self, -1, "Distributor:")
        self.distributor=wxTextCtrl(id=-1,name="merchandise_distributor", parent=self, style=0)
        self.row7.Add(self.static6,0,wxEXPAND|wxALL,5)
        self.row7.Add(self.distributor,1,wxGROW,5,1)
	self.master_sizer.Add(self.row7, 0, wxEXPAND|wxALL,5)

        self.static7=wxStaticText(self, -1, "Owner:")
        self.owner=wxTextCtrl(id=-1,name="merchandise_owner", parent=self, style=0)
        self.owner.SetValue(cfg.get("default_owner"))
        
        self.master_sizer.Add(self.static7,0,wxEXPAND|wxALL,5)
        self.master_sizer.Add(self.owner,0,wxEXPAND|wxALL,5)

        if self.statuses:
            self.static8=wxStaticText(self, -1, "Status:")
            self.status=wxRadioBox(id=-1,name="Radio box 1", parent=self, choices = self.statuses )

            self.master_sizer.Add(self.static8,0,wxEXPAND|wxALL,5)
            self.master_sizer.Add(self.status,0,wxEXPAND|wxALL,5)


        kinds=["%s" % k.kindName for k in list(Kind.select())]
                
        self.static8=wxStaticText(self, -1, "Kind:")
        self.kind=wxChoice(id=-1,name="merchandise_kind", parent=self,choices=kinds,style=0)

        position = self.kind.FindString(self.selected_kind)
	self.kind.SetSelection(position)

        self.master_sizer.Add(self.static8,0,wxEXPAND|wxALL,5)
        self.master_sizer.Add(self.kind,0,wxEXPAND|wxALL,5)

        self.static9=wxStaticText(self, -1, "Notes:")
        self.notes=wxTextCtrl(id=-1,name="merchandise_notes", parent=self, style=0)
        
        self.master_sizer.Add(self.static9,0,wxEXPAND|wxALL,5)
        self.master_sizer.Add(self.notes,0,wxEXPAND|wxALL,5)

        self.b = wxButton(self, -1, "Add and continue", (15, 500))
        EVT_BUTTON(self, self.b.GetId(), self.OnAddAndContinue)

        self.b2 = wxButton(self, -1, "Add and quit", (110, 500))
        EVT_BUTTON(self, self.b2.GetId(), self.OnAddAndQuit)
        self.b3 = wxButton(self, -1, "Cancel", (110, 500))
        EVT_BUTTON(self, self.b3.GetId(), self.OnCancel)

        self.bottomrow=wxBoxSizer(wxHORIZONTAL)
        self.bottomrow.Add(self.b,1,wxGROW, 5)
        self.bottomrow.Add(self.b2,1,wxGROW, 5)
        self.bottomrow.Add(self.b3,1,wxGROW, 5)
        
        self.master_sizer.Add(self.bottomrow,0,wxEXPAND|wxALL,5)
        self.statusBar = wxStatusBar(self, -1, name="statusBar")
        self.master_sizer.Add(self.statusBar,0,wxEXPAND|wxALL,5)
        
        self.number.SetFocus()  
        self.Fit()
	self.SetSizer(self.master_sizer)
        self.SetAutoLayout(1)
        self.master_sizer.Fit(self)
Пример #27
0
    def getInventory(self,queryTerms):
        #print queryTerms
        keys=queryTerms.keys()
        
        isbnSelect=""
        kindSelect=""
        statusSelect=""
        titleSelect=""
        authorSelect=""
        categorySelect=""
        clauseTables=[]

        if "kind" in keys: # joins suck, avoid if possible
            kind_map={}
            for k in [(x.kindName,x.id) for x in list(Kind.select())]:
                kind_map[k[0]]=k[1]
            try:
                kind_id=kind_map[queryTerms['kind']]
                kindSelect=Book.sqlrepr(AND(Field("book","title_id")==Field("title","id"), Field("title","kind_id")==kind_id))
            except: 
                pass
            
        if 'status' in keys:
            statusSelect=Book.sqlrepr(Field("book","status")==queryTerms["status"])
            

        if ('title' in keys) or ('authorName' in keys) or ('kind' in keys) or ('categoryName' in keys) or ('isbn' in keys):
            clauseTables.append('title') 
            #we are going to need to do a join 

            if 'title' in keys:
                titleSelect=Book.sqlrepr(AND(Field("book","title_id")==Field("title","id"), RLIKE(Field("title","booktitle"), queryTerms["title"])))


            if 'isbn' in keys:
                titleSelect=Book.sqlrepr(AND(Field("book","title_id")==Field("title","id"), Field("title","isbn")==queryTerms["isbn"]))


            if 'authorName' in keys:
                #authorSelect="""book.title_id = title.id AND author.title_id=title.id AND author.author_name RLIKE %s""" % (Book.sqlrepr(queryTerms["authorName"]))    
               authorSelect=Book.sqlrepr(AND(Field("book","title_id")==Field("title","id"), Field("author","id")==Field("author_title","author_id"), Field("title","id")==Field("author_title","title_id"), RLIKE(Field("author","author_name"), queryTerms["authorName"])))
               clauseTables.append('author')
               clauseTables.append('author_title')
            
            if 'categoryName' in keys:
                categorySelect="""book.title_id = title.id AND category.title_id=title.id AND category.category_name RLIKE %s""" % (Book.sqlrepr(queryTerms["categoryName"]))
                #categorySelect=Book.sqlrepr(AND(Field("book","title_id")==Field("title","id"), Field("category","title_id")==Field("title","id"), RLIKE(Field("category","category_name"), queryTerms["categoryName"])))
                clauseTables.append('category')
            # At this time, ubuntu install sqlobject 0.6.1 if apt-get install python2.4-sqlobject,
            # which make the search crash, since the distinct attribute is defined somewhere after 0.6.1 
        try:
            books=Book.select(
                string.join([term for term in [statusSelect,titleSelect,authorSelect,kindSelect,categorySelect] if term !=""]," AND "),
                clauseTables=clauseTables,
                distinct=True    )
        except TypeError:
            books=Book.select(
                string.join([term for term in [statusSelect,titleSelect,authorSelect,kindSelect,categorySelect] if term !=""]," AND "),
                clauseTables=clauseTables   )
            
        
        results={}
        i=1
        for b in books:
            theTitle=b.title.booktitle
            authorString=string.join([a.authorName for a in b.title.author],",")
            categoryString=string.join([c.categoryName for c in b.title.categorys],",")
            results[i]=(string.capitalize(theTitle),
                        authorString, 
                        b.listprice  if b.listprice is not None else '',
                        b.title.publisher if b.title.publisher is not None else '',
                        b.status if b.status is not None else'',
                        b.title.isbn,
                        b.distributor if b.distributor is not None else '',
                        b.location.locationName if b.location is not None else '',
                        b.notes if b.notes is not None else '',
                        b.id,
                        b.title.kind and b.title.kind.kindName if b.title.kind is not None else '',
            categoryString,
            b.title.type if b.title.type is not None else '')
        #~ for b in books:
            #~ theTitle=b.title.booktitle.format()
            #~ authorString=string.join([a.authorName.format() for a in b.title.author],",")
            #~ categoryString=string.join([c.categoryName.format() for c in b.title.categorys],",")
            #~ results[i]=(string.capitalize(theTitle),
                        #~ authorString, 
                        #~ b.listprice  if b.listprice is not None else '',
                        #~ b.title.publisher.format() if b.title.publisher is not None else '',
                        #~ b.status.format() if b.status is not None else'',
                        #~ b.title.isbn,
                        #~ b.distributor.format() if b.distributor is not None else '',
            #~ b.location.locationName.format() if b.location is not None else '',
                        #~ b.notes.format() if b.notes is not None else '',
                        #~ b.id,
                        #~ b.title.kind and b.title.kind.kindName if b.title.kind is not None else '',
            #~ categoryString,
            #~ b.title.type if b.title.type is not None else '')

            i=i+1                
        #print "results are ", results
        return results
    def __init__(self,parent, is_dialog=0):
        self.parent=parent
        self.lastSearchModified = False
        self.is_dialog = is_dialog
        if is_dialog:
            self.main_window = parent.parent
        else:
            self.main_window = parent
        self.browser = 0
        self.selected_kind=cfg.get("default_kind")

        wxPanel.__init__(self, parent)
        tID = wxNewId()

        self.master_sizer=wxBoxSizer(wxVERTICAL)
        self.row_1=wxBoxSizer(wxHORIZONTAL)
        self.row_2=wxBoxSizer(wxHORIZONTAL)
        self.col_3=wxBoxSizer(wxVERTICAL)
        self.row_4=wxBoxSizer(wxHORIZONTAL)
        self.row_5=wxBoxSizer(wxHORIZONTAL)
        self.row_6=wxBoxSizer(wxHORIZONTAL)

        self.static1=wxStaticText(self, -1, "Title:")
        self.static2=wxStaticText(self, -1, "Author:")
        self.static3=wxStaticText(self, -1, "Category:")
        self.row_1.Add(self.static1,1,wxEXPAND,2)
        self.row_1.Add(self.static2,1,wxEXPAND,2)
        self.row_1.Add(self.static3,1,wxEXPAND,2)
        
        self.description=wxTextCtrl(id=-1,name="merchandise_description", parent=self,  style=0)
        self.author=wxTextCtrl(id=-1,name="merchandise_author", parent=self, style=0)
        self.category=wxTextCtrl(id=-1,name="merchandise_category", parent=self, style=0)

        self.row_2.Add(self.description,1,wxEXPAND,2)
        self.row_2.Add(self.author,1,wxEXPAND,2)
        self.row_2.Add(self.category,1,wxEXPAND,2)
        
        self.static5=wxStaticText(self, -1, "Kind:")
        self.col_3.Add(self.static5,1,wxEXPAND,2)
        
        kinds=["%s" % k.kindName for k in list(Kind.select())]
        self.kind=wxChoice(id=-1,name="merchandise_kind", parent=self, choices=kinds)
        self.col_3.Add(self.kind,0,wxGROW)
        if bookStatus:
            self.status=wxRadioBox(id=-1,name="status", label="Status", parent=self, choices = bookStatus ) # bookStatus from etc
        position = self.kind.FindString(self.selected_kind)
        self.kind.SetSelection(position)

        self.row_4.Add(self.col_3,0)
        if bookStatus:
            self.row_4.Add(self.status,0)


        self.b2 = wxButton(self, -1, "Search")
        EVT_BUTTON(self, self.b2.GetId(), self.OnSearch)
        self.b2.SetDefault()
        self.row_4.Add(self.b2,0,wxEXPAND|wxALL,5)

        if self.is_dialog:        
            self.b = wxButton(self, -1, "Cancel")
            EVT_BUTTON(self, self.b.GetId(), self.OnCancel)
            self.row_4.Add(self.b,0,wxEXPAND|wxALL,5)
       
        self.master_sizer.Add(self.row_1,0,wxEXPAND|wxALL)
        self.master_sizer.Add(self.row_2,0,wxEXPAND|wxALL)
        self.master_sizer.Add(self.row_4,0,wxGROW)
        
        self.list = InventoryListCtrl(self, tID,
                                 style=wxLC_REPORT | wxSUNKEN_BORDER
                                 | wxLC_EDIT_LABELS
                                 #| wxLC_NO_HEADER
                                 #| wxLC_VRULES | wxLC_HRULES
                                 )
        self.list.InsertColumn(0,"Title")
        self.list.InsertColumn(1,"Author")
        self.list.InsertColumn(2,"Price")
        self.list.InsertColumn(3,"Publisher")
        self.list.InsertColumn(4,"Status")
        self.list.InsertColumn(5,"ISBN")
        self.list.InsertColumn(6,"Distributor")
        self.list.InsertColumn(7,"Notes")
        self.list.InsertColumn(8,"ID")
        self.list.InsertColumn(9,"Kind")
        
        self.master_sizer.Add(self.list, flag=wxGROW, proportion=1)

        self.SetSizer(self.master_sizer)
        self.SetAutoLayout(1)
        self.master_sizer.Fit(self)