def create_document_media(dbo, username, linktype, linkid, template, content): """ Creates a new media record for a document for the link given. linktype: ANIMAL, PERSON, etc linkid: ID for the link template: The name of the template used to create the document content: The document contents """ mediaid = db.get_id(dbo, "media") sql = db.make_insert_sql( "media", (("ID", db.di(mediaid)), ("MediaName", db.ds("%d.html" % mediaid)), ("MediaType", db.di(0)), ("MediaNotes", db.ds(template)), ("WebsitePhoto", db.di(0)), ("WebsiteVideo", db.di(0)), ("DocPhoto", db.di(0)), ("ExcludeFromPublish", db.di(0)), ("NewSinceLastPublish", db.di(1)), ("UpdatedSinceLastPublish", db.di(0)), ("LinkID", db.di(linkid)), ("LinkTypeID", db.di(linktype)), ("Date", db.nowsql()))) db.execute(dbo, sql) path = "" if linktype == ANIMAL: path = "/animal" elif linktype == PERSON: path = "/owner" elif linktype == LOSTANIMAL: path = "/lostanimal" elif linktype == FOUNDANIMAL: path = "/foundanimal" path += "/" + str(linkid) name = str(mediaid) + ".html" dbfs.put_string(dbo, name, path, content) audit.create(dbo, username, "media", str(mediaid) + ": for " + str(linkid) + "/" + str(linktype))
def attach_link_from_form(dbo, username, linktype, linkid, post): """ Attaches a link to a web resource from a form """ existingvid = db.query_int(dbo, "SELECT COUNT(*) FROM media WHERE WebsiteVideo = 1 " \ "AND LinkID = %d AND LinkTypeID = %d" % ( int(linkid), int(linktype) )) defvid = 0 if existingvid == 0 and post.integer("linktype") == MEDIATYPE_VIDEO_LINK: defvid = 1 mediaid = db.get_id(dbo, "media") url = post["linktarget"] if url.find("://") == -1: url = "http://" + url al.debug("attached link %s" % url, "media.attach_file_from_form") sql = db.make_insert_sql("media", ( ( "ID", db.di(mediaid) ), ( "MediaName", db.ds(url) ), ( "MediaType", post.db_integer("linktype") ), ( "MediaNotes", post.db_string("comments") ), ( "WebsitePhoto", db.di(0) ), ( "WebsiteVideo", db.di(defvid) ), ( "DocPhoto", db.di(0) ), ( "ExcludeFromPublish", db.di(0) ), # ASM2_COMPATIBILITY ( "NewSinceLastPublish", db.di(1) ), ( "UpdatedSinceLastPublish", db.di(0) ), # ASM2_COMPATIBILITY ( "LinkID", db.di(linkid) ), ( "LinkTypeID", db.di(linktype) ), ( "Date", db.nowsql() ) )) db.execute(dbo, sql) audit.create(dbo, username, "media", mediaid, str(mediaid) + ": for " + str(linkid) + "/" + str(linktype) + ": link to " + post["linktarget"])
def insert_transport_from_form(dbo, username, post): """ Creates a transport record from posted form data """ l = dbo.locale if post.integer("animal") == 0: raise utils.ASMValidationError(i18n._("Transport requires an animal", l)) transportid = db.get_id(dbo, "animaltransport") sql = db.make_insert_user_sql(dbo, "animaltransport", username, ( ( "ID", db.di(transportid)), ( "AnimalID", post.db_integer("animal")), ( "DriverOwnerID", post.db_integer("driver")), ( "PickupOwnerID", post.db_integer("pickup")), ( "PickupAddress", post.db_string("pickupaddress")), ( "PickupTown", post.db_string("pickuptown")), ( "PickupCounty", post.db_string("pickupcounty")), ( "PickupDateTime", post.db_datetime("pickupdate", "pickuptime")), ( "PickupPostcode", post.db_string("pickuppostcode")), ( "DropoffOwnerID", post.db_integer("dropoff")), ( "DropoffAddress", post.db_string("dropoffaddress")), ( "DropoffTown", post.db_string("dropofftown")), ( "DropoffCounty", post.db_string("dropoffcounty")), ( "DropoffPostcode", post.db_string("dropoffpostcode")), ( "DropoffDateTime", post.db_datetime("dropoffdate", "dropofftime")), ( "Status", post.db_integer("status")), ( "Miles", post.db_integer("miles")), ( "Cost", post.db_integer("cost")), ( "CostPaidDate", post.db_date("costpaid")), ( "Comments", post.db_string("comments")) )) db.execute(dbo, sql) audit.create(dbo, username, "animaltransport", transportid, audit.dump_row(dbo, "animaltransport", transportid)) return transportid
def reschedule_vaccination(dbo, username, vaccinationid, newdays): """ Marks a vaccination completed today (if it's not already completed) and reschedules it for given + newdays onwards. """ av = db.query( dbo, "SELECT * FROM animalvaccination WHERE ID = %d" % int(vaccinationid))[0] given = av["DATEOFVACCINATION"] if given is None: given = now(dbo.timezone) db.execute( dbo, "UPDATE animalvaccination SET DateOfVaccination = %s WHERE ID = %d" % (db.dd(now(dbo.timezone)), int(vaccinationid))) audit.edit(dbo, username, "animalvaccination", str(vaccinationid) + " => given") nvaccid = db.get_id(dbo, "animalvaccination") db.execute( dbo, db.make_insert_user_sql( dbo, "animalvaccination", username, (("ID", db.di(nvaccid)), ("AnimalID", db.di(av["ANIMALID"])), ("VaccinationID", db.di(av["VACCINATIONID"])), ("DateOfVaccination", db.dd(None)), ("DateRequired", db.dd(add_days(given, int(newdays)))), ("Cost", db.di(av["COST"])), ("Comments", db.ds(av["COMMENTS"]))))) audit.create(dbo, username, "animalvaccination", str(nvaccid))
def insert_user_from_form(dbo, username, post): """ Creates a user record from posted form data. Uses the roles key (which should be a comma separated list of role ids) to create userrole records. """ # Verify the username is unique l = dbo.locale if 0 != db.query_int(dbo, "SELECT COUNT(*) FROM users WHERE LOWER(UserName) LIKE LOWER(%s)" % post.db_string("username")): raise utils.ASMValidationError(i18n._("Username '{0}' already exists", l).format(post["username"])) nuserid = db.get_id(dbo, "users") sql = db.make_insert_sql("users", ( ( "ID", db.di(nuserid)), ( "UserName", post.db_string("username")), ( "RealName", post.db_string("realname")), ( "EmailAddress", post.db_string("email")), ( "Password", db.ds(hash_password(post["password"]))), ( "SuperUser", post.db_integer("superuser")), ( "RecordVersion", db.di(0)), ( "SecurityMap", db.ds("dummy")), ( "OwnerID", post.db_integer("person")), ( "SiteID", post.db_integer("site")), ( "LocationFilter", post.db_string("locationfilter")), ( "IPRestriction", post.db_string("iprestriction")) )) db.execute(dbo, sql) audit.create(dbo, username, "users", nuserid, audit.dump_row(dbo, "users", nuserid)) roles = post["roles"].strip() if roles != "": for rid in roles.split(","): if rid.strip() != "": db.execute(dbo, "INSERT INTO userrole VALUES (%d, %d)" % (nuserid, int(rid))) return nuserid
def insert_donation_from_form(dbo, username, data): """ Creates a donation record from posted form data """ l = dbo.locale donationid = db.get_id(dbo, "ownerdonation") sql = db.make_insert_user_sql( dbo, "ownerdonation", username, (("ID", db.di(donationid)), ("OwnerID", db.di(utils.df_ki(data, "person"))), ("AnimalID", db.di(utils.df_ki(data, "animal"))), ("MovementID", db.di(utils.df_ki(data, "movement"))), ("DonationTypeID", utils.df_s(data, "type")), ("DonationPaymentID", utils.df_s(data, "payment")), ("Frequency", utils.df_s(data, "frequency")), ("Donation", utils.df_m(data, "amount", l)), ("DateDue", utils.df_d(data, "due", l)), ("Date", utils.df_d(data, "received", l)), ("NextCreated", db.di(0)), ("IsGiftAid", utils.df_s(data, "giftaid")), ("Comments", utils.df_t(data, "comments")))) db.execute(dbo, sql) audit.create(dbo, username, "ownerdonation", str(donationid)) update_matching_transaction(dbo, username, donationid) check_create_next_donation(dbo, username, donationid) movement.update_movement_donation(dbo, utils.df_ki(data, "movement")) return donationid
def attach_link_from_form(dbo, username, linktype, linkid, data): """ Attaches a link to a web resource from a form """ existingvid = db.query_int(dbo, "SELECT COUNT(*) FROM media WHERE WebsiteVideo = 1 " \ "AND LinkID = %d AND LinkTypeID = %d" % ( int(linkid), int(linktype) )) defvid = 0 if existingvid == 0 and utils.df_ki(data, "linktype") == MEDIATYPE_VIDEO_LINK: defvid = 1 mediaid = db.get_id(dbo, "media") url = utils.df_ks(data, "linktarget") if url.find("://") == -1: url = "http://" + url sql = db.make_insert_sql( "media", (("ID", db.di(mediaid)), ("MediaName", db.ds(url)), ("MediaType", utils.df_s(data, "linktype")), ("MediaNotes", utils.df_t(data, "comments")), ("WebsitePhoto", db.di(0)), ("WebsiteVideo", db.di(defvid)), ("DocPhoto", db.di(0)), ("ExcludeFromPublish", db.di(0)), ("NewSinceLastPublish", db.di(1)), ("UpdatedSinceLastPublish", db.di(0)), ("LinkID", db.di(linkid)), ("LinkTypeID", db.di(linktype)), ("Date", db.nowsql()))) db.execute(dbo, sql) audit.create( dbo, username, "media", str(mediaid) + ": for " + str(linkid) + "/" + str(linktype) + ": link to " + utils.df_ks(data, "linktarget"))
def insert_stocklevel_from_form(dbo, post, username): """ Inserts a stocklevel item from a dialog. The post should include the ID of the stocklevel to adjust and a usage record will be written so usage data should be sent too. """ l = dbo.locale slid = post.integer("id") if post["name"] == "": raise utils.ASMValidationError(_("Stock level must have a name", l)) if post["unitname"] == "": raise utils.ASMValidationError(_("Stock level must have a unit", l)) nid = db.get_id(dbo, "stocklevel") db.execute(dbo, db.make_insert_sql("stocklevel", ( ( "ID", db.di(nid) ), ( "Name", post.db_string("name") ), ( "Description", post.db_string("description") ), ( "StockLocationID", post.db_integer("location") ), ( "UnitName", post.db_string("unitname") ), ( "Total", post.db_floating("total") ), ( "Balance", post.db_floating("balance") ), ( "Expiry", post.db_date("expiry") ), ( "BatchNumber", post.db_string("batchnumber") ), ( "Cost", post.db_integer("cost") ), ( "UnitPrice", post.db_integer("unitprice") ), ( "CreatedDate", db.todaysql() ) ))) insert_stockusage(dbo, username, slid, post.floating("balance"), post.date("usagedate"), post.integer("usagetype"), post["comments"]) audit.create(dbo, username, "stocklevel", nid, audit.dump_row(dbo, "stocklevel", nid)) return nid
def insert_diary(dbo, username, linktypeid, linkid, diarydate, diaryfor, subject, note): """ Creates a diary note from the form data username: User creating the diary linktypeid, linkid: The link diarydate: The date to stamp on the note (python format) diaryfor: Who the diary note is for subject, note """ linkinfo = "" if linkid != 0: linkinfo = get_link_info(dbo, linktypeid, linkid) diaryid = db.get_id(dbo, "diary") sql = db.make_insert_user_sql(dbo, "diary", username, ( ( "ID", db.di(diaryid)), ( "LinkID", db.di(linkid) ), ( "LinkType", db.di(linktypeid) ), ( "LinkInfo", db.ds(linkinfo) ), ( "DiaryDateTime", db.dd(diarydate) ), ( "DiaryForName", db.ds(diaryfor) ), ( "Subject", db.ds(subject) ), ( "Note", db.ds(note) ), ( "DateCompleted", db.dd(None) ) )) db.execute(dbo, sql) audit.create(dbo, username, "diary", str(diaryid)) return diaryid
def insert_donation_from_form(dbo, username, data): """ Creates a donation record from posted form data """ l = dbo.locale donationid = db.get_id(dbo, "ownerdonation") sql = db.make_insert_user_sql(dbo, "ownerdonation", username, ( ( "ID", db.di(donationid)), ( "OwnerID", db.di(utils.df_ki(data, "person"))), ( "AnimalID", db.di(utils.df_ki(data, "animal"))), ( "MovementID", db.di(utils.df_ki(data, "movement"))), ( "DonationTypeID", utils.df_s(data, "type")), ( "DonationPaymentID", utils.df_s(data, "payment")), ( "Frequency", utils.df_s(data, "frequency")), ( "Donation", utils.df_m(data, "amount", l)), ( "DateDue", utils.df_d(data, "due", l)), ( "Date", utils.df_d(data, "received", l)), ( "NextCreated", db.di(0)), ( "IsGiftAid", utils.df_s(data, "giftaid")), ( "Comments", utils.df_t(data, "comments")) )) db.execute(dbo, sql) audit.create(dbo, username, "ownerdonation", str(donationid)) update_matching_transaction(dbo, username, donationid) check_create_next_donation(dbo, username, donationid) movement.update_movement_donation(dbo, utils.df_ki(data, "movement")) return donationid
def attach_link_from_form(dbo, username, linktype, linkid, data): """ Attaches a link to a web resource from a form """ existingvid = db.query_int(dbo, "SELECT COUNT(*) FROM media WHERE WebsiteVideo = 1 " \ "AND LinkID = %d AND LinkTypeID = %d" % ( int(linkid), int(linktype) )) defvid = 0 if existingvid == 0 and utils.df_ki(data, "linktype") == MEDIATYPE_VIDEO_LINK: defvid = 1 mediaid = db.get_id(dbo, "media") url = utils.df_ks(data, "linktarget") if url.find("://") == -1: url = "http://" + url sql = db.make_insert_sql("media", ( ( "ID", db.di(mediaid) ), ( "MediaName", db.ds(url) ), ( "MediaType", utils.df_s(data, "linktype") ), ( "MediaNotes", utils.df_t(data, "comments") ), ( "WebsitePhoto", db.di(0) ), ( "WebsiteVideo", db.di(defvid) ), ( "DocPhoto", db.di(0) ), ( "ExcludeFromPublish", db.di(0) ), ( "NewSinceLastPublish", db.di(1) ), ( "UpdatedSinceLastPublish", db.di(0) ), ( "LinkID", db.di(linkid) ), ( "LinkTypeID", db.di(linktype) ), ( "Date", db.nowsql() ) )) db.execute(dbo, sql) audit.create(dbo, username, "media", str(mediaid) + ": for " + str(linkid) + "/" + str(linktype) + ": link to " + utils.df_ks(data, "linktarget"))
def insert_user_from_form(dbo, username, data): """ Creates a user record from posted form data. Uses the roles key (which should be a comma separated list of role ids) to create userrole records. """ nuserid = db.get_id(dbo, "users") sql = db.make_insert_sql("users", ( ( "ID", db.di(nuserid)), ( "UserName", utils.df_t(data, "username")), ( "RealName", utils.df_t(data, "realname")), ( "EmailAddress", utils.df_t(data, "email")), ( "Password", db.ds(hash_password(utils.df_ks(data, "password"), True))), ( "SuperUser", utils.df_s(data, "superuser")), ( "RecordVersion", db.di(0)), ( "SecurityMap", db.ds("dummy")), ( "OwnerID", utils.df_s(data, "person")), ( "LocationFilter", utils.df_t(data, "locationfilter")), ( "IPRestriction", utils.df_t(data, "iprestriction")) )) db.execute(dbo, sql) audit.create(dbo, username, "users", str(nuserid)) roles = utils.df_ks(data, "roles").strip() if roles != "": for rid in roles.split(","): if rid.strip() != "": db.execute(dbo, "INSERT INTO userrole VALUES (%d, %d)" % (nuserid, int(rid))) return nuserid
def create_document_template(dbo, username, name, ext=".html", content="<p></p>"): """ Creates a document template from the name given. If there's no extension, adds it If it's a relative path (doesn't start with /) adds /templates/ to the front If it's an absolute path that doesn't start with /templates/, add /templates Changes spaces and unwanted punctuation to underscores """ filepath = name if not filepath.endswith(ext): filepath += ext if not filepath.startswith("/"): filepath = "/templates/" + filepath if not filepath.startswith("/templates"): filepath = "/templates" + filepath filepath = sanitise_path(filepath) name = filepath[filepath.rfind("/") + 1:] path = filepath[:filepath.rfind("/")] if 0 != dbo.query_int( "SELECT COUNT(*) FROM templatedocument WHERE Name = ? AND Path = ?", (name, path)): raise utils.ASMValidationError("%s already exists" % filepath) dtid = dbo.insert("templatedocument", { "Name": name, "Path": path, "Content": base64.b64encode(content) }) audit.create(dbo, username, "templatedocument", dtid, "id: %d, name: %s" % (dtid, name)) return dtid
def insert_user_from_form(dbo, username, data): """ Creates a user record from posted form data. Uses the roles key (which should be a comma separated list of role ids) to create userrole records. """ nuserid = db.get_id(dbo, "users") sql = db.make_insert_sql( "users", (("ID", db.di(nuserid)), ("UserName", utils.df_t(data, "username")), ("RealName", utils.df_t(data, "realname")), ("EmailAddress", utils.df_t(data, "email")), ("Password", db.ds(hash_password(utils.df_ks(data, "password"), True))), ("SuperUser", utils.df_s(data, "superuser")), ("RecordVersion", db.di(0)), ("SecurityMap", db.ds("dummy")), ("OwnerID", utils.df_s(data, "person")), ("LocationFilter", utils.df_t(data, "locationfilter")), ("IPRestriction", utils.df_t(data, "iprestriction")))) db.execute(dbo, sql) audit.create(dbo, username, "users", str(nuserid)) roles = utils.df_ks(data, "roles").strip() if roles != "": for rid in roles.split(","): if rid.strip() != "": db.execute( dbo, "INSERT INTO userrole VALUES (%d, %d)" % (nuserid, int(rid))) return nuserid
def insert_account_from_form(dbo, username, post): """ Creates an account from posted form data """ l = dbo.locale if post["code"] == "": raise utils.ASMValidationError(i18n._("Account code cannot be blank.", l)) if 0 != db.query_int(dbo, "SELECT COUNT(*) FROM accounts WHERE Code Like '%s'" % post["code"]): raise utils.ASMValidationError(i18n._("Account code '{0}' has already been used.", l).format(post["code"])) aid = db.get_id(dbo, "accounts") sql = db.make_insert_user_sql(dbo, "accounts", username, ( ( "ID", db.di(aid)), ( "Code", post.db_string("code")), ( "AccountType", post.db_integer("type")), ( "DonationTypeID", post.db_integer("donationtype")), ( "Description", post.db_string("description")) )) db.execute(dbo, sql) audit.create(dbo, username, "accounts", str(aid)) accountid = post.integer("accountid") for rid in post.integer_list("viewroles"): db.execute(dbo, "INSERT INTO accountsrole (AccountID, RoleID, CanView, CanEdit) VALUES (%d, %d, 1, 0)" % (accountid, rid)) for rid in post.integer_list("editroles"): if rid in post.integer_list("viewroles"): db.execute(dbo, "UPDATE accountsrole SET CanEdit = 1 WHERE AccountID = %d AND RoleID = %d" % (accountid, rid)) else: db.execute(dbo, "INSERT INTO accountsrole (AccountID, RoleID, CanView, CanEdit) VALUES (%d, %d, 0, 1)" % (accountid, rid)) return aid
def insert_trx_from_form(dbo, username, post): """ Creates a transaction from posted form data """ l = dbo.locale amount = 0 source = 0 target = 0 deposit = post.money("deposit") withdrawal = post.money("withdrawal") account = post.integer("accountid") other = get_account_id(dbo, post["otheraccount"]) if other == 0: raise utils.ASMValidationError(i18n._("Account code '{0}' is not valid.", l).format(post["otheraccount"])) if deposit > 0: amount = deposit source = other target = account else: amount = withdrawal source = account target = other tid = db.get_id(dbo, "accountstrx") sql = db.make_insert_user_sql(dbo, "accountstrx", username, ( ( "ID", db.di(tid) ), ( "TrxDate", post.db_date("trxdate")), ( "Description", post.db_string("description")), ( "Reconciled", post.db_boolean("reconciled")), ( "Amount", db.di(amount)), ( "SourceAccountID", db.di(source)), ( "DestinationAccountID", db.di(target)), ( "OwnerDonationID", db.di(0)) )) db.execute(dbo, sql) audit.create(dbo, username, "accountstrx", str(tid) + ": " + post["description"])
def insert_waitinglist_from_form(dbo, data, username): """ Creates a waiting list record from the screen data: The webpy data object containing form parameters """ l = dbo.locale if utils.df_ks(data, "description") == "": raise utils.ASMValidationError(_("Description cannot be blank", l)) if utils.df_ki(data, "owner") == "0": raise utils.ASMValidationError(_("Waiting list entries must have a contact", l)) if utils.df_ks(data, "dateputon") == "": raise utils.ASMValidationError(_("Date put on cannot be blank", l)) nwlid = db.get_id(dbo, "animalwaitinglist") db.execute(dbo, db.make_insert_user_sql(dbo, "animalwaitinglist", username, ( ( "ID", db.di(nwlid)), ( "SpeciesID", utils.df_s(data, "species")), ( "DatePutOnList", utils.df_d(data, "dateputon", l)), ( "OwnerID", utils.df_s(data, "owner")), ( "AnimalDescription", utils.df_t(data, "description")), ( "ReasonForWantingToPart", utils.df_t(data, "reasonforwantingtopart")), ( "CanAffordDonation", utils.df_c(data, "canafforddonation")), ( "Urgency", utils.df_s(data, "urgency")), ( "DateRemovedFromList", utils.df_d(data, "dateremoved", l)), ( "AutoRemovePolicy", utils.df_s(data, "autoremovepolicy")), ( "DateOfLastOwnerContact", db.dd(now(dbo.timezone))), ( "ReasonForRemoval", utils.df_t(data, "reasonforremoval")), ( "Comments", utils.df_t(data, "comments")), ( "UrgencyLastUpdatedDate", db.dd(now(dbo.timezone))), ( "UrgencyUpdateDate", db.dd(add_days(now(dbo.timezone), configuration.waiting_list_urgency_update_period(dbo)))) ))) audit.create(dbo, username, "animalwaitinglist", str(nwlid)) return nwlid
def insert(self, table, values, user="", generateID=True, setOverrideDBLock=False, setRecordVersion=True, setCreated=True, writeAudit=True): """ Inserts a row into a table. table: The table to insert into values: A dict of column names with values user: The user account performing the insert. If set, adds CreatedBy/Date/LastChangedBy/Date fields generateID: If True, sets a value for the ID column setRecordVersion: If user is non-blank and this is True, sets RecordVersion writeAudit: If True, writes an audit record for the insert Returns the ID of the inserted record """ if user != "" and setCreated: values["CreatedBy"] = user values["LastChangedBy"] = user values["CreatedDate"] = self.now() values["LastChangedDate"] = self.now() if setRecordVersion: values["RecordVersion"] = self.get_recordversion() iid = 0 if generateID: iid = self.get_id(table) values["ID"] = iid elif "ID" in values: iid = values["ID"] values = self.encode_str_before_write(values) sql = "INSERT INTO %s (%s) VALUES (%s)" % ( table, ",".join(values.iterkeys()), self.sql_placeholders(values) ) self.execute(sql, values.values(), override_lock=setOverrideDBLock) if writeAudit and iid != 0 and user != "": audit.create(self, user, table, iid, audit.dump_row(self, table, iid)) return iid
def insert_foundanimal_from_form(dbo, post, username): """ Inserts a new found animal record from the screen data: The webpy data object containing form parameters """ l = dbo.locale if post.date("datefound") is None: raise utils.ASMValidationError(_("Date found cannot be blank", l)) if post.date("datereported") is None: raise utils.ASMValidationError(_("Date reported cannot be blank", l)) if post.integer("owner") == 0: raise utils.ASMValidationError( _("Found animals must have a contact", l)) nid = db.get_id(dbo, "animalfound") db.execute( dbo, db.make_insert_user_sql( dbo, "animalfound", username, (("ID", db.di(nid)), ("AnimalTypeID", post.db_integer("species")), ("DateReported", post.db_date("datereported")), ("ReturnToOwnerDate", post.db_date("returntoownerdate")), ("DateFound", post.db_date("datefound")), ("Sex", post.db_integer("sex")), ("BreedID", post.db_integer("breed")), ("AgeGroup", post.db_string("agegroup")), ("BaseColourID", post.db_integer("colour")), ("DistFeat", post.db_string("markings")), ("AreaFound", post.db_string("areafound")), ("AreaPostcode", post.db_string("areapostcode")), ("OwnerID", post.db_integer("owner")), ("Comments", post.db_string("comments"))))) audit.create(dbo, username, "animalfound", str(nid)) return nid
def insert_foundanimal_from_form(dbo, data, username): """ Inserts a new found animal record from the screen data: The webpy data object containing form parameters """ l = dbo.locale if utils.df_kd(data, "datefound", l) is None: raise utils.ASMValidationError(_("Date found cannot be blank", l)) if utils.df_kd(data, "datereported", l) is None: raise utils.ASMValidationError(_("Date reported cannot be blank", l)) if utils.df_ki(data, "owner") == "0": raise utils.ASMValidationError(_("Found animals must have a contact", l)) nid = db.get_id(dbo, "animalfound") db.execute(dbo, db.make_insert_user_sql(dbo, "animalfound", username, ( ( "ID", db.di(nid)), ( "AnimalTypeID", utils.df_s(data, "species")), ( "DateReported", utils.df_d(data, "datereported", l)), ( "ReturnToOwnerDate", utils.df_d(data, "returntoownerdate", l)), ( "DateFound", utils.df_d(data, "datefound", l)), ( "Sex", utils.df_s(data, "sex")), ( "BreedID", utils.df_s(data, "breed")), ( "AgeGroup", utils.df_t(data, "agegroup")), ( "BaseColourID", utils.df_s(data, "colour")), ( "DistFeat", utils.df_t(data, "markings")), ( "AreaFound", utils.df_t(data, "areafound")), ( "AreaPostcode", utils.df_t(data, "areapostcode")), ( "OwnerID", utils.df_s(data, "owner")), ( "Comments", utils.df_t(data, "comments")) ))) audit.create(dbo, username, "animalfound", str(nid)) return nid
def update_animalcontrol_addlink(dbo, username, acid, animalid): """ Adds a link between an animal and an incident. """ l = dbo.locale if 0 != db.query_int(dbo, "SELECT COUNT(*) FROM animalcontrolanimal WHERE AnimalControlID = %d AND AnimalID = %d" % (acid, animalid)): raise utils.ASMValidationError(_("That animal is already linked to the incident", l)) db.execute(dbo, "INSERT INTO animalcontrolanimal (AnimalControlID, AnimalID) VALUES (%d, %d)" % (acid, animalid)) audit.create(dbo, username, "animalcontrolanimal", acid, "incident %d linked to animal %d" % (acid, animalid))
def insert_role_from_form(dbo, username, data): """ Creates a role record from posted form data. """ nroleid = db.get_id(dbo, "role") sql = db.make_insert_sql( "role", (("ID", db.di(nroleid)), ("Rolename", utils.df_t(data, "rolename")), ("SecurityMap", utils.df_t(data, "securitymap")))) db.execute(dbo, sql) audit.create(dbo, username, "role", str(nroleid))
def update_html_template(dbo, username, name, head, body, foot, builtin = False): """ Creates/updates an HTML publishing template """ dbo.execute("DELETE FROM templatehtml WHERE Name = ?", [name]) htid = dbo.insert("templatehtml", { "Name": name, "*Header": head, "*Body": body, "*Footer": foot, "IsBuiltIn": builtin and 1 or 0 }) audit.create(dbo, username, "templatehtml", htid, "", "id: %d, name: %s" % (htid, name))
def add_log(dbo, username, linktype, linkid, logtypeid, logtext): logid = db.get_id(dbo, "log") sql = db.make_insert_user_sql( dbo, "log", username, (("ID", db.di(logid)), ("LogTypeID", db.di(logtypeid)), ("LinkID", db.di(linkid)), ("LinkType", db.di(linktype)), ("Date", db.dd(i18n.now(dbo.timezone))), ("Comments", db.ds(logtext)))) db.execute(dbo, sql) audit.create(dbo, username, "log", str(logid)) return logid
def add_log(dbo, username, linktype, linkid, logtypeid, logtext): logid = db.get_id(dbo, "log") sql = db.make_insert_user_sql(dbo, "log", username, ( ( "ID", db.di(logid) ), ( "LogTypeID", db.di(logtypeid) ), ( "LinkID", db.di(linkid) ), ( "LinkType", db.di(linktype) ), ( "Date", db.dd(i18n.now(dbo.timezone)) ), ( "Comments", db.ds(logtext) ) )) db.execute(dbo, sql) audit.create(dbo, username, "log", str(logid))
def clone_document_template(dbo, username, dbfsid, newname): """ Creates a new document template with the content from the dbfsid given. """ # Get the extension/type from newname, defaulting to html ext = ".html" if newname.rfind(".") != -1: ext = newname[newname.rfind("."):] content = get_string_id(dbo, dbfsid) ndbfsid = create_document_template(dbo, username, newname, ext, content) audit.create(dbo, username, "documenttemplate", ndbfsid, "clone %d to %s (new id: %d)" % (dbfsid, newname, ndbfsid)) return ndbfsid
def insert_role_from_form(dbo, username, data): """ Creates a role record from posted form data. """ nroleid = db.get_id(dbo, "role") sql = db.make_insert_sql("role", ( ( "ID", db.di(nroleid)), ( "Rolename", utils.df_t(data, "rolename")), ( "SecurityMap", utils.df_t(data, "securitymap")) )) db.execute(dbo, sql) audit.create(dbo, username, "role", str(nroleid))
def insert_role_from_form(dbo, username, post): """ Creates a role record from posted form data. """ nroleid = db.get_id(dbo, "role") sql = db.make_insert_sql("role", ( ( "ID", db.di(nroleid)), ( "Rolename", post.db_string("rolename")), ( "SecurityMap", post.db_string("securitymap")) )) db.execute(dbo, sql) audit.create(dbo, username, "role", nroleid, audit.dump_row(dbo, "role", nroleid))
def insert_movement_from_form(dbo, username, data): """ Creates a movement record from posted form data """ movementid = db.get_id(dbo, "adoption") adoptionno = utils.df_ks(data, "adoptionno") animalid = utils.df_ki(data, "animal") if adoptionno == "": # No adoption number was supplied, generate a # unique number from the movementid idx = movementid while True: adoptionno = utils.padleft(idx, 6) data["adoptionno"] = adoptionno if 0 == db.query_int( dbo, "SELECT COUNT(*) FROM adoption WHERE AdoptionNumber LIKE '%s'" % adoptionno): break else: idx += 1 validate_movement_form_data(dbo, data) l = dbo.locale sql = db.make_insert_user_sql( dbo, "adoption", username, (("ID", db.di(movementid)), ("AdoptionNumber", db.ds(adoptionno)), ("OwnerID", db.di(utils.df_ki(data, "person"))), ("RetailerID", db.di(utils.df_ki(data, "retailer"))), ("AnimalID", db.di(utils.df_ki(data, "animal"))), ("OriginalRetailerMovementID", db.di(utils.df_ki(data, "originalretailermovement"))), ("MovementDate", utils.df_d(data, "movementdate", l)), ("MovementType", utils.df_s(data, "type")), ("ReturnDate", utils.df_d(data, "returndate", l)), ("ReturnedReasonID", utils.df_s(data, "returncategory")), ("Donation", utils.df_m(data, "donation", l)), ("InsuranceNumber", utils.df_t(data, "insurance")), ("ReasonForReturn", utils.df_t(data, "reason")), ("ReservationDate", utils.df_d(data, "reservationdate", l)), ("ReservationCancelledDate", utils.df_d(data, "reservationcancelled", l)), ("IsTrial", utils.df_c(data, "trial")), ("IsPermanentFoster", utils.df_c(data, "permanentfoster")), ("TrialEndDate", utils.df_d(data, "trialenddate", l)), ("Comments", utils.df_t(data, "comments")))) db.execute(dbo, sql) audit.create(dbo, username, "adoption", str(movementid)) animal.update_animal_status(dbo, animalid) animal.update_variable_animal_data(dbo, animalid) update_movement_donation(dbo, movementid) return movementid
def insert_diarytaskhead_from_form(dbo, username, post): """ Creates a diary task header from form data """ nid = db.get_id(dbo, "diarytaskhead") sql = db.make_insert_sql("diarytaskhead", (("ID", db.di(nid)), ("Name", post.db_string("name")), ("RecordType", post.db_integer("type")), ("RecordVersion", db.di(0)))) db.execute(dbo, sql) audit.create(dbo, username, "diarytaskhead", str(nid)) return nid
def insert_diarytaskhead_from_form(dbo, username, data): """ Creates a diary task header from form data """ nid = db.get_id(dbo, "diarytaskhead") sql = db.make_insert_sql("diarytaskhead", (("ID", db.di(nid)), ("Name", utils.df_t(data, "name")), ("RecordType", utils.df_s(data, "type")), ("RecordVersion", db.di(0)))) db.execute(dbo, sql) audit.create(dbo, username, "diarytaskhead", str(nid)) return nid
def insert_animalcontrol_from_form(dbo, post, username): """ Inserts a new animal control incident record from the screen data: The webpy data object containing form parameters """ l = dbo.locale if post.date("incidentdate") is None: raise utils.ASMValidationError(_("Incident date cannot be blank", l)) nid = db.get_id(dbo, "animalcontrol") db.execute( dbo, db.make_insert_user_sql( dbo, "animalcontrol", username, (("ID", db.di(nid)), ("IncidentDateTime", post.db_datetime("incidentdate", "incidenttime")), ("IncidentTypeID", post.db_integer("incidenttype")), ("CallDateTime", post.db_datetime("calldate", "calltime")), ("CallNotes", post.db_string("callnotes")), ("CallTaker", post.db_string("calltaker")), ("CallerID", post.db_integer("caller")), ("VictimID", post.db_integer("victim")), ("DispatchAddress", post.db_string("dispatchaddress")), ("DispatchTown", post.db_string("dispatchtown")), ("DispatchCounty", post.db_string("dispatchcounty")), ("DispatchPostcode", post.db_string("dispatchpostcode")), ("DispatchLatLong", post.db_string("dispatchlatlong")), ("DispatchedACO", post.db_string("dispatchedaco")), ("DispatchDateTime", post.db_datetime("dispatchdate", "dispatchtime")), ("RespondedDateTime", post.db_datetime("respondeddate", "respondedtime")), ("FollowupDateTime", post.db_datetime("followupdate", "followuptime")), ("FollowupDateTime2", post.db_datetime("followupdate2", "followuptime2")), ("FollowupDateTime3", post.db_datetime("followupdate3", "followuptime3")), ("CompletedDate", post.db_date("completeddate")), ("IncidentCompletedID", post.db_integer("completedtype")), ("OwnerID", post.db_integer("owner")), ("Owner2ID", post.db_integer("owner2")), ("Owner3ID", post.db_integer("owner3")), ("AnimalID", post.db_integer("animal")), ("AnimalDescription", post.db_string("animaldescription")), ("SpeciesID", post.db_integer("species")), ("Sex", post.db_integer("sex")), ("AgeGroup", post.db_string("agegroup"))))) audit.create(dbo, username, "animalcontrol", str(nid)) return nid
def insert_regimen_from_form(dbo, username, data): """ Creates a regimen record from posted form data """ l = dbo.locale if utils.df_kd(data, "startdate", l) is None: raise utils.ASMValidationError(_("Start date must be a valid date", l)) if utils.df_ks(data, "treatmentname") == "": raise utils.ASMValidationError(_("Treatment name cannot be blank", l)) l = dbo.locale nregid = db.get_id(dbo, "animalmedical") timingrule = utils.df_ki(data, "timingrule") timingrulenofrequencies = utils.df_ki(data, "timingrulenofrequencies") timingrulefrequency = utils.df_ki(data, "timingrulefrequency") totalnumberoftreatments = utils.df_ki(data, "totalnumberoftreatments") treatmentsremaining = int(totalnumberoftreatments) * int(timingrule) treatmentrule = utils.df_ki(data, "treatmentrule") singlemulti = utils.df_ki(data, "singlemulti") if singlemulti == 0: timingrule = 0 timingrulenofrequencies = 0 timingrulefrequency = 0 treatmentsremaining = 1 if treatmentrule != 0: totalnumberoftreatments = 0 treatmentsremaining = 0 sql = db.make_insert_user_sql( dbo, "animalmedical", username, (("ID", db.di(nregid)), ("AnimalID", db.di(utils.df_ki(data, "animal"))), ("MedicalProfileID", utils.df_s(data, "profileid")), ("TreatmentName", utils.df_t(data, "treatmentname")), ("Dosage", utils.df_t(data, "dosage")), ("StartDate", utils.df_d(data, "startdate", l)), ("Status", db.di(0)), ("Cost", utils.df_m(data, "cost", l)), ("TimingRule", db.di(timingrule)), ("TimingRuleFrequency", db.di(timingrulefrequency)), ("TimingRuleNoFrequencies", db.di(timingrulenofrequencies)), ("TreatmentRule", utils.df_s(data, "treatmentrule")), ("TotalNumberOfTreatments", db.di(totalnumberoftreatments)), ("TreatmentsGiven", db.di(0)), ("TreatmentsRemaining", db.di(treatmentsremaining)), ("Comments", utils.df_t(data, "comments")))) db.execute(dbo, sql) audit.create( dbo, username, "animalmedical", str(nregid) + ": " + utils.df_ks(data, "treatmentname") + " " + utils.df_ks(data, "dosage")) update_medical_treatments(dbo, username, nregid)
def insert_stockusage(dbo, username, slid, diff, usagedate, usagetype, comments): """ Inserts a new stock usage record """ nid = db.get_id(dbo, "stockusage") db.execute(dbo, db.make_insert_user_sql(dbo, "stockusage", username, ( ( "ID", db.di(nid)), ( "StockUsageTypeID", db.di(usagetype) ), ( "StockLevelID", db.di(slid) ), ( "UsageDate", db.dd(usagedate) ), ( "Quantity", db.df(diff) ), ( "Comments", db.ds(comments) ) ))) audit.create(dbo, username, "stockusage", nid, audit.dump_row(dbo, "stockusage", nid))
def insert_diarytaskhead_from_form(dbo, username, data): """ Creates a diary task header from form data """ nid = db.get_id(dbo, "diarytaskhead") sql = db.make_insert_sql("diarytaskhead", ( ( "ID", db.di(nid)), ( "Name", utils.df_t(data, "name")), ( "RecordType", utils.df_s(data, "type")), ( "RecordVersion", db.di(0)) )) db.execute(dbo, sql) audit.create(dbo, username, "diarytaskhead", str(nid)) return nid
def insert_onlineform_from_form(dbo, username, data): """ Create an onlineform record from posted data """ formid = db.get_id(dbo, "onlineform") sql = db.make_insert_sql( "onlineform", (("ID", db.di(formid)), ("Name", db.ds(utils.df_ks(data, "name"))), ("RedirectUrlAfterPOST", db.ds(utils.df_ks(data, "redirect"))), ("SetOwnerFlags", db.ds(utils.df_ks(data, "flags"))), ("Description", db.ds(utils.df_ks(data, "description"))))) db.execute(dbo, sql) audit.create(dbo, username, "onlineform", str(formid)) return formid
def insert_animalcontrol_from_form(dbo, post, username): """ Inserts a new animal control incident record from the screen data: The webpy data object containing form parameters """ l = dbo.locale if post.date("incidentdate") is None: raise utils.ASMValidationError(_("Incident date cannot be blank", l)) nid = db.get_id(dbo, "animalcontrol") db.execute(dbo, db.make_insert_user_sql(dbo, "animalcontrol", username, ( ( "ID", db.di(nid)), ( "IncidentDateTime", post.db_datetime("incidentdate", "incidenttime")), ( "IncidentTypeID", post.db_integer("incidenttype")), ( "CallDateTime", post.db_datetime("calldate", "calltime")), ( "CallNotes", post.db_string("callnotes")), ( "CallTaker", post.db_string("calltaker")), ( "CallerID", post.db_integer("caller")), ( "VictimID", post.db_integer("victim")), ( "DispatchAddress", post.db_string("dispatchaddress")), ( "DispatchTown", post.db_string("dispatchtown")), ( "DispatchCounty", post.db_string("dispatchcounty")), ( "DispatchPostcode", post.db_string("dispatchpostcode")), ( "PickupLocationID", post.db_integer("pickuplocation")), ( "DispatchLatLong", post.db_string("dispatchlatlong")), ( "DispatchedACO", post.db_string("dispatchedaco")), ( "DispatchDateTime", post.db_datetime("dispatchdate", "dispatchtime")), ( "RespondedDateTime", post.db_datetime("respondeddate", "respondedtime")), ( "FollowupDateTime", post.db_datetime("followupdate", "followuptime")), ( "FollowupComplete", post.db_boolean("followupcomplete")), ( "FollowupDateTime2", post.db_datetime("followupdate2", "followuptime2")), ( "FollowupComplete2", post.db_boolean("followupcomplete2")), ( "FollowupDateTime3", post.db_datetime("followupdate3", "followuptime3")), ( "FollowupComplete3", post.db_boolean("followupcomplete3")), ( "CompletedDate", post.db_date("completeddate")), ( "IncidentCompletedID", post.db_integer("completedtype")), ( "OwnerID", post.db_integer("owner")), ( "Owner2ID", post.db_integer("owner2")), ( "Owner3ID", post.db_integer("owner3")), ( "AnimalDescription", post.db_string("animaldescription")), ( "SpeciesID", post.db_integer("species")), ( "Sex", post.db_integer("sex")), ( "AgeGroup", post.db_string("agegroup")) ))) audit.create(dbo, username, "animalcontrol", nid, audit.dump_row(dbo, "animalcontrol", nid)) # Save any additional field values given additional.save_values_for_link(dbo, post, nid, "incident") return nid
def insert_diarytaskhead_from_form(dbo, username, post): """ Creates a diary task header from form data """ nid = db.get_id(dbo, "diarytaskhead") sql = db.make_insert_sql("diarytaskhead", ( ( "ID", db.di(nid)), ( "Name", post.db_string("name")), ( "RecordType", post.db_integer("type")), ( "RecordVersion", db.di(0)) )) db.execute(dbo, sql) audit.create(dbo, username, "diarytaskhead", nid, audit.dump_row(dbo, "diarytaskhead", nid)) return nid
def insert_account_from_donationtype(dbo, dtid, name, desc): """ Creates an account from a donation type record """ l = dbo.locale aid = db.get_id(dbo, "accounts") acode = i18n._("Income::", l) + name.replace(" ", "") sql = db.make_insert_user_sql(dbo, "accounts", "system", (("ID", db.di(aid)), ("Code", db.ds(acode)), ("AccountType", db.di(INCOME)), ("DonationTypeID", db.di(dtid)), ("Description", db.ds(desc)))) db.execute(dbo, sql) audit.create(dbo, "system", "accounts", str(aid))
def insert_regimen_from_form(dbo, username, data): """ Creates a regimen record from posted form data """ l = dbo.locale if utils.df_kd(data, "startdate", l) is None: raise utils.ASMValidationError(_("Start date must be a valid date", l)) if utils.df_ks(data, "treatmentname") == "": raise utils.ASMValidationError(_("Treatment name cannot be blank", l)) l = dbo.locale nregid = db.get_id(dbo, "animalmedical") timingrule = utils.df_ki(data, "timingrule") timingrulenofrequencies = utils.df_ki(data, "timingrulenofrequencies") timingrulefrequency = utils.df_ki(data, "timingrulefrequency") totalnumberoftreatments = utils.df_ki(data, "totalnumberoftreatments") treatmentsremaining = int(totalnumberoftreatments) * int(timingrule) treatmentrule = utils.df_ki(data, "treatmentrule") singlemulti = utils.df_ki(data, "singlemulti") if singlemulti == 0: timingrule = 0 timingrulenofrequencies = 0 timingrulefrequency = 0 treatmentsremaining = 1 if treatmentrule != 0: totalnumberoftreatments = 0 treatmentsremaining = 0 sql = db.make_insert_user_sql(dbo, "animalmedical", username, ( ( "ID", db.di(nregid)), ( "AnimalID", db.di(utils.df_ki(data, "animal"))), ( "MedicalProfileID", utils.df_s(data, "profileid")), ( "TreatmentName", utils.df_t(data, "treatmentname")), ( "Dosage", utils.df_t(data, "dosage")), ( "StartDate", utils.df_d(data, "startdate", l)), ( "Status", db.di(0)), ( "Cost", utils.df_m(data, "cost", l)), ( "TimingRule", db.di(timingrule)), ( "TimingRuleFrequency", db.di(timingrulefrequency)), ( "TimingRuleNoFrequencies", db.di(timingrulenofrequencies)), ( "TreatmentRule", utils.df_s(data, "treatmentrule")), ( "TotalNumberOfTreatments", db.di(totalnumberoftreatments)), ( "TreatmentsGiven", db.di(0)), ( "TreatmentsRemaining", db.di(treatmentsremaining)), ( "Comments", utils.df_t(data, "comments")) )) db.execute(dbo, sql) audit.create(dbo, username, "animalmedical", str(nregid) + ": " + utils.df_ks(data, "treatmentname") + " " + utils.df_ks(data, "dosage")) update_medical_treatments(dbo, username, nregid)
def insert_investigation_from_form(dbo, username, data): """ Creates an investigation record from posted form data """ l = dbo.locale ninv = db.get_id(dbo, "ownerinvestigation") sql = db.make_insert_user_sql( dbo, "ownerinvestigation", username, (("ID", db.di(ninv)), ("OwnerID", db.di(utils.df_ki(data, "personid"))), ("Date", utils.df_d(data, "date", l)), ("Notes", utils.df_t(data, "notes")))) db.execute(dbo, sql) audit.create(dbo, username, "ownerinvestigation", str(ninv)) return ninv
def insert_onlineform_from_form(dbo, username, data): """ Create an onlineform record from posted data """ formid = db.get_id(dbo, "onlineform") sql = db.make_insert_sql("onlineform", ( ( "ID", db.di(formid)), ( "Name", db.ds(utils.df_ks(data, "name"))), ( "RedirectUrlAfterPOST", db.ds(utils.df_ks(data, "redirect"))), ( "SetOwnerFlags", db.ds(utils.df_ks(data, "flags"))), ( "Description", db.ds(utils.df_ks(data, "description"))) )) db.execute(dbo, sql) audit.create(dbo, username, "onlineform", str(formid)) return formid
def update_animalcontrol_addlink(dbo, username, acid, animalid): """ Adds a link between an animal and an incident. """ l = dbo.locale if 0 != dbo.query_int( "SELECT COUNT(*) FROM animalcontrolanimal WHERE AnimalControlID = ? AND AnimalID = ?", (acid, animalid)): raise utils.ASMValidationError( _("That animal is already linked to the incident", l)) dbo.execute( "INSERT INTO animalcontrolanimal (AnimalControlID, AnimalID) VALUES (?, ?)", (acid, animalid)) audit.create(dbo, username, "animalcontrolanimal", acid, "", "incident %d linked to animal %d" % (acid, animalid))
def insert_diarytaskdetail_from_form(dbo, username, post): """ Creates a diary task detail from form data """ nid = db.get_id(dbo, "diarytaskdetail") sql = db.make_insert_sql( "diarytaskdetail", (("ID", db.di(nid)), ("DiaryTaskHeadID", post.db_integer("taskid")), ("DayPivot", post.db_integer("pivot")), ("WhoFor", post.db_string("for")), ("Subject", post.db_string("subject")), ("Note", post.db_string("note")), ("RecordVersion", db.di(0)))) db.execute(dbo, sql) audit.create(dbo, username, "diarytaskdetail", str(nid)) return nid
def insert_investigation_from_form(dbo, username, data): """ Creates an investigation record from posted form data """ l = dbo.locale ninv = db.get_id(dbo, "ownerinvestigation") sql = db.make_insert_user_sql(dbo, "ownerinvestigation", username, ( ( "ID", db.di(ninv)), ( "OwnerID", db.di(utils.df_ki(data, "personid"))), ( "Date", utils.df_d(data, "date", l)), ( "Notes", utils.df_t(data, "notes")) )) db.execute(dbo, sql) audit.create(dbo, username, "ownerinvestigation", str(ninv)) return ninv
def insert_movement_from_form(dbo, username, data): """ Creates a movement record from posted form data """ movementid = db.get_id(dbo, "adoption") adoptionno = utils.df_ks(data, "adoptionno") animalid = utils.df_ki(data, "animal") if adoptionno == "": # No adoption number was supplied, generate a # unique number from the movementid idx = movementid while True: adoptionno = utils.padleft(idx, 6) data["adoptionno"] = adoptionno if 0 == db.query_int(dbo, "SELECT COUNT(*) FROM adoption WHERE AdoptionNumber LIKE '%s'" % adoptionno): break else: idx += 1 validate_movement_form_data(dbo, data) l = dbo.locale sql = db.make_insert_user_sql(dbo, "adoption", username, ( ( "ID", db.di(movementid)), ( "AdoptionNumber", db.ds(adoptionno)), ( "OwnerID", db.di(utils.df_ki(data, "person"))), ( "RetailerID", db.di(utils.df_ki(data, "retailer"))), ( "AnimalID", db.di(utils.df_ki(data, "animal"))), ( "OriginalRetailerMovementID", db.di(utils.df_ki(data, "originalretailermovement"))), ( "MovementDate", utils.df_d(data, "movementdate", l)), ( "MovementType", utils.df_s(data, "type")), ( "ReturnDate", utils.df_d(data, "returndate", l)), ( "ReturnedReasonID", utils.df_s(data, "returncategory")), ( "Donation", utils.df_m(data, "donation", l)), ( "InsuranceNumber", utils.df_t(data, "insurance")), ( "ReasonForReturn", utils.df_t(data, "reason")), ( "ReservationDate", utils.df_d(data, "reservationdate", l)), ( "ReservationCancelledDate", utils.df_d(data, "reservationcancelled", l)), ( "IsTrial", utils.df_c(data, "trial")), ( "IsPermanentFoster", utils.df_c(data, "permanentfoster")), ( "TrialEndDate", utils.df_d(data, "trialenddate", l)), ( "Comments", utils.df_t(data, "comments")) )) db.execute(dbo, sql) audit.create(dbo, username, "adoption", str(movementid)) animal.update_animal_status(dbo, animalid) animal.update_variable_animal_data(dbo, animalid) update_movement_donation(dbo, movementid) return movementid
def create_document_template(dbo, username, name, ext = ".html", content = "<p></p>"): """ Creates a document template from the name given. If there's no extension, adds it If it's a relative path (doesn't start with /) adds /templates/ to the front If it's an absolute path that doesn't start with /templates/, add /templates Changes spaces and unwanted punctuation to underscores """ filepath = name if not filepath.endswith(ext): filepath += ext if not filepath.startswith("/"): filepath = "/templates/" + filepath if not filepath.startswith("/templates"): filepath = "/templates" + filepath filepath = sanitise_path(filepath) dbfsid = put_string_filepath(dbo, filepath, content) audit.create(dbo, username, "documenttemplate", dbfsid, "id: %d, name: %s" % (dbfsid, name)) return dbfsid
def insert_account_from_donationtype(dbo, dtid, name, desc): """ Creates an account from a donation type record """ l = dbo.locale aid = db.get_id(dbo, "accounts") acode = i18n._("Income::", l) + name.replace(" ", "") sql = db.make_insert_user_sql(dbo, "accounts", "system", ( ( "ID", db.di(aid)), ( "Code", db.ds(acode)), ( "AccountType", db.di(INCOME)), ( "DonationTypeID", db.di(dtid)), ( "Description", db.ds(desc)) )) db.execute(dbo, sql) audit.create(dbo, "system", "accounts", str(aid))
def insert_field_from_form(dbo, username, post): """ Creates an additional field """ nid = db.get_id(dbo, "additionalfield") sql = db.make_insert_sql( "additionalfield", (("ID", db.di(nid)), ("FieldName", post.db_string("name")), ("FieldLabel", post.db_string("label")), ("ToolTip", post.db_string("tooltip")), ("LookupValues", post.db_string("lookupvalues")), ("Mandatory", post.db_boolean("mandatory")), ("FieldType", post.db_integer("type")), ("LinkType", post.db_integer("link")), ("DisplayIndex", post.db_integer("displayindex")))) db.execute(dbo, sql) audit.create(dbo, username, "additionalfield", post["name"])
def insert_diarytaskdetail_from_form(dbo, username, data): """ Creates a diary task detail from form data """ nid = db.get_id(dbo, "diarytaskdetail") sql = db.make_insert_sql("diarytaskdetail", ( ( "ID", db.di(nid)), ( "DiaryTaskHeadID", utils.df_s(data, "taskid")), ( "DayPivot", utils.df_s(data, "pivot")), ( "WhoFor", utils.df_t(data, "for")), ( "Subject", utils.df_t(data, "subject")), ( "Note", utils.df_t(data, "note")), ( "RecordVersion", db.di(0)) )) db.execute(dbo, sql) audit.create(dbo, username, "diarytaskdetail", str(nid)) return nid
def insert_diarytaskdetail_from_form(dbo, username, post): """ Creates a diary task detail from form data """ nid = db.get_id(dbo, "diarytaskdetail") sql = db.make_insert_sql("diarytaskdetail", ( ( "ID", db.di(nid)), ( "DiaryTaskHeadID", post.db_integer("taskid")), ( "DayPivot", post.db_integer("pivot")), ( "WhoFor", post.db_string("for")), ( "Subject", post.db_string("subject")), ( "Note", post.db_string("note")), ( "RecordVersion", db.di(0)) )) db.execute(dbo, sql) audit.create(dbo, username, "diarytaskdetail", nid, audit.dump_row(dbo, "diarytaskdetail", nid)) return nid
def insert_voucher_from_form(dbo, username, data): """ Creates a voucher record from posted form data """ l = dbo.locale voucherid = db.get_id(dbo, "ownervoucher") sql = db.make_insert_user_sql(dbo, "ownervoucher", username, ( ( "ID", db.di(voucherid)), ( "OwnerID", db.di(utils.df_ki(data, "personid"))), ( "VoucherID", utils.df_s(data, "type")), ( "DateIssued", utils.df_d(data, "issued", l)), ( "DateExpired", utils.df_d(data, "expires", l)), ( "Value", utils.df_m(data, "amount", l)), ( "Comments", utils.df_t(data, "comments")) )) db.execute(dbo, sql) audit.create(dbo, username, "ownervoucher", str(voucherid)) return voucherid
def insert_voucher_from_form(dbo, username, data): """ Creates a voucher record from posted form data """ l = dbo.locale voucherid = db.get_id(dbo, "ownervoucher") sql = db.make_insert_user_sql( dbo, "ownervoucher", username, (("ID", db.di(voucherid)), ("OwnerID", db.di(utils.df_ki(data, "personid"))), ("VoucherID", utils.df_s(data, "type")), ("DateIssued", utils.df_d(data, "issued", l)), ("DateExpired", utils.df_d(data, "expires", l)), ("Value", utils.df_m(data, "amount", l)), ("Comments", utils.df_t(data, "comments")))) db.execute(dbo, sql) audit.create(dbo, username, "ownervoucher", str(voucherid)) return voucherid
def insert_onlineform_from_form(dbo, username, post): """ Create an onlineform record from posted data """ formid = db.get_id(dbo, "onlineform") sql = db.make_insert_sql("onlineform", ( ( "ID", db.di(formid)), ( "Name", post.db_string("name")), ( "RedirectUrlAfterPOST", post.db_string("redirect")), ( "SetOwnerFlags", post.db_string("flags")), ( "EmailAddress", post.db_string("email")), ( "Header", post.db_string("header")), ( "Footer", post.db_string("footer")), ( "Description", post.db_string("description")) )) db.execute(dbo, sql) audit.create(dbo, username, "onlineform", str(formid)) return formid
def insert_onlineformfield_from_form(dbo, username, data): """ Create an onlineformfield record from posted data """ formfieldid = db.get_id(dbo, "onlineformfield") sql = db.make_insert_sql( "onlineformfield", (("ID", db.di(formfieldid)), ("OnlineFormID", db.di(utils.df_ki(data, "formid"))), ("FieldName", db.ds(utils.df_ks(data, "fieldname"))), ("FieldType", db.di(utils.df_ki(data, "fieldtype"))), ("Label", db.ds(utils.df_ks(data, "label"))), ("DisplayIndex", db.di(utils.df_ki(data, "displayindex"))), ("Lookups", db.ds(utils.df_ks(data, "lookups"))), ("Tooltip", db.ds(utils.df_ks(data, "tooltip"))))) db.execute(dbo, sql) audit.create(dbo, username, "onlineformfield", str(formfieldid)) return formfieldid
def insert_traploan_from_form(dbo, username, post): """ Creates a traploan record from posted form data """ traploanid = db.get_id(dbo, "ownertraploan") sql = db.make_insert_user_sql( dbo, "ownertraploan", username, (("ID", db.di(traploanid)), ("OwnerID", post.db_integer("person")), ("TrapTypeID", post.db_integer("type")), ("LoanDate", post.db_date("loandate")), ("DepositAmount", post.db_integer("depositamount")), ("DepositReturnDate", post.db_date("depositreturndate")), ("TrapNumber", post.db_string("trapnumber")), ("ReturnDueDate", post.db_date("returnduedate")), ("ReturnDate", post.db_date("returndate")), ("Comments", post.db_string("comments")))) db.execute(dbo, sql) audit.create(dbo, username, "ownertraploan", str(traploanid)) return traploanid
def insert_onlineformfield_from_form(dbo, username, post): """ Create an onlineformfield record from posted data """ formfieldid = db.get_id(dbo, "onlineformfield") sql = db.make_insert_sql("onlineformfield", ( ( "ID", db.di(formfieldid)), ( "OnlineFormID", post.db_integer("formid")), ( "FieldName", post.db_string("fieldname")), ( "FieldType", post.db_integer("fieldtype")), ( "Label", post.db_string("label")), ( "DisplayIndex", post.db_integer("displayindex")), ( "Mandatory", post.db_boolean("mandatory")), ( "Lookups", post.db_string("lookups")), ( "Tooltip", post.db_string("tooltip")) )) db.execute(dbo, sql) audit.create(dbo, username, "onlineformfield", str(formfieldid)) return formfieldid
def create_blank_document_media(dbo, username, linktype, linkid): """ Creates a new media record for a blank document for the link given. linktype: ANIMAL, PERSON, etc linkid: ID for the link returns the new media id """ mediaid = db.get_id(dbo, "media") sql = db.make_insert_sql( "media", ( ("ID", db.di(mediaid)), ("MediaName", db.ds("%d.html" % mediaid)), ("MediaType", db.di(0)), ("MediaNotes", db.ds("New document")), ("WebsitePhoto", db.di(0)), ("WebsiteVideo", db.di(0)), ("DocPhoto", db.di(0)), ("ExcludeFromPublish", db.di(0)), # ASM2_COMPATIBILITY ("NewSinceLastPublish", db.di(1)), ("UpdatedSinceLastPublish", db.di(0)), # ASM2_COMPATIBILITY ("LinkID", db.di(linkid)), ("LinkTypeID", db.di(linktype)), ("Date", db.nowsql()))) db.execute(dbo, sql) path = "" if linktype == ANIMAL: path = "/animal" elif linktype == PERSON: path = "/owner" elif linktype == LOSTANIMAL: path = "/lostanimal" elif linktype == FOUNDANIMAL: path = "/foundanimal" path += "/" + str(linkid) name = str(mediaid) + ".html" dbfs.put_string(dbo, name, path, "") audit.create(dbo, username, "media", str(mediaid) + ": for " + str(linkid) + "/" + str(linktype)) return mediaid
def insert_account_from_form(dbo, username, post): """ Creates an account from posted form data """ l = dbo.locale if post["code"] == "": raise utils.ASMValidationError( i18n._("Account code cannot be blank.", l)) if 0 != db.query_int( dbo, "SELECT COUNT(*) FROM accounts WHERE Code Like '%s'" % post["code"]): raise utils.ASMValidationError( i18n._("Account code '{0}' has already been used.", l).format(post["code"])) aid = db.get_id(dbo, "accounts") sql = db.make_insert_user_sql( dbo, "accounts", username, (("ID", db.di(aid)), ("Code", post.db_string("code")), ("AccountType", post.db_integer("type")), ("DonationTypeID", post.db_integer("donationtype")), ("Description", post.db_string("description")))) db.execute(dbo, sql) audit.create(dbo, username, "accounts", str(aid)) accountid = post.integer("accountid") for rid in post.integer_list("viewroles"): db.execute( dbo, "INSERT INTO accountsrole (AccountID, RoleID, CanView, CanEdit) VALUES (%d, %d, 1, 0)" % (accountid, rid)) for rid in post.integer_list("editroles"): if rid in post.integer_list("viewroles"): db.execute( dbo, "UPDATE accountsrole SET CanEdit = 1 WHERE AccountID = %d AND RoleID = %d" % (accountid, rid)) else: db.execute( dbo, "INSERT INTO accountsrole (AccountID, RoleID, CanView, CanEdit) VALUES (%d, %d, 0, 1)" % (accountid, rid)) return aid
def insert_profile_from_form(dbo, username, data): """ Creates a profile record from posted form data """ l = dbo.locale if utils.df_ks(data, "treatmentname") == "": raise utils.ASMValidationError(_("Treatment name cannot be blank", l)) if utils.df_ks(data, "profilename") == "": raise utils.ASMValidationError(_("Profile name cannot be blank", l)) nprofid = db.get_id(dbo, "medicalprofile") timingrule = utils.df_ki(data, "timingrule") timingrulenofrequencies = utils.df_ki(data, "timingrulenofrequencies") timingrulefrequency = utils.df_ki(data, "timingrulefrequency") totalnumberoftreatments = utils.df_ki(data, "totalnumberoftreatments") treatmentrule = utils.df_ki(data, "treatmentrule") singlemulti = utils.df_ki(data, "singlemulti") if singlemulti == 0: timingrule = 0 timingrulenofrequencies = 0 timingrulefrequency = 0 if treatmentrule != 0: totalnumberoftreatments = 0 sql = db.make_insert_user_sql( dbo, "medicalprofile", username, (("ID", db.di(nprofid)), ("ProfileName", utils.df_t(data, "profilename")), ("TreatmentName", utils.df_t(data, "treatmentname")), ("Dosage", utils.df_t(data, "dosage")), ("Cost", utils.df_m(data, "cost", l)), ("TimingRule", db.di(timingrule)), ("TimingRuleFrequency", db.di(timingrulefrequency)), ("TimingRuleNoFrequencies", db.di(timingrulenofrequencies)), ("TreatmentRule", utils.df_s(data, "treatmentrule")), ("TotalNumberOfTreatments", db.di(totalnumberoftreatments)), ("Comments", utils.df_t(data, "comments")))) db.execute(dbo, sql) audit.create( dbo, username, "medicalprofile", str(nprofid) + ": " + utils.df_ks(data, "treatmentname") + " " + utils.df_ks(data, "dosage"))