Exemple #1
0
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))
Exemple #2
0
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)
Exemple #3
0
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))
Exemple #4
0
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)))
Exemple #5
0
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"))
Exemple #6
0
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))
Exemple #7
0
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))
Exemple #8
0
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_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))
Exemple #10
0
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)
Exemple #11
0
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))
Exemple #12
0
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)))
Exemple #13
0
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)))
Exemple #14
0
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))
Exemple #15
0
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))
Exemple #16
0
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))
Exemple #17
0
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"]))
Exemple #18
0
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)
Exemple #19
0
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)
Exemple #20
0
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)))
Exemple #21
0
def update_user_settings(dbo, username, email = "", realname = "", locale = "", theme = ""):
    userid = db.query_int(dbo, "SELECT ID FROM users WHERE Username = '%s'" % 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", ]))
Exemple #22
0
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))
Exemple #23
0
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))
Exemple #24
0
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)
Exemple #25
0
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", ]))
Exemple #26
0
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 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))
Exemple #28
0
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))
Exemple #29
0
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))
Exemple #30
0
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))