def get_territory_docs(territory_id): """ collects all docs for territory """ territory = {} for doc in get_all_docs_for(territory_id): street = get_street(doc["address"]) if street not in territory: territory[street] = [] territory[street].append(doc) return territory.items()
def change_address_and_add_owner_data(doc, address, owner_data): """ updates wrong address and adds assessor results """ updates = { "assessorAccountNumber": owner_data.get("account_number", None), "lastUpdate": datetime.now(), "ownerName": owner_data["owner_name"], "ownerLivesThere": owner_data["lives_there"], "address": address, "street": get_street(address), } ADDR.update_one(doc, {"$set": updates})
def add_address(territory_id, doc): """ add address to collection it ain't already there """ if "coords" not in doc: raise CoordsMissingException if not ADDR.find_one({"coords": doc["coords"]}): doc.update({ "territoryId": territory_id, "street": get_street(doc["address"]), "lastUpdate": datetime.now(), }) ADDR.insert(doc)