def create_animal_from_found(dbo, username, aid): """ Creates an animal record from a found animal with the id given """ a = dbo.first_row( dbo.query("SELECT * FROM animalfound WHERE ID = %d" % int(aid)) ) l = dbo.locale data = { "animalname": _("Found Animal {0}", l).format(aid), "markings": str(a["DISTFEAT"]), "species": str(a["ANIMALTYPEID"]), "comments": str(a["COMMENTS"]), "broughtinby": str(a["OWNERID"]), "originalowner": str(a["OWNERID"]), "animaltype": asm3.configuration.default_type(dbo), "breed1": a["BREEDID"], "breed2": a["BREEDID"], "basecolour": str(a["BASECOLOURID"]), "microchipped": asm3.utils.iif(a["MICROCHIPNUMBER"] is not None and a["MICROCHIPNUMBER"] != "", "1", "0"), "microchipnumber": a["MICROCHIPNUMBER"], "size": asm3.configuration.default_size(dbo), "internallocation": asm3.configuration.default_location(dbo), "dateofbirth": python2display(l, subtract_years(now(dbo.timezone))), "estimateddob": "1", } # If we're creating shelter codes manually, we need to put something unique # in there for now. Use the id if asm3.configuration.manual_codes(dbo): data["sheltercode"] = "FA" + str(aid) data["shortcode"] = "FA" + str(aid) nextid, dummy = asm3.animal.insert_animal_from_form(dbo, asm3.utils.PostedData(data, l), username) return nextid
def create_animal(dbo, username, wlid): """ Creates an animal record from a waiting list entry with the id given """ l = dbo.locale a = dbo.first_row( dbo.query("SELECT * FROM animalwaitinglist WHERE ID = ?", [wlid])) data = { "animalname": _("Waiting List {0}", l).format(wlid), "markings": str(a["ANIMALDESCRIPTION"]), "reasonforentry": str(a["REASONFORWANTINGTOPART"]), "species": str(a["SPECIESID"]), "hiddenanimaldetails": str(a["COMMENTS"]), "broughtinby": str(a["OWNERID"]), "originalowner": str(a["OWNERID"]), "animaltype": asm3.configuration.default_type(dbo), "entryreason": asm3.configuration.default_entry_reason(dbo), "breed1": asm3.configuration.default_breed(dbo), "breed2": asm3.configuration.default_breed(dbo), "basecolour": asm3.configuration.default_colour(dbo), "size": asm3.configuration.default_size(dbo), "internallocation": asm3.configuration.default_location(dbo), "dateofbirth": python2display(l, subtract_years(now(dbo.timezone))), "estimateddob": "1" } # If we aren't showing the time brought in, set it to midnight if not asm3.configuration.add_animals_show_time_brought_in(dbo): data["timebroughtin"] = "00:00:00" # If we're creating shelter codes manually, we need to put something unique # in there for now. Use the id if asm3.configuration.manual_codes(dbo): data["sheltercode"] = "WL" + str(wlid) data["shortcode"] = "WL" + str(wlid) nextid, code = asm3.animal.insert_animal_from_form( dbo, asm3.utils.PostedData(data, l), username) # Now that we've created our animal, we should remove this entry from the waiting list dbo.update( "animalwaitinglist", wlid, { "DateRemovedFromList": dbo.today(), "ReasonForRemoval": _("Moved to animal record {0}", l).format(code) }, username) # If there were any logs and media entries on the waiting list, create them on the animal # Media for me in dbo.query( "SELECT * FROM media WHERE LinkTypeID = ? AND LinkID = ?", (asm3.media.WAITINGLIST, wlid)): ext = me.medianame ext = ext[ext.rfind("."):].lower() mediaid = dbo.get_id("media") medianame = "%d%s" % (mediaid, ext) dbo.insert( "media", { "ID": mediaid, "DBFSID": 0, "MediaSize": 0, "MediaName": medianame, "MediaMimeType": asm3.media.mime_type(medianame), "MediaType": me.mediatype, "MediaNotes": me.medianotes, "WebsitePhoto": me.websitephoto, "WebsiteVideo": me.websitevideo, "DocPhoto": me.docphoto, "ExcludeFromPublish": me.excludefrompublish, # ASM2_COMPATIBILITY "NewSinceLastPublish": 1, "UpdatedSinceLastPublish": 0, # ASM2_COMPATIBILITY "LinkID": nextid, "LinkTypeID": asm3.media.ANIMAL, "Date": me.date, "CreatedDate": me.createddate, "RetainUntil": me.retainuntil }, generateID=False) # Now clone the dbfs item pointed to by this media item if it's a file if me.mediatype == asm3.media.MEDIATYPE_FILE: filedata = asm3.dbfs.get_string(dbo, me.medianame) dbfsid = asm3.dbfs.put_string(dbo, medianame, "/animal/%d" % nextid, filedata) dbo.execute( "UPDATE media SET DBFSID = ?, MediaSize = ? WHERE ID = ?", (dbfsid, len(filedata), mediaid)) # Logs for lo in dbo.query("SELECT * FROM log WHERE LinkType = ? AND LinkID = ?", (asm3.log.WAITINGLIST, wlid)): dbo.insert( "log", { "LinkID": nextid, "LinkType": asm3.log.ANIMAL, "LogTypeID": lo.LOGTYPEID, "Date": lo.DATE, "Comments": lo.COMMENTS }, username) return nextid