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 = configuration.waiting_list_urgency_update_period(dbo) if update_period_days == 0: al.debug( "urgency update period is 0, not updating waiting list entries", "waitinglist.auto_update_urgencies", dbo) return rows = db.query(dbo, "SELECT a.* " \ "FROM animalwaitinglist a WHERE UrgencyUpdateDate <= %s " \ "AND Urgency > 2" % db.dd(now(dbo.timezone))) updates = [] for r in rows: al.debug("increasing urgency of waitinglist entry %d" % int(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: db.execute_many(dbo, "UPDATE animalwaitinglist SET " \ "UrgencyLastUpdatedDate=%s, " \ "UrgencyUpdateDate=%s, " \ "Urgency=%s " \ "WHERE ID=%s ", updates)
def update_missing_geocodes(dbo): """ Goes through all people records without geocodes and completes the missing ones, using our configured bulk geocoding service. We limit this to LIMIT geocode requests per call so that databases with a lot of historical data don't end up tying up the daily batch for a long time, they'll just slowly complete over time. """ LIMIT = 250 people = db.query(dbo, "SELECT ID, OwnerAddress, OwnerTown, OwnerCounty, OwnerPostcode " \ "FROM owner WHERE LatLong Is Null OR LatLong = '' LIMIT %d" % LIMIT) batch = [] for p in people: latlong = geo.get_lat_long(dbo, p["OWNERADDRESS"], p["OWNERTOWN"], p["OWNERCOUNTY"], p["OWNERPOSTCODE"]) if latlong is not None: batch.append((latlong, p["ID"])) db.execute_many(dbo, "UPDATE owner SET LatLong = %s WHERE ID = %s", batch) al.debug("updated %d person geocodes" % len(batch), "person.update_missing_geocodes", dbo)
def auto_remove_waitinglist(dbo): """ Finds and automatically marks entries removed that have gone past the last contact date + weeks. """ l = dbo.locale rows = db.query(dbo, "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): al.debug("auto removing waitinglist entry %d due to policy" % int(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: db.execute_many(dbo, "UPDATE animalwaitinglist SET DateRemovedFromList = %s, " \ "ReasonForRemoval=%s WHERE ID=%s", updates)
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 = configuration.waiting_list_urgency_update_period(dbo) if update_period_days == 0: al.debug("urgency update period is 0, not updating waiting list entries", "waitinglist.auto_update_urgencies", dbo) return rows = db.query(dbo, "SELECT a.* " \ "FROM animalwaitinglist a WHERE UrgencyUpdateDate <= %s " \ "AND Urgency > 2" % db.dd(now(dbo.timezone))) updates = [] for r in rows: al.debug("increasing urgency of waitinglist entry %d" % int(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: db.execute_many(dbo, "UPDATE animalwaitinglist SET " \ "UrgencyLastUpdatedDate=%s, " \ "UrgencyUpdateDate=%s, " \ "Urgency=%s " \ "WHERE ID=%s ", 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 = db.query(dbo, "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): al.debug( "auto removing waitinglist entry %d due to policy" % int(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: db.execute_many(dbo, "UPDATE animalwaitinglist SET DateRemovedFromList = %s, " \ "ReasonForRemoval=%s WHERE ID=%s", updates)