示例#1
0
文件: lostfound.py 项目: rutaq/asm3
def update_foundanimal_from_form(dbo, post, username):
    """
    Updates a found animal record from the screen
    post: The webpy data object containing form parameters
    """
    l = dbo.locale
    lfid = post.integer("id")

    if not dbo.optimistic_check("animalfound", post.integer("id"), post.integer("recordversion")):
        raise utils.ASMValidationError(_("This record has been changed by another user, please reload.", l))

    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))

    dbo.update("animalfound", lfid, {
        "AnimalTypeID":     post.integer("species"),
        "DateReported":     post.date("datereported"),
        "ReturnToOwnerDate": post.date("returntoownerdate"),
        "DateFound":        post.date("datefound"),
        "Sex":              post.integer("sex"),
        "BreedID":          post.integer("breed"),
        "AgeGroup":         post["agegroup"],
        "BaseColourID":     post.integer("colour"),
        "DistFeat":         post["markings"],
        "AreaFound":        post["areafound"],
        "AreaPostcode":     post["areapostcode"],
        "OwnerID":          post.integer("owner"),
        "Comments":         post["comments"]
    }, username)
    additional.save_values_for_link(dbo, post, lfid, "foundanimal")
示例#2
0
文件: lostfound.py 项目: rutaq/asm3
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 = dbo.insert("animalfound", {
        "AnimalTypeID":     post.integer("species"),
        "DateReported":     post.date("datereported"),
        "ReturnToOwnerDate": post.date("returntoownerdate"),
        "DateFound":        post.date("datefound"),
        "Sex":              post.integer("sex"),
        "BreedID":          post.integer("breed"),
        "AgeGroup":         post["agegroup"],
        "BaseColourID":     post.integer("colour"),
        "DistFeat":         post["markings"],
        "AreaFound":        post["areafound"],
        "AreaPostcode":     post["areapostcode"],
        "OwnerID":          post.integer("owner"),
        "Comments":         post["comments"]
    }, username)

    # Save any additional field values given
    additional.save_values_for_link(dbo, post, nid, "foundanimal", True)

    return nid
示例#3
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))
示例#4
0
def insert_animalcontrol_from_form(dbo, post, username, geocode=True):
    """
    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 = dbo.insert(
        "animalcontrol", {
            "IncidentDateTime": post.datetime("incidentdate", "incidenttime"),
            "IncidentTypeID": post.integer("incidenttype"),
            "CallDateTime": post.datetime("calldate", "calltime"),
            "CallNotes": post["callnotes"],
            "CallTaker": post["calltaker"],
            "CallerID": post.integer("caller"),
            "VictimID": post.integer("victim"),
            "DispatchAddress": post["dispatchaddress"],
            "DispatchTown": post["dispatchtown"],
            "DispatchCounty": post["dispatchcounty"],
            "DispatchPostcode": post["dispatchpostcode"],
            "JurisdictionID": post.integer("jurisdiction"),
            "PickupLocationID": post.integer("pickuplocation"),
            "DispatchLatLong": post["dispatchlatlong"],
            "DispatchedACO": post["dispatchedaco"],
            "DispatchDateTime": post.datetime("dispatchdate", "dispatchtime"),
            "RespondedDateTime": post.datetime("respondeddate",
                                               "respondedtime"),
            "FollowupDateTime": post.datetime("followupdate", "followuptime"),
            "FollowupComplete": post.boolean("followupcomplete"),
            "FollowupDateTime2": post.datetime("followupdate2",
                                               "followuptime2"),
            "FollowupComplete2": post.boolean("followupcomplete2"),
            "FollowupDateTime3": post.datetime("followupdate3",
                                               "followuptime3"),
            "FollowupComplete3": post.boolean("followupcomplete3"),
            "CompletedDate": post.date("completeddate"),
            "IncidentCompletedID": post.integer("completedtype"),
            "SiteID": post.integer("site"),
            "OwnerID": post.integer("owner"),
            "Owner2ID": post.integer("owner2"),
            "Owner3ID": post.integer("owner3"),
            "AnimalDescription": post["animaldescription"],
            "SpeciesID": post.integer("species"),
            "Sex": post.integer("sex"),
            "AgeGroup": post["agegroup"]
        }, username)

    additional.save_values_for_link(dbo, post, nid, "incident", True)
    update_animalcontrol_roles(dbo, nid, post.integer_list("viewroles"),
                               post.integer_list("editroles"))

    # Look up a geocode for the dispatch address
    if geocode:
        update_dispatch_geocode(dbo, nid, "", post["dispatchaddress"],
                                post["dispatchtown"], post["dispatchcounty"],
                                post["dispatchpostcode"])

    return nid
示例#5
0
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_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))
示例#7
0
文件: waitinglist.py 项目: rutaq/asm3
def insert_waitinglist_from_form(dbo, post, username):
    """
    Creates a waiting list record from the screen
    data: The webpy data object containing form parameters
    """
    l = dbo.locale
    if post["description"] == "":
        raise utils.ASMValidationError(_("Description cannot be blank", l))
    if post.integer("owner") == 0:
        raise utils.ASMValidationError(
            _("Waiting list entries must have a contact", l))
    if post["dateputon"] == "":
        raise utils.ASMValidationError(_("Date put on cannot be blank", l))

    nwlid = dbo.insert(
        "animalwaitinglist", {
            "SpeciesID":
            post.integer("species"),
            "Size":
            post.integer("size"),
            "DatePutOnList":
            post.date("dateputon"),
            "OwnerID":
            post.integer("owner"),
            "AnimalDescription":
            post["description"],
            "ReasonForWantingToPart":
            post["reasonforwantingtopart"],
            "CanAffordDonation":
            post.boolean("canafforddonation"),
            "Urgency":
            post.integer("urgency"),
            "DateRemovedFromList":
            post.date("dateremoved"),
            "AutoRemovePolicy":
            post.integer("autoremovepolicy"),
            "DateOfLastOwnerContact":
            post.date("dateoflastownercontact"),
            "ReasonForRemoval":
            post["reasonforremoval"],
            "Comments":
            post["comments"],
            "UrgencyLastUpdatedDate":
            dbo.today(),
            "UrgencyUpdateDate":
            dbo.today(
                offset=configuration.waiting_list_urgency_update_period(dbo))
        }, username)

    # Save any additional field values given
    additional.save_values_for_link(dbo, post, nwlid, "waitinglist", True)

    return nwlid
示例#8
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))
示例#9
0
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
示例#10
0
文件: waitinglist.py 项目: rutaq/asm3
def update_waitinglist_from_form(dbo, post, username):
    """
    Updates a waiting list record from the screen
    data: The webpy data object containing form parameters
    """
    l = dbo.locale
    wlid = post.integer("id")

    if not dbo.optimistic_check("animalwaitinglist", post.integer("id"),
                                post.integer("recordversion")):
        raise utils.ASMValidationError(
            _("This record has been changed by another user, please reload.",
              l))

    if post["description"] == "":
        raise utils.ASMValidationError(_("Description cannot be blank", l))
    if post.integer("owner") == 0:
        raise utils.ASMValidationError(
            _("Waiting list entries must have a contact", l))
    if post["dateputon"] == "":
        raise utils.ASMValidationError(_("Date put on cannot be blank", l))

    dbo.update(
        "animalwaitinglist", wlid, {
            "SpeciesID": post.integer("species"),
            "Size": post.integer("size"),
            "DatePutOnList": post.date("dateputon"),
            "OwnerID": post.integer("owner"),
            "AnimalDescription": post["description"],
            "ReasonForWantingToPart": post["reasonforwantingtopart"],
            "CanAffordDonation": post.boolean("canafforddonation"),
            "Urgency": post.integer("urgency"),
            "DateRemovedFromList": post.date("dateremoved"),
            "AutoRemovePolicy": post.integer("autoremovepolicy"),
            "DateOfLastOwnerContact": post.date("dateoflastownercontact"),
            "ReasonForRemoval": post["reasonforremoval"],
            "Comments": post["comments"]
        }, username)

    additional.save_values_for_link(dbo, post, wlid, "waitinglist")
示例#11
0
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))
示例#12
0
文件: lostfound.py 项目: magul/asm3
def update_foundanimal_from_form(dbo, post, username):
    """
    Updates a found animal record from the screen
    post: The webpy data object containing form parameters
    """
    l = dbo.locale
    lfid = post.integer("id")

    if not db.check_recordversion(dbo, "animalfound", post.integer("id"), post.integer("recordversion")):
        raise utils.ASMValidationError(_("This record has been changed by another user, please reload.", l))

    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))

    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", 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"))
        )))
    additional.save_values_for_link(dbo, post, lfid, "foundanimal")
    postaudit = db.query(dbo, "SELECT * FROM animalfound WHERE ID = %d" % lfid)
    audit.edit(dbo, username, "animalfound", lfid, audit.map_diff(preaudit, postaudit))
def update_foundanimal_from_form(dbo, post, username):
    """
    Updates a found animal record from the screen
    post: The webpy data object containing form parameters
    """
    l = dbo.locale
    lfid = post.integer("id")
    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))

    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", 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")))))
    additional.save_values_for_link(dbo, post, lfid, "foundanimal")
    postaudit = db.query(dbo, "SELECT * FROM animalfound WHERE ID = %d" % lfid)
    audit.edit(dbo, username, "animalfound",
               audit.map_diff(preaudit, postaudit))
示例#14
0
文件: lostfound.py 项目: magul/asm3
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", nid, audit.dump_row(dbo, "animalfound", nid))

    # Save any additional field values given
    additional.save_values_for_link(dbo, post, nid, "foundanimal")

    return nid
示例#15
0
def update_person_from_form(dbo, data, username):
    """
    Updates an existing person record from incoming form data
    data: The webpy data object containing form parameters
    """
    l = dbo.locale
    pid = utils.df_ki(data, "id")
    flags = utils.df_ks(data, "flags").split(",")

    def bi(b):
        return b and 1 or 0

    homechecked = bi("homechecked" in flags)
    banned = bi("banned" in flags)
    volunteer = bi("volunteer" in flags)
    member = bi("member" in flags)
    homechecker = bi("homechecker" in flags)
    donor = bi("donor" in flags)
    shelter = bi("shelter" in flags)
    aco = bi("aco" in flags)
    staff = bi("staff" in flags)
    fosterer = bi("fosterer" in flags)
    retailer = bi("retailer" in flags)
    vet = bi("vet" in flags)
    giftaid = bi("giftaid" in flags)
    flagstr = "|".join(flags) + "|"
    sql = db.make_update_user_sql(
        dbo, "owner", username, "ID=%d" % pid,
        (("OwnerName",
          db.ds("%s %s %s" %
                (utils.df_ks(data, "title"), utils.df_ks(
                    data, "forenames"), utils.df_ks(data, "surname")))),
         ("OwnerTitle", utils.df_t(data, "title")),
         ("OwnerInitials", utils.df_t(data, "initials")),
         ("OwnerForenames", utils.df_t(data, "forenames")),
         ("OwnerSurname", utils.df_t(data, "surname")),
         ("OwnerAddress", utils.df_t(data, "address")),
         ("OwnerTown", utils.df_t(data, "town")),
         ("OwnerCounty", utils.df_t(data, "county")),
         ("OwnerPostcode", utils.df_t(data, "postcode")),
         ("LatLong", utils.df_t(data, "latlong")),
         ("HomeTelephone", utils.df_t(data, "hometelephone")),
         ("WorkTelephone", utils.df_t(data, "worktelephone")),
         ("MobileTelephone", utils.df_t(data, "mobiletelephone")),
         ("EmailAddress", utils.df_t(
             data, "email")), ("IDCheck", db.di(homechecked)),
         ("Comments", utils.df_t(data,
                                 "comments")), ("IsBanned", db.di(banned)),
         ("IsVolunteer", db.di(volunteer)), ("IsMember", db.di(member)),
         ("MembershipExpiryDate", utils.df_d(data, "membershipexpires", l)),
         ("MembershipNumber", utils.df_t(data, "membershipnumber")),
         ("IsHomeChecker", db.di(homechecker)), ("IsDonor", db.di(donor)),
         ("IsShelter", db.di(shelter)), ("IsACO", db.di(aco)),
         ("IsStaff", db.di(staff)), ("IsFosterer", db.di(fosterer)),
         ("IsRetailer", db.di(retailer)), ("IsVet", db.di(vet)),
         ("IsGiftAid", db.di(giftaid)), ("AdditionalFlags", db.ds(flagstr)),
         ("HomeCheckAreas", utils.df_t(data, "areas")),
         ("DateLastHomeChecked", utils.df_d(data, "homechecked", l)),
         ("HomeCheckedBy", utils.df_s(data, "homecheckedby")),
         ("MatchActive", utils.df_s(data, "matchactive")),
         ("MatchAdded", utils.df_d(data, "matchadded", l)),
         ("MatchExpires", utils.df_d(data, "matchexpires", l)),
         ("MatchSex", utils.df_s(
             data, "matchsex")), ("MatchSize", utils.df_s(data, "matchsize")),
         ("MatchColour", utils.df_s(data, "matchcolour")),
         ("MatchAgeFrom", utils.df_s(data, "agedfrom")),
         ("MatchAgeTo", utils.df_s(
             data, "agedto")), ("MatchAnimalType", utils.df_s(
                 data, "matchtype")), ("MatchSpecies",
                                       utils.df_s(data, "matchspecies")),
         ("MatchBreed", utils.df_s(
             data,
             "matchbreed1")), ("MatchBreed2", utils.df_s(data, "matchbreed2")),
         ("MatchGoodWithCats", utils.df_s(data, "matchgoodwithcats")),
         ("MatchGoodWithDogs", utils.df_s(data, "matchgoodwithdogs")),
         ("MatchGoodWithChildren", utils.df_s(data, "matchgoodwithchildren")),
         ("MatchHouseTrained", utils.df_s(data, "matchhousetrained")),
         ("MatchCommentsContain", utils.df_t(data, "commentscontain"))))
    preaudit = db.query(dbo, "SELECT * FROM owner WHERE ID=%d" % pid)
    db.execute(dbo, sql)
    postaudit = db.query(dbo, "SELECT * FROM owner WHERE ID=%d" % pid)
    audit.edit(dbo, username, "owner",
               audit.map_diff(preaudit, postaudit, [
                   "OWNERNAME",
               ]))

    # Save any additional field values given
    additional.save_values_for_link(dbo, data, pid, "person")
示例#16
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 dbo.optimistic_check("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))

    dbo.update(
        "animalcontrol", acid, {
            "IncidentDateTime": post.datetime("incidentdate", "incidenttime"),
            "IncidentTypeID": post.integer("incidenttype"),
            "CallDateTime": post.datetime("calldate", "calltime"),
            "CallNotes": post["callnotes"],
            "CallTaker": post["calltaker"],
            "CallerID": post.integer("caller"),
            "VictimID": post.integer("victim"),
            "DispatchAddress": post["dispatchaddress"],
            "DispatchTown": post["dispatchtown"],
            "DispatchCounty": post["dispatchcounty"],
            "DispatchPostcode": post["dispatchpostcode"],
            "JurisdictionID": post.integer("jurisdiction"),
            "PickupLocationID": post.integer("pickuplocation"),
            "DispatchLatLong": post["dispatchlatlong"],
            "DispatchedACO": post["dispatchedaco"],
            "DispatchDateTime": post.datetime("dispatchdate", "dispatchtime"),
            "RespondedDateTime": post.datetime("respondeddate",
                                               "respondedtime"),
            "FollowupDateTime": post.datetime("followupdate", "followuptime"),
            "FollowupComplete": post.boolean("followupcomplete"),
            "FollowupDateTime2": post.datetime("followupdate2",
                                               "followuptime2"),
            "FollowupComplete2": post.boolean("followupcomplete2"),
            "FollowupDateTime3": post.datetime("followupdate3",
                                               "followuptime3"),
            "FollowupComplete3": post.boolean("followupcomplete3"),
            "CompletedDate": post.date("completeddate"),
            "IncidentCompletedID": post.integer("completedtype"),
            "SiteID": post.integer("site"),
            "OwnerID": post.integer("owner"),
            "Owner2ID": post.integer("owner2"),
            "Owner3ID": post.integer("owner3"),
            "AnimalDescription": post["animaldescription"],
            "SpeciesID": post.integer("species"),
            "Sex": post.integer("sex"),
            "AgeGroup": post["agegroup"]
        }, username)

    additional.save_values_for_link(dbo, post, acid, "incident")
    update_animalcontrol_roles(dbo, acid, post.integer_list("viewroles"),
                               post.integer_list("editroles"))

    # Check/update the geocode for the dispatch address
    update_dispatch_geocode(dbo, acid, post["dispatchlatlong"],
                            post["dispatchaddress"], post["dispatchtown"],
                            post["dispatchcounty"], post["dispatchpostcode"])
示例#17
0
 def test_save_values_for_link(self):
     additional.save_values_for_link(base.get_dbo(),
                                     utils.PostedData({}, "en"), 0,
                                     "animal")
示例#18
0
def update_person_from_form(dbo, data, username):
    """
    Updates an existing person record from incoming form data
    data: The webpy data object containing form parameters
    """
    l = dbo.locale
    pid = utils.df_ki(data, "id")
    flags = utils.df_ks(data, "flags").split(",")
    def bi(b): return b and 1 or 0
    homechecked = bi("homechecked" in flags)
    banned = bi("banned" in flags)
    volunteer = bi("volunteer" in flags)
    member = bi("member" in flags)
    homechecker = bi("homechecker" in flags)
    donor = bi("donor" in flags)
    shelter = bi("shelter" in flags)
    aco = bi("aco" in flags)
    staff = bi("staff" in flags)
    fosterer = bi("fosterer" in flags)
    retailer = bi("retailer" in flags)
    vet = bi("vet" in flags)
    giftaid = bi("giftaid" in flags)
    flagstr = "|".join(flags) + "|"
    sql = db.make_update_user_sql(dbo, "owner", username, "ID=%d" % pid, (
        ( "OwnerName", db.ds("%s %s %s" % ( utils.df_ks(data, "title"), utils.df_ks(data, "forenames"), utils.df_ks(data, "surname") ))),
        ( "OwnerTitle", utils.df_t(data, "title")),
        ( "OwnerInitials", utils.df_t(data, "initials")),
        ( "OwnerForenames", utils.df_t(data, "forenames")), 
        ( "OwnerSurname", utils.df_t(data, "surname")),
        ( "OwnerAddress", utils.df_t(data, "address")),
        ( "OwnerTown", utils.df_t(data, "town")),
        ( "OwnerCounty", utils.df_t(data, "county")),
        ( "OwnerPostcode", utils.df_t(data, "postcode")),
        ( "LatLong", utils.df_t(data, "latlong")),
        ( "HomeTelephone", utils.df_t(data, "hometelephone")),
        ( "WorkTelephone", utils.df_t(data, "worktelephone")),
        ( "MobileTelephone", utils.df_t(data, "mobiletelephone")),
        ( "EmailAddress", utils.df_t(data, "email")),
        ( "IDCheck", db.di(homechecked) ),
        ( "Comments", utils.df_t(data, "comments")),
        ( "IsBanned", db.di(banned)),
        ( "IsVolunteer", db.di(volunteer)),
        ( "IsMember", db.di(member)),
        ( "MembershipExpiryDate", utils.df_d(data, "membershipexpires", l)),
        ( "MembershipNumber", utils.df_t(data, "membershipnumber")),
        ( "IsHomeChecker", db.di(homechecker)),
        ( "IsDonor", db.di(donor)),
        ( "IsShelter", db.di(shelter)),
        ( "IsACO", db.di(aco)),
        ( "IsStaff", db.di(staff)),
        ( "IsFosterer", db.di(fosterer)),
        ( "IsRetailer", db.di(retailer)),
        ( "IsVet", db.di(vet)),
        ( "IsGiftAid", db.di(giftaid)),
        ( "AdditionalFlags", db.ds(flagstr)),
        ( "HomeCheckAreas", utils.df_t(data, "areas")),
        ( "DateLastHomeChecked", utils.df_d(data, "homechecked", l)),
        ( "HomeCheckedBy", utils.df_s(data, "homecheckedby")),
        ( "MatchActive", utils.df_s(data, "matchactive")),
        ( "MatchAdded", utils.df_d(data, "matchadded", l)),
        ( "MatchExpires", utils.df_d(data, "matchexpires", l)),
        ( "MatchSex", utils.df_s(data, "matchsex")),
        ( "MatchSize", utils.df_s(data, "matchsize")),
        ( "MatchColour", utils.df_s(data, "matchcolour")),
        ( "MatchAgeFrom", utils.df_s(data, "agedfrom")),
        ( "MatchAgeTo", utils.df_s(data, "agedto")),
        ( "MatchAnimalType", utils.df_s(data, "matchtype")),
        ( "MatchSpecies", utils.df_s(data, "matchspecies")),
        ( "MatchBreed", utils.df_s(data, "matchbreed1")),
        ( "MatchBreed2", utils.df_s(data, "matchbreed2")),
        ( "MatchGoodWithCats", utils.df_s(data, "matchgoodwithcats")),
        ( "MatchGoodWithDogs", utils.df_s(data, "matchgoodwithdogs")),
        ( "MatchGoodWithChildren", utils.df_s(data, "matchgoodwithchildren")),
        ( "MatchHouseTrained", utils.df_s(data, "matchhousetrained")),
        ( "MatchCommentsContain", utils.df_t(data, "commentscontain"))
    ))
    preaudit = db.query(dbo, "SELECT * FROM owner WHERE ID=%d" % pid)
    db.execute(dbo, sql)
    postaudit = db.query(dbo, "SELECT * FROM owner WHERE ID=%d" % pid)
    audit.edit(dbo, username, "owner", audit.map_diff(preaudit, postaudit, [ "OWNERNAME", ]))

    # Save any additional field values given
    additional.save_values_for_link(dbo, data, pid, "person")
示例#19
0
 def test_save_values_for_link(self):
     additional.save_values_for_link(base.get_dbo(), utils.PostedData({}, "en"), 0, "animal")