def update_movement_from_form(dbo, username, data): """ Updates a movement record from posted form data """ validate_movement_form_data(dbo, data) l = dbo.locale movementid = utils.df_ki(data, "movementid") sql = db.make_update_user_sql(dbo, "adoption", username, "ID=%d" % movementid, ( ( "AdoptionNumber", utils.df_t(data, "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")) )) preaudit = db.query(dbo, "SELECT * FROM adoption WHERE ID = %d" % movementid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM adoption WHERE ID = %d" % movementid) audit.edit(dbo, username, "adoption", audit.map_diff(preaudit, postaudit)) animal.update_animal_status(dbo, utils.df_ki(data, "animal")) animal.update_variable_animal_data(dbo, utils.df_ki(data, "animal")) update_movement_donation(dbo, movementid)
def update_movement_from_form(dbo, username, post): """ Updates a movement record from posted form data """ validate_movement_form_data(dbo, post) movementid = post.integer("movementid") sql = db.make_update_user_sql(dbo, "adoption", username, "ID=%d" % movementid, ( ( "AdoptionNumber", post.db_string("adoptionno")), ( "OwnerID", post.db_integer("person")), ( "RetailerID", post.db_integer("retailer")), ( "AnimalID", post.db_integer("animal")), ( "OriginalRetailerMovementID", post.db_integer("originalretailermovement")), ( "MovementDate", post.db_date("movementdate")), ( "MovementType", post.db_integer("type")), ( "ReturnDate", post.db_date("returndate")), ( "ReturnedReasonID", post.db_integer("returncategory")), ( "Donation", post.db_integer("donation")), ( "InsuranceNumber", post.db_string("insurance")), ( "ReasonForReturn", post.db_string("reason")), ( "ReservationDate", post.db_date("reservationdate")), ( "ReservationCancelledDate", post.db_date("reservationcancelled")), ( "ReservationStatusID", post.db_integer("reservationstatus")), ( "IsTrial", post.db_boolean("trial")), ( "IsPermanentFoster", post.db_boolean("permanentfoster")), ( "TrialEndDate", post.db_date("trialenddate")), ( "Comments", post.db_string("comments")) )) preaudit = db.query(dbo, "SELECT * FROM adoption WHERE ID = %d" % movementid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM adoption WHERE ID = %d" % movementid) audit.edit(dbo, username, "adoption", movementid, audit.map_diff(preaudit, postaudit)) animal.update_animal_status(dbo, post.integer("animal")) animal.update_variable_animal_data(dbo, post.integer("animal")) update_movement_donation(dbo, movementid)
def update_animalcontrol_dispatchnow(dbo, acid, username): """ Updates an animal control incident record, marking it dispatched now with the current user as ACO. """ db.execute(dbo, "UPDATE animalcontrol SET DispatchedACO=%s, DispatchDateTime=%s WHERE ID=%d" % (db.ds(username), db.ddt(now(dbo.timezone)), acid)) audit.edit(dbo, username, "animalcontrol", acid, "aco=%s, dispatch=%s" % (username, now(dbo.timezone)))
def update_foundanimal_from_form(dbo, data, username): """ Updates a found animal record from the screen data: The webpy data object containing form parameters """ l = dbo.locale lfid = utils.df_ki(data, "id") 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)) preaudit = db.query(dbo, "SELECT * FROM animalfound WHERE ID = %d" % lfid) db.execute(dbo, db.make_update_user_sql(dbo, "animalfound", username, "ID=%d" % lfid, ( ( "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")) ))) additional.save_values_for_link(dbo, data, lfid, "foundanimal") postaudit = db.query(dbo, "SELECT * FROM animalfound WHERE ID = %d" % lfid) audit.edit(dbo, username, "animalfound", audit.map_diff(preaudit, postaudit))
def update_file_content(dbo, username, mid, content): """ Updates the dbfs content for the file pointed to by id """ dbfs.replace_string(dbo, content, get_name_for_id(dbo, mid)) db.execute(dbo, "UPDATE media SET Date = %s WHERE ID = %d" % ( db.nowsql(), int(mid) )) audit.edit(dbo, username, "media", str(mid) + " changed file contents")
def update_stocklevel_from_form(dbo, post, username): """ Updates 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("stocklevelid") 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)) preaudit = db.query(dbo, "SELECT * FROM stocklevel WHERE ID = %d" % slid) if len(preaudit) == 0: raise utils.ASMValidationError("stocklevel %d does not exist, cannot adjust" % slid) db.execute(dbo, db.make_update_sql("stocklevel", "ID=%d" % slid, ( ( "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") ) ))) postaudit = db.query(dbo, "SELECT * FROM stocklevel WHERE ID = %d" % slid) diff = postaudit[0]["BALANCE"] - preaudit[0]["BALANCE"] if diff != 0: insert_stockusage(dbo, username, slid, diff, post.date("usagedate"), post.integer("usagetype"), post["comments"]) audit.edit(dbo, username, "animalcontrol", slid, audit.map_diff(preaudit, postaudit))
def update_donation_from_form(dbo, username, data): """ Updates a donation record from posted form data """ l = dbo.locale donationid = utils.df_ki(data, "donationid") sql = db.make_update_user_sql( dbo, "ownerdonation", username, "ID=%d" % 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)), ("IsGiftAid", utils.df_s(data, "giftaid")), ("Comments", utils.df_t(data, "comments")))) preaudit = db.query( dbo, "SELECT * FROM ownerdonation WHERE ID = %d" % donationid) db.execute(dbo, sql) postaudit = db.query( dbo, "SELECT * FROM ownerdonation WHERE ID = %d" % donationid) audit.edit(dbo, username, "ownerdonation", audit.map_diff(preaudit, postaudit)) update_matching_transaction(dbo, username, donationid) check_create_next_donation(dbo, username, donationid) movement.update_movement_donation(dbo, utils.df_ki(data, "movement"))
def update_donation_from_form(dbo, username, data): """ Updates a donation record from posted form data """ l = dbo.locale donationid = utils.df_ki(data, "donationid") sql = db.make_update_user_sql(dbo, "ownerdonation", username, "ID=%d" % 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)), ( "IsGiftAid", utils.df_s(data, "giftaid")), ( "Comments", utils.df_t(data, "comments")) )) preaudit = db.query(dbo, "SELECT * FROM ownerdonation WHERE ID = %d" % donationid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM ownerdonation WHERE ID = %d" % donationid) audit.edit(dbo, username, "ownerdonation", audit.map_diff(preaudit, postaudit)) update_matching_transaction(dbo, username, donationid) check_create_next_donation(dbo, username, donationid) movement.update_movement_donation(dbo, utils.df_ki(data, "movement"))
def update(self, table, where, values, user="", setOverrideDBLock=False, setRecordVersion=True, setLastChanged=True, writeAudit=True): """ Updates a row in a table. table: The table to update where: Either a where clause or an int ID value for ID=where values: A dict of column names with values user: The user account performing the update. If set, adds CreatedBy/Date/LastChangedBy/Date fields setRecordVersion: If user is non-blank and this is True, sets RecordVersion writeAudit: If True, writes an audit record for the update returns the number of rows updated """ if user != "" and setLastChanged: values["LastChangedBy"] = user values["LastChangedDate"] = self.now() if setRecordVersion: values["RecordVersion"] = self.get_recordversion() values = self.encode_str_before_write(values) iid = 0 if type(where) == int: iid = where where = "ID=%s" % where sql = "UPDATE %s SET %s WHERE %s" % ( table, ",".join( ["%s=?" % x for x in values.iterkeys()] ), where ) if iid > 0: preaudit = self.query_row(table, iid) rows_affected = self.execute(sql, values.values(), override_lock=setOverrideDBLock) if iid > 0: postaudit = self.query_row(table, iid) if user != "" and iid > 0 and writeAudit: audit.edit(self, user, table, iid, audit.map_diff(preaudit, postaudit)) return rows_affected
def update_account_from_form(dbo, username, post): """ Updates an account from posted form data """ l = dbo.locale accountid = post.integer("accountid") 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' AND ID <> %d" % (post["code"], accountid)): raise utils.ASMValidationError(i18n._("Account code '{0}' has already been used.", l).format(post["code"])) sql = db.make_update_user_sql(dbo, "accounts", username, "ID=%d" % accountid, ( ( "Code", post.db_string("code")), ( "AccountType", post.db_integer("type")), ( "DonationTypeID", post.db_integer("donationtype")), ( "Description", post.db_string("description")) )) preaudit = db.query(dbo, "SELECT * FROM accounts WHERE ID = %d" % accountid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM accounts WHERE ID = %d" % accountid) audit.edit(dbo, username, "accounts", audit.map_diff(preaudit, postaudit)) db.execute(dbo, "DELETE FROM accountsrole WHERE AccountID = %d" % 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))
def update_trx_from_form(dbo, username, post): """ Updates 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") trxid = post.integer("trxid") 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 sql = db.make_update_user_sql(dbo, "accountstrx", username, "ID=%d" % trxid, ( ( "TrxDate", post.db_date("trxdate")), ( "Description", post.db_string("description")), ( "Reconciled", post.db_integer("reconciled")), ( "Amount", db.di(amount)), ( "SourceAccountID", db.di(source)), ( "DestinationAccountID", db.di(target)) )) preaudit = db.query(dbo, "SELECT * FROM accountstrx WHERE ID = %d" % trxid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM accountstrx WHERE ID = %d" % trxid) audit.edit(dbo, username, "accountstrx", audit.map_diff(preaudit, postaudit))
def rename_document_template(dbo, username, dbfsid, newname): """ Renames a document template. """ if not newname.endswith(".html") and not newname.endswith(".odt"): newname += ".html" rename_file_id(dbo, dbfsid, newname) audit.edit(dbo, username, "documenttemplate", dbfsid, "rename %d to %s" % (dbfsid, newname))
def update_field_from_form(dbo, username, post): """ Updates an additional field record. All aspects of an additional field can be changed after creation since only the ID ties things together. """ aid = post.integer("id") sql = db.make_update_sql( "additionalfield", "ID=%d" % aid, ( ("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")), ), ) preaudit = db.query(dbo, "SELECT * FROM additionalfield WHERE ID = %d" % aid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM additionalfield WHERE ID = %d" % aid) audit.edit(dbo, username, "additionalfield", audit.map_diff(preaudit, postaudit))
def update_treatment_required(dbo, username, amtid, newdate): """ Marks a treatment record as required on newdate, assuming that newdate is valid. """ db.execute(dbo, "UPDATE animalmedicaltreatment SET DateRequired = %s WHERE ID = %d" % (db.dd(newdate), amtid)) audit.edit(dbo, username, "animalmedicaltreatment", "%d required => %s" % (amtid, str(newdate)))
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 update_user_from_form(dbo, username, post): """ Updates 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. """ userid = post.integer("userid") sql = db.make_update_sql("users", "ID=%d" % userid, ( ( "RealName", post.db_string("realname")), ( "EmailAddress", post.db_string("email")), ( "SuperUser", post.db_integer("superuser")), ( "OwnerID", post.db_integer("person")), ( "SiteID", post.db_integer("site")), ( "LocationFilter", post.db_string("locationfilter")), ( "IPRestriction", post.db_string("iprestriction")) )) preaudit = db.query(dbo, "SELECT * FROM users WHERE ID = %d" % userid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM users WHERE ID = %d" % userid) audit.edit(dbo, username, "users", userid, audit.map_diff(preaudit, postaudit, [ "USERNAME", ])) db.execute(dbo, "DELETE FROM userrole WHERE UserID = %d" % userid) roles = post["roles"].strip() if roles != "": for rid in roles.split(","): if rid.strip() != "": db.execute(dbo, "INSERT INTO userrole VALUES (%d, %d)" % (userid, int(rid)))
def update_waitinglist_from_form(dbo, data, username): """ Updates a waiting list record from the screen data: The webpy data object containing form parameters """ l = dbo.locale wlid = utils.df_ki(data, "id") 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)) preaudit = db.query(dbo, "SELECT * FROM animalwaitinglist WHERE ID = %d" % wlid) db.execute(dbo, db.make_update_user_sql(dbo, "animalwaitinglist", username, "ID=%d" % wlid, ( ( "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", utils.df_d(data, "dateoflastownercontact", l)), ( "ReasonForRemoval", utils.df_t(data, "reasonforremoval")), ( "Comments", utils.df_t(data, "comments")) ))) additional.save_values_for_link(dbo, data, wlid, "waitinglist") postaudit = db.query(dbo, "SELECT * FROM animalwaitinglist WHERE ID = %d" % wlid) audit.edit(dbo, username, "animalwaitinglist", audit.map_diff(preaudit, postaudit))
def update_user_from_form(dbo, username, data): """ Updates 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. """ userid = utils.df_ki(data, "userid") sql = db.make_update_sql( "users", "ID=%d" % userid, (("RealName", utils.df_t(data, "realname")), ("EmailAddress", utils.df_t(data, "email")), ("SuperUser", utils.df_s(data, "superuser")), ("OwnerID", utils.df_s(data, "person")), ("LocationFilter", utils.df_t(data, "locationfilter")), ("IPRestriction", utils.df_t(data, "iprestriction")))) preaudit = db.query(dbo, "SELECT * FROM users WHERE ID = %d" % userid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM users WHERE ID = %d" % userid) audit.edit(dbo, username, "users", audit.map_diff(preaudit, postaudit, [ "USERNAME", ])) db.execute(dbo, "DELETE FROM userrole WHERE UserID = %d" % userid) if utils.df_ki(data, "issuperuser") == 0: 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)" % (userid, int(rid)))
def update_vaccination_from_form(dbo, username, data): """ Updates a vaccination record from posted form data """ l = dbo.locale vaccid = utils.df_ki(data, "vaccid") if utils.df_kd(data, "required", l) is None: raise utils.ASMValidationError( _("Required date must be a valid date", l)) sql = db.make_update_user_sql( dbo, "animalvaccination", username, "ID=%d" % vaccid, (("AnimalID", db.di(utils.df_ki(data, "animal"))), ("VaccinationID", utils.df_s(data, "type")), ("DateOfVaccination", utils.df_d(data, "given", l)), ("DateRequired", utils.df_d(data, "required", l)), ("Cost", utils.df_m(data, "cost", l)), ("Comments", utils.df_t(data, "comments")))) preaudit = db.query( dbo, "SELECT * FROM animalvaccination WHERE ID = %d" % vaccid) db.execute(dbo, sql) postaudit = db.query( dbo, "SELECT * FROM animalvaccination WHERE ID = %d" % vaccid) audit.edit(dbo, username, "animalvaccination", audit.map_diff(preaudit, postaudit))
def update_regimen_from_form(dbo, username, data): """ Updates a regimen record from posted form data """ l = dbo.locale regimenid = utils.df_ki(data, "regimenid") if utils.df_ks(data, "treatmentname") == "": raise utils.ASMValidationError(_("Treatment name cannot be blank", l)) sql = db.make_update_user_sql( dbo, "animalmedical", username, "ID=%d" % regimenid, (("TreatmentName", utils.df_t(data, "treatmentname")), ("Dosage", utils.df_t(data, "dosage")), ("Status", utils.df_s(data, "status")), ("Cost", utils.df_m(data, "cost", l)), ("Comments", utils.df_t(data, "comments")))) preaudit = db.query(dbo, "SELECT * FROM animalmedical WHERE ID=%d" % regimenid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM animalmedical WHERE ID=%d" % regimenid) audit.edit( dbo, username, "animalmedical", audit.map_diff(preaudit, postaudit, ["TREATMENTNAME", "DOSAGE"])) update_medical_treatments(dbo, username, utils.df_ki(data, "regimenid"))
def update_test_from_form(dbo, username, data): """ Updates a test record from posted form data """ l = dbo.locale testid = utils.df_ki(data, "testid") if utils.df_kd(data, "required", l) is None: raise utils.ASMValidationError( _("Required date must be a valid date", l)) sql = db.make_update_user_sql( dbo, "animaltest", username, "ID=%d" % testid, (("AnimalID", db.di(utils.df_ki(data, "animal"))), ("TestTypeID", utils.df_s(data, "type")), ("TestResultID", utils.df_s(data, "result")), ("DateOfTest", utils.df_d(data, "given", l)), ("DateRequired", utils.df_d(data, "required", l)), ("Cost", utils.df_m(data, "cost", l)), ("Comments", utils.df_t(data, "comments")))) preaudit = db.query(dbo, "SELECT * FROM animaltest WHERE ID = %d" % testid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM animaltest WHERE ID = %d" % testid) audit.edit(dbo, username, "animaltest", audit.map_diff(preaudit, postaudit)) # ASM2_COMPATIBILITY update_asm2_tests(dbo, testid)
def update_diary_from_form(dbo, username, data): """ Updates a diary note from form data """ l = dbo.locale diaryid = utils.df_ki(data, "diaryid") if utils.df_ks(data, "diarydate") == "": raise utils.ASMValidationError(i18n._("Diary date cannot be blank", l)) if utils.df_kd(data, "diarydate", l) is None: raise utils.ASMValidationError(i18n._("Diary date is not valid", l)) if utils.df_ks(data, "subject") == "": raise utils.ASMValidationError(i18n._("Diary subject cannot be blank", l)) if utils.df_ks(data, "note") == "": raise utils.ASMValidationError(i18n._("Diary note cannot be blank", l)) diarytime = utils.df_ks(data, "diarytime").strip() if diarytime != "": if diarytime.find(":") == -1: raise utils.ASMValidationError(i18n._("Invalid time, times should be in HH:MM format", l)) if not utils.is_numeric(diarytime.replace(":", "")): raise utils.ASMValidationError(i18n._("Invalid time, times should be in HH:MM format", l)) sql = db.make_update_user_sql(dbo, "diary", username, "ID=%d" % diaryid, ( ( "DiaryDateTime", utils.df_dt(data, "diarydate", "diarytime", l) ), ( "DiaryForName", utils.df_t(data, "diaryfor") ), ( "Subject", utils.df_t(data, "subject") ), ( "Note", utils.df_t(data, "note") ), ( "Comments", utils.df_t(data, "comments") ), ( "DateCompleted", utils.df_d(data, "completed", l) ) )) preaudit = db.query(dbo, "SELECT * FROM diary WHERE ID=%d" % diaryid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diary WHERE ID=%d" % diaryid) audit.edit(dbo, username, "diary", audit.map_diff(preaudit, postaudit))
def update_diary_from_form(dbo, username, post): """ Updates a diary note from form data """ l = dbo.locale diaryid = post.integer("diaryid") if post["diarydate"] == "": raise utils.ASMValidationError(i18n._("Diary date cannot be blank", l)) if post.date("diarydate") is None: raise utils.ASMValidationError(i18n._("Diary date is not valid", l)) if post["subject"] == "": raise utils.ASMValidationError( i18n._("Diary subject cannot be blank", l)) if post["note"] == "": raise utils.ASMValidationError(i18n._("Diary note cannot be blank", l)) diarytime = post["diarytime"].strip() if diarytime != "": if diarytime.find(":") == -1: raise utils.ASMValidationError( i18n._("Invalid time, times should be in HH:MM format", l)) if not utils.is_numeric(diarytime.replace(":", "")): raise utils.ASMValidationError( i18n._("Invalid time, times should be in HH:MM format", l)) sql = db.make_update_user_sql( dbo, "diary", username, "ID=%d" % diaryid, (("DiaryDateTime", post.db_datetime("diarydate", "diarytime")), ("DiaryForName", post.db_string("diaryfor")), ("Subject", post.db_string("subject")), ("Note", post.db_string("note")), ("DateCompleted", post.db_date("completed")))) preaudit = db.query(dbo, "SELECT * FROM diary WHERE ID=%d" % diaryid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diary WHERE ID=%d" % diaryid) audit.edit(dbo, username, "diary", audit.map_diff(preaudit, postaudit))
def update_transport_from_form(dbo, username, post): """ Updates a movement record from posted form data """ transportid = post.integer("transportid") sql = db.make_update_user_sql(dbo, "animaltransport", username, "ID=%d" % 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")) )) preaudit = db.query(dbo, "SELECT * FROM animaltransport WHERE ID = %d" % transportid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM animaltransport WHERE ID = %d" % transportid) audit.edit(dbo, username, "animaltransport", transportid, audit.map_diff(preaudit, postaudit))
def complete_diary_note(dbo, username, diaryid): """ Marks a diary note completed as of right now """ db.execute( dbo, "UPDATE diary SET DateCompleted = %s WHERE ID = %d" % (db.dd(i18n.now(dbo.timezone)), int(diaryid))) audit.edit(dbo, username, "diary", str(diaryid) + " => complete")
def update_media_notes(dbo, username, mid, notes): sql = db.make_update_sql("media", "ID=%d" % int(mid), ( ("MediaNotes", db.ds(notes)), ("MediaName", "MediaName"), ("UpdatedSinceLastPublish", db.di(1)), )) db.execute(dbo, sql) audit.edit(dbo, username, "media", str(mid) + "notes => " + notes)
def set_excluded(dbo, username, mid, exclude=1): """ Marks the media with id excluded from publishing. """ db.execute( dbo, "UPDATE media SET ExcludeFromPublish = %d WHERE ID = %d" % (exclude, mid)) audit.edit(dbo, username, "media", str(mid) + ": excluded from publishing")
def update_media_notes(dbo, username, mid, notes): sql = db.make_update_sql("media", "ID=%d" % int(mid), ( ( "MediaNotes", db.ds(notes)), ( "MediaName", "MediaName" ), ( "UpdatedSinceLastPublish", db.di(1)), )) db.execute(dbo, sql) audit.edit(dbo, username, "media", str(mid) + "notes => " + notes)
def set_web_preferred(dbo, username, mid): """ Makes the media with id the preferred for the web in the link """ link = db.query(dbo, "SELECT LinkID, LinkTypeID FROM media WHERE ID = %d" % int(mid))[0] db.execute(dbo, "UPDATE media SET WebsitePhoto = 0 WHERE LinkID = %d AND LinkTypeID = %d" % ( int(link["LINKID"]), int(link["LINKTYPEID"]))) db.execute(dbo, "UPDATE media SET WebsitePhoto = 1 WHERE ID = %d" % int(mid)) audit.edit(dbo, username, "media", str(id) + ": web preferred for " + str(link["LINKID"]) + "/" + str(link["LINKTYPEID"]))
def csave(dbo, username, post): """ Takes configuration data passed as a web post and saves it to the database. """ def valid_code(s): """ Returns True if s has a valid code portion in it """ VALID_CODES = ("XX", "XXX", "NN", "NNN", "UUUU", "UUUUUUUUUU") for v in VALID_CODES: if s.find(v) != -1: return True return False cmap = get_map(dbo) def put(k, v, sanitiseXSS = True): # Only update the value in the database if it's new or changed if k not in cmap or cmap[k] != v: cset(dbo, k, v, sanitiseXSS = sanitiseXSS, invalidateConfigCache = False) for k in post.data.iterkeys(): if k == "mode" or k == "filechooser": continue v = post.string(k, False) if k == "EmailSignature": # It's HTML - don't XSS escape it put(k, v, sanitiseXSS = False) elif k == "CodingFormat": # If there's no valid N, X or U tokens in there, it's not valid so reset to # the default. if not valid_code(v): put(k, "TYYYYNNN") else: put(k, v) elif k == "ShortCodingFormat": # If there's no N, X or U in there, it's not valid so reset to # the default. if not valid_code(v): put(k, "NNT") else: put(k, v) elif k == "DefaultDailyBoardingCost": # Need to handle currency fields differently put(k, str(post.integer(k))) elif k.startswith("rc:"): # It's a NOT check if v == "checked": v = "No" if v == "off": v = "Yes" put(k[3:], v) elif v == "checked" or v == "off": # It's a checkbox if v == "checked": v = "Yes" if v == "off": v = "No" put(k, v) else: # Plain string value put(k, v) audit.edit(dbo, username, "configuration", 0, str(post)) invalidate_config_cache(dbo)
def update_vaccination_required(dbo, username, vaccid, newdate): """ Gives a vaccination record a required date of newdate, assuming that newdate is valid. """ db.execute(dbo, db.make_update_user_sql(dbo, "animalvaccination", username, "ID = %d" % vaccid, ( ( "DateRequired", db.dd(newdate) ), ))) audit.edit(dbo, username, "animalvaccination", "%d required => %s" % (vaccid, str(newdate)))
def rediarise_diary_note(dbo, username, diaryid, newdate): """ Moves a diary note on to the date supplied (newdate is a python date) """ db.execute( dbo, "UPDATE diary SET DiaryDateTime = %s WHERE ID = %d" % (db.dd(newdate), int(diaryid))) audit.edit(dbo, username, "diary", str(diaryid) + " => moved on to " + str(newdate))
def rename_document_template(dbo, username, dtid, newname): """ Renames a document template. """ if not newname.endswith(".html") and not newname.endswith(".odt"): newname += ".html" dbo.update("templatedocument", dtid, {"Name": newname}) audit.edit(dbo, username, "templatedocument", dtid, "rename %d to %s" % (dtid, newname))
def receive_donation(dbo, username, did): """ Marks a donation received """ if id is None or did == "": return db.execute(dbo, "UPDATE ownerdonation SET Date = %s WHERE ID = %d" % ( db.dd(i18n.now(dbo.timezone)), int(did))) audit.edit(dbo, username, "ownerdonation", str(did) + ": received") update_matching_transaction(dbo, username, int(did)) check_create_next_donation(dbo, username, did)
def update_file_content(dbo, username, mid, content): """ Updates the dbfs content for the file pointed to by id """ dbfs.replace_string(dbo, content, get_name_for_id(dbo, mid)) db.execute( dbo, "UPDATE media SET Date = %s WHERE ID = %d" % (db.nowsql(), int(mid))) audit.edit(dbo, username, "media", str(mid) + " changed file contents")
def complete_vaccination(dbo, username, vaccinationid): """ Marks a vaccination completed today """ 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")
def update_animalcontrol_from_form(dbo, post, username): """ Updates an animal control incident record from the screen data: The webpy data object containing form parameters """ l = dbo.locale acid = post.integer("id") if post.date("incidentdate") is None: raise utils.ASMValidationError(_("Incident date cannot be blank", l)) preaudit = db.query(dbo, "SELECT * FROM animalcontrol WHERE ID = %d" % acid) db.execute( dbo, db.make_update_user_sql( dbo, "animalcontrol", username, "ID=%d" % acid, (("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"))))) additional.save_values_for_link(dbo, post, acid, "incident") postaudit = db.query(dbo, "SELECT * FROM animalcontrol WHERE ID = %d" % acid) audit.edit(dbo, username, "animalcontrol", audit.map_diff(preaudit, postaudit))
def update_waitinglist_remove(dbo, username, wid): """ Marks a waiting list record as removed """ db.execute( dbo, "UPDATE animalwaitinglist SET DateRemovedFromList = %s WHERE ID = %d" % (db.dd(now(dbo.timezone)), int(wid))) audit.edit( dbo, username, "animalwaitinglist", "%s: DateRemovedFromList ==> %s" % (str(wid), python2display(dbo.locale, now(dbo.timezone))))
def update_treatment_required(dbo, username, amtid, newdate): """ Marks a treatment record as required on newdate, assuming that newdate is valid. """ db.execute( dbo, "UPDATE animalmedicaltreatment SET DateRequired = %s WHERE ID = %d" % (db.dd(newdate), amtid)) audit.edit(dbo, username, "animalmedicaltreatment", "%d required => %s" % (amtid, str(newdate)))
def receive_donation(dbo, username, did): """ Marks a donation received """ if id is None or did == "": return db.execute( dbo, "UPDATE ownerdonation SET Date = %s WHERE ID = %d" % (db.dd(i18n.now(dbo.timezone)), int(did))) audit.edit(dbo, username, "ownerdonation", str(did) + ": received") update_matching_transaction(dbo, username, int(did)) check_create_next_donation(dbo, username, did)
def update_user_settings(dbo, username, email = "", realname = "", locale = "", theme = ""): userid = db.query_int(dbo, "SELECT ID FROM users WHERE Username = '******'" % username) sql = db.make_update_sql("users", "ID=%d" % userid, ( ( "RealName", db.ds(realname) ), ( "EmailAddress", db.ds(email) ), ( "ThemeOverride", db.ds(theme) ), ( "LocaleOverride", db.ds(locale) ) )) preaudit = db.query(dbo, "SELECT * FROM users WHERE ID = %d" % int(userid))[0] db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM users WHERE ID = %d" % int(userid))[0] audit.edit(dbo, username, "users", audit.map_diff(preaudit, postaudit, [ "USERNAME", ]))
def update_vaccination_required(dbo, username, vaccid, newdate): """ Gives a vaccination record a required date of newdate, assuming that newdate is valid. """ db.execute( dbo, db.make_update_user_sql(dbo, "animalvaccination", username, "ID = %d" % vaccid, (("DateRequired", db.dd(newdate)), ))) audit.edit(dbo, username, "animalvaccination", "%d required => %s" % (vaccid, str(newdate)))
def csave(dbo, username, data): """ Takes configuration data passed as a web post and saves it to the database. """ l = dbo.locale def valid_code(s): """ Returns True if s has a valid code portion in it """ VALID_CODES = ("NN", "NNN", "UUUU", "UUUUUUUUUU") for v in VALID_CODES: if s.find(v) != -1: return True return False for k in data.iterkeys(): v = utils.df_ks(data, k) if k == "mode": pass elif k == "CodingFormat": # If there's no valid N or U tokens in there, it's not valid so reset to # the default. if not valid_code(v): cset(dbo, k, "TYYYYNNN") else: cset(dbo, k, v) elif k == "ShortCodingFormat": # If there's no N or U in there, it's not valid so reset to # the default. if not valid_code(v): cset(dbo, k, "NNT") else: cset(dbo, k, v) elif k == "DefaultDailyBoardingCost": # Need to handle currency fields differently cset(dbo, k, utils.df_m(data, k, l)) elif k.startswith("rc:"): # It's a NOT check if v == "checked": v = "No" if v == "off": v = "Yes" cset(dbo, k[3:], v) elif v == "checked" or v == "off": # It's a checkbox if v == "checked": v = "Yes" if v == "off": v = "No" cset(dbo, k, v) else: # Must be a string cset(dbo, k, v) audit.edit(dbo, username, "configuration", str(data))
def update_diarytaskhead_from_form(dbo, username, post): """ Updates a diary task header from form data """ tid = post.integer("diarytaskid") sql = db.make_update_sql("diarytaskhead", "ID=%d" % tid, ( ( "Name", post.db_string("name")), ( "RecordType", post.db_integer("type")) )) preaudit = db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID=%d" % tid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID=%d" % tid) audit.edit(dbo, username, "diarytaskhead", tid, audit.map_diff(preaudit, postaudit))
def update_role_from_form(dbo, username, post): """ Updates a role record from posted form data """ roleid = post.integer("roleid") sql = db.make_update_sql("role", "ID=%d" % roleid, ( ( "Rolename", post.db_string("rolename")), ( "SecurityMap", post.db_string("securitymap")) )) preaudit = db.query(dbo, "SELECT * FROM role WHERE ID = %d" % roleid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM role WHERE ID = %d" % roleid) audit.edit(dbo, username, "role", roleid, audit.map_diff(preaudit, postaudit, [ "ROLENAME", ]))
def update_html_publisher_template(dbo, username, name, header, body, footer): """ Creates a new html publisher template with the name given. If the template already exists, it recreates it. """ delete_path(dbo, "/internet/" + name) delete(dbo, name, "/internet") create_path(dbo, "/internet", name) put_string(dbo, "head.html", "/internet/%s" % name, header) put_string(dbo, "body.html", "/internet/%s" % name, body) put_string(dbo, "foot.html", "/internet/%s" % name, footer) al.debug("%s updated html template %s" % (username, name), "dbfs.update_html_publisher_template", dbo) audit.edit(dbo, username, "htmltemplate", 0, "altered html template '%s'" % name)
def update_diarytaskhead_from_form(dbo, username, data): """ Updates a diary task header from form data """ tid = utils.df_ki(data, "diarytaskid") sql = db.make_update_sql("diarytaskhead", "ID=%d" % tid, ( ( "Name", utils.df_t(data, "name")), ( "RecordType", utils.df_s(data, "type")) )) preaudit = db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID=%d" % tid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID=%d" % tid) audit.edit(dbo, username, "diarytaskhead", audit.map_diff(preaudit, postaudit))
def update_diarytaskhead_from_form(dbo, username, post): """ Updates a diary task header from form data """ tid = post.integer("diarytaskid") sql = db.make_update_sql("diarytaskhead", "ID=%d" % tid, (("Name", post.db_string("name")), ("RecordType", post.db_integer("type")))) preaudit = db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID=%d" % tid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID=%d" % tid) audit.edit(dbo, username, "diarytaskhead", audit.map_diff(preaudit, postaudit))
def update_diarytaskhead_from_form(dbo, username, data): """ Updates a diary task header from form data """ tid = utils.df_ki(data, "diarytaskid") sql = db.make_update_sql("diarytaskhead", "ID=%d" % tid, (("Name", utils.df_t(data, "name")), ("RecordType", utils.df_s(data, "type")))) preaudit = db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID=%d" % tid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID=%d" % tid) audit.edit(dbo, username, "diarytaskhead", audit.map_diff(preaudit, postaudit))
def update_animalcontrol_from_form(dbo, post, username): """ Updates an animal control incident record from the screen data: The webpy data object containing form parameters """ l = dbo.locale acid = post.integer("id") if not db.check_recordversion(dbo, "animalcontrol", post.integer("id"), post.integer("recordversion")): raise utils.ASMValidationError(_("This record has been changed by another user, please reload.", l)) if post.date("incidentdate") is None: raise utils.ASMValidationError(_("Incident date cannot be blank", l)) preaudit = db.query(dbo, "SELECT * FROM animalcontrol WHERE ID = %d" % acid) db.execute(dbo, db.make_update_user_sql(dbo, "animalcontrol", username, "ID=%d" % acid, ( ( "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")) ))) additional.save_values_for_link(dbo, post, acid, "incident") postaudit = db.query(dbo, "SELECT * FROM animalcontrol WHERE ID = %d" % acid) audit.edit(dbo, username, "animalcontrol", acid, audit.map_diff(preaudit, postaudit))
def update_investigation_from_form(dbo, username, data): """ Updates an investigation record from posted form data """ l = dbo.locale investigationid = utils.df_ki(data, "investigationid") sql = db.make_update_user_sql(dbo, "ownerinvestigation", username, "ID=%d" % investigationid, ( ( "Date", utils.df_d(data, "date", l)), ( "Notes", utils.df_t(data, "notes")) )) preaudit = db.query(dbo, "SELECT * FROM ownerinvestigation WHERE ID = %d" % investigationid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM ownerinvestigation WHERE ID = %d" % investigationid) audit.edit(dbo, username, "ownerinvestigation", audit.map_diff(preaudit, postaudit))
def update_diarytaskdetail_from_form(dbo, username, data): """ Updates a diary task detail from form data """ did = utils.df_ki(data, "diarytaskdetailid") sql = db.make_update_sql("diarytaskdetail", "ID=%d" % did, ( ( "DayPivot", utils.df_s(data, "pivot")), ( "WhoFor", utils.df_t(data, "for")), ( "Subject", utils.df_t(data, "subject")), ( "Note", utils.df_t(data, "note")) )) preaudit = db.query(dbo, "SELECT * FROM diarytaskdetail WHERE ID=%d" % did) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diarytaskdetail WHERE ID=%d" % did) audit.edit(dbo, username, "diarytaskhead", audit.map_diff(preaudit, postaudit))
def update_onlineform_from_form(dbo, username, data): """ Update an onlineform record from posted data """ formid = utils.df_ki(data, "formid") sql = db.make_update_sql("onlineform", "ID=%d" % 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"))) )) preaudit = db.query(dbo, "SELECT * FROM onlineform WHERE ID = %d" % formid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM onlineform WHERE ID = %d" % formid) audit.edit(dbo, username, "onlineform", audit.map_diff(preaudit, postaudit))
def set_doc_preferred(dbo, username, mid): """ Makes the media with id the preferred for docs in the link """ link = db.query( dbo, "SELECT LinkID, LinkTypeID FROM media WHERE ID = %d" % int(mid))[0] db.execute( dbo, "UPDATE media SET DocPhoto = 0 WHERE LinkID = %d AND LinkTypeID = %d" % (int(link["LINKID"]), int(link["LINKTYPEID"]))) db.execute(dbo, "UPDATE media SET DocPhoto = 1 WHERE ID = %d" % int(mid)) audit.edit( dbo, username, "media", str(mid) + ": document preferred for " + str(link["LINKID"]) + "/" + str(link["LINKTYPEID"]))
def update_role_from_form(dbo, username, data): """ Updates a role record from posted form data """ roleid = utils.df_ki(data, "roleid") sql = db.make_update_sql( "role", "ID=%d" % roleid, (("Rolename", utils.df_t(data, "rolename")), ("SecurityMap", utils.df_t(data, "securitymap")))) preaudit = db.query(dbo, "SELECT * FROM role WHERE ID = %d" % roleid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM role WHERE ID = %d" % roleid) audit.edit(dbo, username, "role", audit.map_diff(preaudit, postaudit, [ "ROLENAME", ]))
def update_diarytaskdetail_from_form(dbo, username, post): """ Updates a diary task detail from form data """ did = post.integer("diarytaskdetailid") sql = db.make_update_sql("diarytaskdetail", "ID=%d" % did, (("DayPivot", post.db_integer("pivot")), ("WhoFor", post.db_string("for")), ("Subject", post.db_string("subject")), ("Note", post.db_string("note")))) preaudit = db.query(dbo, "SELECT * FROM diarytaskdetail WHERE ID=%d" % did) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diarytaskdetail WHERE ID=%d" % did) audit.edit(dbo, username, "diarytaskhead", audit.map_diff(preaudit, postaudit))
def update_diarytaskdetail_from_form(dbo, username, data): """ Updates a diary task detail from form data """ did = utils.df_ki(data, "diarytaskdetailid") sql = db.make_update_sql("diarytaskdetail", "ID=%d" % did, (("DayPivot", utils.df_s(data, "pivot")), ("WhoFor", utils.df_t(data, "for")), ("Subject", utils.df_t(data, "subject")), ("Note", utils.df_t(data, "note")))) preaudit = db.query(dbo, "SELECT * FROM diarytaskdetail WHERE ID=%d" % did) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diarytaskdetail WHERE ID=%d" % did) audit.edit(dbo, username, "diarytaskhead", audit.map_diff(preaudit, postaudit))
def update_account_from_form(dbo, username, post): """ Updates an account from posted form data """ l = dbo.locale accountid = post.integer("accountid") 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' AND ID <> %d" % (post["code"], accountid)): raise utils.ASMValidationError( i18n._("Account code '{0}' has already been used.", l).format(post["code"])) sql = db.make_update_user_sql( dbo, "accounts", username, "ID=%d" % accountid, (("Code", post.db_string("code")), ("AccountType", post.db_integer("type")), ("DonationTypeID", post.db_integer("donationtype")), ("Description", post.db_string("description")))) preaudit = db.query(dbo, "SELECT * FROM accounts WHERE ID = %d" % accountid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM accounts WHERE ID = %d" % accountid) audit.edit(dbo, username, "accounts", audit.map_diff(preaudit, postaudit)) db.execute(dbo, "DELETE FROM accountsrole WHERE AccountID = %d" % 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))
def set_video_preferred(dbo, username, mid): """ Makes the media with id the preferred for video in the link """ link = db.query( dbo, "SELECT LinkID, LinkTypeID FROM media WHERE ID = %d" % int(mid))[0] db.execute( dbo, "UPDATE media SET WebsiteVideo = 0 WHERE LinkID = %d AND LinkTypeID = %d" % (int(link["LINKID"]), int(link["LINKTYPEID"]))) db.execute(dbo, "UPDATE media SET WebsiteVideo = 1 WHERE ID = %d" % int(mid)) audit.edit( dbo, username, "media", str(id) + ": video preferred for " + str(link["LINKID"]) + "/" + str(link["LINKTYPEID"]))