def update_waitinglist_highlight(dbo, wlid, himode): """ Toggles a waiting list ID record as highlighted. wlid: The waiting list id to toggle himode: a highlight value from 1 to 5 for a colour """ hl = list(configuration.waiting_list_highlights(dbo).split(" ")) wlid = str(wlid).strip() # Create a new highlight list that doesn't have our id in it nl = [] removed = False for hi in hl: if hi != "": if hi.find("|") != -1: wid, h = hi.split("|") else: wid = hi h = "1" if wlid == wid: removed = True else: nl.append(wid + "|" + h) # If our id wasn't present in the list, add it (so we're # effectively toggling the id on and off) if not removed: nl.append(wlid + "|" + himode) configuration.waiting_list_highlights(dbo, " ".join(nl))
def get_waitinglist(dbo, priorityfloor=5, species=-1, addresscontains="", includeremoved=0, namecontains="", descriptioncontains=""): """ Retrieves the waiting list priorityfloor: The lowest urgency to show (1 = urgent, 5 = lowest) species: A species filter or -1 for all addresscontains: A partial address includeremoved: Whether or not to include removed entries namecontains: A partial name descriptioncontains: A partial description """ l = dbo.locale ranks = get_waitinglist_ranks(dbo) sql = get_waitinglist_query() + " WHERE a.Urgency <= " + str(priorityfloor) if includeremoved == 0: sql += " AND a.DateRemovedFromList Is Null" if species != -1: sql += " AND a.SpeciesID = " + str(species) if addresscontains != "": sql += " AND UPPER(OwnerAddress) Like '%" + str( addresscontains).upper().replace("'", "`") + "%'" if namecontains != "": sql += " AND UPPER(OwnerName) Like '%" + str( namecontains).upper().replace("'", "`") + "%'" if descriptioncontains != "": sql += " AND UPPER(AnimalDescription) Like '%" + str( descriptioncontains).upper().replace("'", "`") + "%'" sql += " ORDER BY a.Urgency, a.DatePutOnList" rows = db.query(dbo, sql) wlh = configuration.waiting_list_highlights(dbo).split(" ") for r in rows: r["HIGHLIGHT"] = "" for hi in wlh: if hi != "": if hi.find("|") == -1: wid = hi h = "1" else: wid, h = hi.split("|") if wid == str(r["WLID"]).strip(): r["HIGHLIGHT"] = h break if ranks.has_key(r["WLID"]): r["RANK"] = ranks[r["WLID"]] else: r["RANK"] = "" r["TIMEONLIST"] = date_diff(l, r["DATEPUTONLIST"], now(dbo.timezone)) return rows
def get_waitinglist(dbo, priorityfloor = 5, species = -1, addresscontains = "", includeremoved = 0, namecontains = "", descriptioncontains = ""): """ Retrieves the waiting list priorityfloor: The lowest urgency to show (1 = urgent, 5 = lowest) species: A species filter or -1 for all addresscontains: A partial address includeremoved: Whether or not to include removed entries namecontains: A partial name descriptioncontains: A partial description """ l = dbo.locale ranks = get_waitinglist_ranks(dbo) sql = get_waitinglist_query() + " WHERE a.Urgency <= " + str(priorityfloor) if includeremoved == 0: sql += " AND a.DateRemovedFromList Is Null" if species != -1: sql += " AND a.SpeciesID = " + str(species) if addresscontains != "": sql += " AND UPPER(OwnerAddress) Like '%" + str(addresscontains).upper().replace("'", "`") + "%'" if namecontains != "": sql += " AND UPPER(OwnerName) Like '%" + str(namecontains).upper().replace("'", "`") + "%'" if descriptioncontains != "": sql += " AND UPPER(AnimalDescription) Like '%" + str(descriptioncontains).upper().replace("'", "`") + "%'" sql += " ORDER BY a.Urgency, a.DatePutOnList" rows = db.query(dbo, sql) wlh = configuration.waiting_list_highlights(dbo).split(" ") for r in rows: r["HIGHLIGHT"] = "" for hi in wlh: if hi != "": if hi.find("|") == -1: wid = hi h = "1" else: wid, h = hi.split("|") if wid == str(r["WLID"]).strip(): r["HIGHLIGHT"] = h break if ranks.has_key(r["WLID"]): r["RANK"] = ranks[r["WLID"]] else: r["RANK"] = "" r["TIMEONLIST"] = date_diff(l, r["DATEPUTONLIST"], now(dbo.timezone)) return rows
def get_waitinglist(dbo, priorityfloor=5, species=-1, size=-1, addresscontains="", includeremoved=0, namecontains="", descriptioncontains="", siteid=0): """ Retrieves the waiting list priorityfloor: The lowest urgency to show (1 = urgent, 5 = lowest) species: A species filter or -1 for all size: A size filter or -1 for all addresscontains: A partial address includeremoved: Whether or not to include removed entries namecontains: A partial name descriptioncontains: A partial description """ l = dbo.locale ands = [] values = [] def add(a, v=None): ands.append(a) if v: values.append(v) add("a.Urgency <= ?", priorityfloor) if includeremoved == 0: add("a.DateRemovedFromList Is Null") if species != -1: add("a.SpeciesID = ?", species) if size != -1: add("a.Size = ?", size) if addresscontains != "": add("UPPER(OwnerAddress) LIKE ?", "%%%s%%" % addresscontains.upper()) if namecontains != "": add("UPPER(OwnerName) LIKE ?", "%%%s%%" % namecontains.upper()) if descriptioncontains != "": add("UPPER(AnimalDescription) LIKE ?", "%%%s%%" % descriptioncontains.upper()) if siteid != 0: add("(o.SiteID = 0 OR o.SiteID = ?)", siteid) sql = "%s WHERE %s ORDER BY a.Urgency, a.DatePutOnList" % ( get_waitinglist_query(dbo), " AND ".join(ands)) rows = dbo.query(sql, values) wlh = configuration.waiting_list_highlights(dbo).split(" ") ranks = get_waitinglist_ranks(dbo) for r in rows: r.HIGHLIGHT = "" for hi in wlh: if hi != "": if hi.find("|") == -1: wid = hi h = "1" else: wid, h = hi.split("|") if wid == str(r.WLID).strip(): r.HIGHLIGHT = h break if r.WLID in ranks: r.RANK = ranks[r.WLID] else: r.RANK = "" r.TIMEONLIST = date_diff(l, r.DATEPUTONLIST, now(dbo.timezone)) return rows