def auto_update_urgencies(dbo): """ Finds all animals where the next UrgencyUpdateDate field is greater than or equal to today and the urgency is larger than High (so we can never reach Urgent). """ update_period_days = asm3.configuration.waiting_list_urgency_update_period( dbo) if update_period_days == 0: asm3.al.debug( "urgency update period is 0, not updating waiting list entries", "waitinglist.auto_update_urgencies", dbo) return rows = dbo.query("SELECT a.* " \ "FROM animalwaitinglist a WHERE UrgencyUpdateDate <= ? " \ "AND Urgency > 2", [dbo.today()]) updates = [] for r in rows: asm3.al.debug("increasing urgency of waitinglist entry %d" % r.ID, "waitinglist.auto_update_urgencies", dbo) updates.append((now(dbo.timezone), add_days(r.URGENCYUPDATEDATE, update_period_days), r.URGENCY - 1, r.ID)) if len(updates) > 0: dbo.execute_many("UPDATE animalwaitinglist SET " \ "UrgencyLastUpdatedDate=?, " \ "UrgencyUpdateDate=?, " \ "Urgency=? " \ "WHERE ID=? ", updates)
def auto_remove_waitinglist(dbo): """ Finds and automatically marks entries removed that have gone past the last contact date + weeks. """ l = dbo.locale rows = dbo.query("SELECT a.ID, a.DateOfLastOwnerContact, " \ "a.AutoRemovePolicy " \ "FROM animalwaitinglist a WHERE a.DateRemovedFromList Is Null " \ "AND AutoRemovePolicy > 0 AND DateOfLastOwnerContact Is Not Null") updates = [] for r in rows: xdate = add_days(r.DATEOFLASTOWNERCONTACT, 7 * r.AUTOREMOVEPOLICY) if after(now(dbo.timezone), xdate): asm3.al.debug("auto removing waitinglist entry %d due to policy" % r.ID, "waitinglist.auto_remove_waitinglist", dbo) updates.append((now(dbo.timezone), _("Auto removed due to lack of owner contact.", l), r.ID)) if len(updates) > 0: dbo.execute_many("UPDATE animalwaitinglist SET DateRemovedFromList = ?, " \ "ReasonForRemoval=? WHERE ID=?", updates)