def create_animalcontrol(dbo, username, collationid): """ Creates a animal control/incident record from the incoming form data with collationid. Also, attaches the form to the incident as media. """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) d = {} d["incidentdate"] = i18n.python2display(l, i18n.now(dbo.timezone)) d["incidenttime"] = i18n.format_time_now(dbo.timezone) d["calldate"] = d["incidentdate"] d["calltime"] = d["incidenttime"] d["incidenttype"] = 1 for f in fields: if f["FIELDNAME"] == "callnotes": d["callnotes"] = f["VALUE"] if f["FIELDNAME"] == "dispatchaddress": d["dispatchaddress"] = f["VALUE"] if f["FIELDNAME"] == "dispatchcity": d["dispatchtown"] = f["VALUE"] if f["FIELDNAME"] == "dispatchstate": d["dispatchcounty"] = f["VALUE"] if f["FIELDNAME"] == "dispatchzipcode": d["dispatchpostcode"] = f["VALUE"] # Have we got enough info to create the animal control record? We need notes and dispatchaddress if not d.has_key("callnotes") or not d.has_key("dispatchaddress"): raise utils.ASMValidationError(i18n._("There is not enough information in the form to create an incident record (need call notes and dispatch address).", l)) # We need the person/caller record before we create the incident collationid, personid, personname = create_person(dbo, username, collationid) d["caller"] = personid # Create the incident incidentid = animalcontrol.insert_animalcontrol_from_form(dbo, utils.PostedData(d, dbo.locale), username) # Attach the form to the incident formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html(dbo, collationid) media.create_document_media(dbo, username, media.ANIMALCONTROL, incidentid, formname, formhtml ) return (collationid, incidentid, utils.padleft(incidentid, 6) + " - " + personname)
def create_waitinglist(dbo, username, collationid): """ Creates a waitinglist record from the incoming form data with collationid. Also, attaches the form to the waiting list as media. """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) d = {} d["dateputon"] = i18n.python2display(l, i18n.now(dbo.timezone)) d["urgency"] = "5" for f in fields: if f["FIELDNAME"] == "species": d["species"] = guess_species(dbo, f["VALUE"]) if f["FIELDNAME"] == "description": d["description"] = f["VALUE"] if f["FIELDNAME"] == "reason": d["reasonforwantingtopart"] = f["VALUE"] if not d.has_key("species"): d["species"] = guess_species(dbo, "") # Have we got enough info to create the waiting list record? We need a description if not d.has_key("description"): raise utils.ASMValidationError( i18n._( "There is not enough information in the form to create a waiting list record (need a description).", l)) # We need the person record before we create the waiting list collationid, personid, personname = create_person(dbo, username, collationid) d["owner"] = personid # Create the waiting list wlid = waitinglist.insert_waitinglist_from_form(dbo, d, username) # Attach the form to the waiting list formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html(dbo, collationid) media.create_document_media(dbo, username, media.WAITINGLIST, wlid, formname, formhtml) return (collationid, wlid, utils.padleft(wlid, 6) + " - " + personname)
def create_waitinglist(dbo, username, collationid): """ Creates a waitinglist record from the incoming form data with collationid. Also, attaches the form to the waiting list as media. """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) d = {} d["dateputon"] = i18n.python2display(l, i18n.now(dbo.timezone)) d["urgency"] = "5" for f in fields: if f["FIELDNAME"] == "species": d["species"] = guess_species(dbo, f["VALUE"]) if f["FIELDNAME"] == "description": d["description"] = f["VALUE"] if f["FIELDNAME"] == "reason": d["reasonforwantingtopart"] = f["VALUE"] if not d.has_key("species"): d["species"] = guess_species(dbo, "") # Have we got enough info to create the waiting list record? We need a description if not d.has_key("description"): raise utils.ASMValidationError(i18n._("There is not enough information in the form to create a waiting list record (need a description).", l)) # We need the person record before we create the waiting list collationid, personid, personname = create_person(dbo, username, collationid) d["owner"] = personid # Create the waiting list wlid = waitinglist.insert_waitinglist_from_form(dbo, d, username) # Attach the form to the waiting list formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html(dbo, collationid) media.create_document_media(dbo, username, media.WAITINGLIST, wlid, formname, formhtml ) return (collationid, wlid, utils.padleft(wlid, 6) + " - " + personname)
def create_person(dbo, username, collationid): """ Creates a person record from the incoming form data with collationid. Also, attaches the form to the person as media. The return value is tuple of collationid, personid, personname """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) d = {} flags = None for f in fields: if flags is None: flags = f["FLAGS"] if f["FIELDNAME"] == "title": d["title"] = f["VALUE"] if f["FIELDNAME"] == "forenames": d["forenames"] = f["VALUE"] if f["FIELDNAME"] == "firstname": d["forenames"] = f["VALUE"] if f["FIELDNAME"] == "surname": d["surname"] = f["VALUE"] if f["FIELDNAME"] == "lastname": d["surname"] = f["VALUE"] if f["FIELDNAME"] == "address": d["address"] = f["VALUE"] if f["FIELDNAME"] == "town": d["town"] = f["VALUE"] if f["FIELDNAME"] == "city": d["town"] = f["VALUE"] if f["FIELDNAME"] == "county": d["county"] = f["VALUE"] if f["FIELDNAME"] == "state": d["county"] = f["VALUE"] if f["FIELDNAME"] == "postcode": d["postcode"] = f["VALUE"] if f["FIELDNAME"] == "zipcode": d["postcode"] = f["VALUE"] if f["FIELDNAME"] == "hometelephone": d["hometelephone"] = f["VALUE"] if f["FIELDNAME"] == "worktelephone": d["worktelephone"] = f["VALUE"] if f["FIELDNAME"] == "mobiletelephone": d["mobiletelephone"] = f["VALUE"] if f["FIELDNAME"] == "celltelephone": d["mobiletelephone"] = f["VALUE"] if f["FIELDNAME"] == "emailaddress": d["emailaddress"] = f["VALUE"] if f["FIELDNAME"].startswith("reserveanimalname"): d[f["FIELDNAME"]] = f["VALUE"] d["flags"] = flags # Have we got enough info to create the person record? We just need a surname if not d.has_key("surname"): raise utils.ASMValidationError(i18n._("There is not enough information in the form to create a person record (need a surname).", l)) # Does this person already exist? personid = 0 if d.has_key("surname") and d.has_key("forenames") and d.has_key("address"): similar = person.get_person_similar(dbo, d["surname"], d["forenames"], d["address"]) if len(similar) > 0: personid = similar[0]["ID"] # Create the person record if we didn't find one if personid == 0: personid = person.insert_person_from_form(dbo, utils.PostedData(d, dbo.locale), username) personname = person.get_person_name_code(dbo, personid) # Attach the form to the person formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html_print(dbo, [collationid,]) media.create_document_media(dbo, username, media.PERSON, personid, formname, formhtml ) # Was there a reserveanimalname field? If so, create reservation(s) to the person if possible for k, v in d.iteritems(): if k.startswith("reserveanimalname"): movement.insert_reserve_for_animal_name(dbo, username, personid, v) return (collationid, personid, personname)
def create_foundanimal(dbo, username, collationid): """ Creates a found animal record from the incoming form data with collationid. Also, attaches the form to the found animal as media. """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) d = {} d["datefound"] = i18n.python2display(l, i18n.now(dbo.timezone)) d["datereported"] = i18n.python2display(l, i18n.now(dbo.timezone)) for f in fields: if f["FIELDNAME"] == "species": d["species"] = guess_species(dbo, f["VALUE"]) if f["FIELDNAME"] == "sex": d["sex"] = guess_sex(dbo, f["VALUE"]) if f["FIELDNAME"] == "breed": d["breed"] = guess_breed(dbo, f["VALUE"]) if f["FIELDNAME"] == "agegroup": d["agegroup"] = guess_agegroup(dbo, f["VALUE"]) if f["FIELDNAME"] == "color": d["colour"] = guess_colour(dbo, f["VALUE"]) if f["FIELDNAME"] == "colour": d["colour"] = guess_colour(dbo, f["VALUE"]) if f["FIELDNAME"] == "description": d["markings"] = f["VALUE"] if f["FIELDNAME"] == "areafound": d["areafound"] = f["VALUE"] if f["FIELDNAME"] == "areapostcode": d["areapostcode"] = f["VALUE"] if f["FIELDNAME"] == "areazipcode": d["areazipcode"] = f["VALUE"] if not d.has_key("species"): d["species"] = guess_species(dbo, "") if not d.has_key("sex"): d["sex"] = guess_sex(dbo, "") if not d.has_key("breed"): d["breed"] = guess_breed(dbo, "") if not d.has_key("agegroup"): d["agegroup"] = guess_agegroup(dbo, "") if not d.has_key("colour"): d["colour"] = guess_colour(dbo, "") # Have we got enough info to create the found animal record? We need a description and areafound if not d.has_key("markings") or not d.has_key("areafound"): raise utils.ASMValidationError( i18n._( "There is not enough information in the form to create a found animal record (need a description and area found).", l)) # We need the person record before we create the found animal collationid, personid, personname = create_person(dbo, username, collationid) d["owner"] = personid # Create the found animal foundanimalid = lostfound.insert_foundanimal_from_form(dbo, d, username) # Attach the form to the found animal formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html(dbo, collationid) media.create_document_media(dbo, username, media.FOUNDANIMAL, foundanimalid, formname, formhtml) return (collationid, foundanimalid, utils.padleft(foundanimalid, 6) + " - " + personname)
def create_person(dbo, username, collationid): """ Creates a person record from the incoming form data with collationid. Also, attaches the form to the person as media. The return value is tuple of collationid, personid, personname """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) d = {} flags = None for f in fields: if flags is None: flags = f["FLAGS"] if f["FIELDNAME"] == "title": d["title"] = f["VALUE"] if f["FIELDNAME"] == "forenames": d["forenames"] = f["VALUE"] if f["FIELDNAME"] == "firstname": d["forenames"] = f["VALUE"] if f["FIELDNAME"] == "surname": d["surname"] = f["VALUE"] if f["FIELDNAME"] == "lastname": d["surname"] = f["VALUE"] if f["FIELDNAME"] == "address": d["address"] = f["VALUE"] if f["FIELDNAME"] == "town": d["town"] = f["VALUE"] if f["FIELDNAME"] == "city": d["town"] = f["VALUE"] if f["FIELDNAME"] == "county": d["county"] = f["VALUE"] if f["FIELDNAME"] == "state": d["county"] = f["VALUE"] if f["FIELDNAME"] == "postcode": d["postcode"] = f["VALUE"] if f["FIELDNAME"] == "zipcode": d["postcode"] = f["VALUE"] if f["FIELDNAME"] == "hometelephone": d["hometelephone"] = f["VALUE"] if f["FIELDNAME"] == "worktelephone": d["worktelephone"] = f["VALUE"] if f["FIELDNAME"] == "mobiletelephone": d["mobiletelephone"] = f["VALUE"] if f["FIELDNAME"] == "celltelephone": d["mobiletelephone"] = f["VALUE"] if f["FIELDNAME"] == "emailaddress": d["emailaddress"] = f["VALUE"] d["flags"] = flags # Have we got enough info to create the person record? We just need a surname if not d.has_key("surname"): raise utils.ASMValidationError( i18n._( "There is not enough information in the form to create a person record (need a surname).", l)) # Create the person record personid = person.insert_person_from_form(dbo, d, username) personname = person.get_person_name_code(dbo, personid) # Attach the form to the person formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html(dbo, collationid) media.create_document_media(dbo, username, media.PERSON, personid, formname, formhtml) return (collationid, personid, personname)
def create_person(dbo, username, collationid): """ Creates a person record from the incoming form data with collationid. Also, attaches the form to the person as media. The return value is tuple of collationid, personid, personname """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) d = {} flags = None for f in fields: if flags is None: flags = f["FLAGS"] if f["FIELDNAME"] == "title": d["title"] = f["VALUE"] if f["FIELDNAME"] == "forenames": d["forenames"] = f["VALUE"] if f["FIELDNAME"] == "firstname": d["forenames"] = f["VALUE"] if f["FIELDNAME"] == "surname": d["surname"] = f["VALUE"] if f["FIELDNAME"] == "lastname": d["surname"] = f["VALUE"] if f["FIELDNAME"] == "address": d["address"] = f["VALUE"] if f["FIELDNAME"] == "town": d["town"] = f["VALUE"] if f["FIELDNAME"] == "city": d["town"] = f["VALUE"] if f["FIELDNAME"] == "county": d["county"] = f["VALUE"] if f["FIELDNAME"] == "state": d["county"] = f["VALUE"] if f["FIELDNAME"] == "postcode": d["postcode"] = f["VALUE"] if f["FIELDNAME"] == "zipcode": d["postcode"] = f["VALUE"] if f["FIELDNAME"] == "hometelephone": d["hometelephone"] = f["VALUE"] if f["FIELDNAME"] == "worktelephone": d["worktelephone"] = f["VALUE"] if f["FIELDNAME"] == "mobiletelephone": d["mobiletelephone"] = f["VALUE"] if f["FIELDNAME"] == "celltelephone": d["mobiletelephone"] = f["VALUE"] if f["FIELDNAME"] == "emailaddress": d["emailaddress"] = f["VALUE"] d["flags"] = flags # Have we got enough info to create the person record? We just need a surname if not d.has_key("surname"): raise utils.ASMValidationError(i18n._("There is not enough information in the form to create a person record (need a surname).", l)) # Create the person record personid = person.insert_person_from_form(dbo, d, username) personname = person.get_person_name_code(dbo, personid) # Attach the form to the person formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html(dbo, collationid) media.create_document_media(dbo, username, media.PERSON, personid, formname, formhtml ) return (collationid, personid, personname)
def attach_animal(dbo, username, collationid): """ Finds the existing shelter animal with "animalname" and attaches the form to it as person media. Return value is a tuple of collationid, animalid, animal code/name """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) animalname = "" for f in fields: if f["FIELDNAME"] == "animalname": animalname = f["VALUE"] if animalname == "": raise utils.ASMValidationError(i18n._("There is not enough information in the form to attach to a shelter animal record (need an animal name).", l)) # Find the animal aid = db.query_int(dbo, "SELECT ID FROM animal WHERE LOWER(AnimalName) LIKE '%s' ORDER BY ID DESC" % animalname.lower()) if aid == 0: raise utils.ASMValidationError(i18n._("Could not find animal with name '{0}'", l).format(animalname)) formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html_print(dbo, [collationid,]) media.create_document_media(dbo, username, media.ANIMAL, aid, formname, formhtml ) return (collationid, aid, animal.get_animal_namecode(dbo, aid))
def create_foundanimal(dbo, username, collationid): """ Creates a found animal record from the incoming form data with collationid. Also, attaches the form to the found animal as media. """ l = dbo.locale fields = get_onlineformincoming_detail(dbo, collationid) d = {} d["datefound"] = i18n.python2display(l, i18n.now(dbo.timezone)) d["datereported"] = i18n.python2display(l, i18n.now(dbo.timezone)) for f in fields: if f["FIELDNAME"] == "species": d["species"] = guess_species(dbo, f["VALUE"]) if f["FIELDNAME"] == "sex": d["sex"] = guess_sex(dbo, f["VALUE"]) if f["FIELDNAME"] == "breed": d["breed"] = guess_breed(dbo, f["VALUE"]) if f["FIELDNAME"] == "agegroup": d["agegroup"] = guess_agegroup(dbo, f["VALUE"]) if f["FIELDNAME"] == "color": d["colour"] = guess_colour(dbo, f["VALUE"]) if f["FIELDNAME"] == "colour": d["colour"] = guess_colour(dbo, f["VALUE"]) if f["FIELDNAME"] == "description": d["markings"] = f["VALUE"] if f["FIELDNAME"] == "areafound": d["areafound"] = f["VALUE"] if f["FIELDNAME"] == "areapostcode": d["areapostcode"] = f["VALUE"] if f["FIELDNAME"] == "areazipcode": d["areazipcode"] = f["VALUE"] if not d.has_key("species"): d["species"] = guess_species(dbo, "") if not d.has_key("sex"): d["sex"] = guess_sex(dbo, "") if not d.has_key("breed"): d["breed"] = guess_breed(dbo, "") if not d.has_key("agegroup"): d["agegroup"] = guess_agegroup(dbo, "") if not d.has_key("colour"): d["colour"] = guess_colour(dbo, "") # Have we got enough info to create the found animal record? We need a description and areafound if not d.has_key("markings") or not d.has_key("areafound"): raise utils.ASMValidationError(i18n._("There is not enough information in the form to create a found animal record (need a description and area found).", l)) # We need the person record before we create the found animal collationid, personid, personname = create_person(dbo, username, collationid) d["owner"] = personid # Create the found animal foundanimalid = lostfound.insert_foundanimal_from_form(dbo, d, username) # Attach the form to the found animal formname = get_onlineformincoming_name(dbo, collationid) formhtml = get_onlineformincoming_html(dbo, collationid) media.create_document_media(dbo, username, media.FOUNDANIMAL, foundanimalid, formname, formhtml ) return (collationid, foundanimalid, utils.padleft(foundanimalid, 6) + " - " + personname)