예제 #1
0
def delete_person(dbo, username, personid):
    """
    Deletes a person and all its satellite records.
    """
    l = dbo.locale
    if db.query_int(dbo, "SELECT COUNT(ID) FROM adoption WHERE OwnerID=%d OR RetailerID=%d" % (personid, personid)):
        raise utils.ASMValidationError(_("This person has movements and cannot be removed.", l))
    if db.query_int(dbo, "SELECT COUNT(ID) FROM animal WHERE BroughtInByOwnerID=%d OR OriginalOwnerID=%d OR CurrentVetID=%d OR OwnersVetID=%d" % (personid, personid, personid, personid)):
        raise utils.ASMValidationError(_("This person is linked to an animal and cannot be removed.", l))
    if db.query_int(dbo, "SELECT COUNT(ID) FROM ownerdonation WHERE OwnerID=%d" % personid):
        raise utils.ASMValidationError(_("This person has donations and cannot be removed.", l))
    animals = db.query(dbo, "SELECT AnimalID FROM adoption WHERE OwnerID = %d" % personid)
    audit.delete(dbo, username, "owner", str(db.query(dbo, "SELECT * FROM owner WHERE ID=%d" % personid)))
    db.execute(dbo, "DELETE FROM media WHERE LinkID = %d AND LinkTypeID = %d" % (personid, 1))
    db.execute(dbo, "DELETE FROM diary WHERE LinkID = %d AND LinkType = %d" % (personid, 2))
    db.execute(dbo, "DELETE FROM log WHERE LinkID = %d AND LinkType = %d" % (personid, 1))
    db.execute(dbo, "DELETE FROM additional WHERE LinkID = %d AND LinkType IN (%s)" % (personid, additional.PERSON_IN))
    db.execute(dbo, "DELETE FROM adoption WHERE OwnerID = %d" % personid)
    db.execute(dbo, "DELETE FROM ownerdonation WHERE OwnerID = %d" % personid)
    db.execute(dbo, "DELETE FROM ownervoucher WHERE OwnerID = %d" % personid)
    dbfs.delete_path(dbo, "/owner/%d" % personid)
    db.execute(dbo, "DELETE FROM owner WHERE ID = %d" % personid)
    # Now that we've removed the person, update any animals that were previously
    # attached to it so that they return to the shelter.
    for a in animals:
        animal.update_animal_status(dbo, int(a["ANIMALID"]))
        animal.update_variable_animal_data(dbo, int(a["ANIMALID"]))
예제 #2
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)
예제 #3
0
파일: movement.py 프로젝트: tgage/asm3
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")

    dbo.update("adoption", movementid, {
        "AdoptionNumber":               post["adoptionno"],
        "OwnerID":                      post.integer("person"),
        "RetailerID":                   post.integer("retailer"),
        "AnimalID":                     post.integer("animal"),
        "OriginalRetailerMovementID":   post.integer("originalretailermovement"),
        "MovementDate":                 post.date("movementdate"),
        "MovementType":                 post.integer("type"),
        "ReturnDate":                   post.date("returndate"),
        "ReturnedReasonID":             post.integer("returncategory"),
        "Donation":                     post.integer("donation"),
        "InsuranceNumber":              post["insurance"],
        "ReasonForReturn":              post["reason"],
        "ReturnedByOwnerID":            post.integer("returnedby"),
        "ReservationDate":              post.date("reservationdate"),
        "ReservationCancelledDate":     post.date("reservationcancelled"),
        "ReservationStatusID":          post.integer("reservationstatus"),
        "IsTrial":                      post.boolean("trial"),
        "IsPermanentFoster":            post.boolean("permanentfoster"),
        "TrialEndDate":                 post.date("trialenddate"),
        "Comments":                     post["comments"]
    }, username)

    animal.update_animal_status(dbo, post.integer("animal"))
    animal.update_variable_animal_data(dbo, post.integer("animal"))
    update_movement_donation(dbo, movementid)
예제 #4
0
파일: movement.py 프로젝트: magul/asm3
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)
예제 #5
0
파일: movement.py 프로젝트: tgage/asm3
def delete_movement(dbo, username, mid):
    """
    Deletes a movement record
    """
    animalid = dbo.query_int("SELECT AnimalID FROM adoption WHERE ID = ?", [mid])
    if animalid == 0:
        raise utils.ASMError("Trying to delete a movement that does not exist")
    dbo.execute("UPDATE ownerdonation SET MovementID = 0 WHERE MovementID = ?", [mid])
    dbo.delete("adoption", mid, username)
    animal.update_animal_status(dbo, animalid)
    animal.update_variable_animal_data(dbo, animalid)
예제 #6
0
def delete_movement(dbo, username, mid):
    """
    Deletes a movement record
    """
    animalid = db.query_int(dbo, "SELECT AnimalID FROM adoption WHERE ID = %d" % int(mid))
    if animalid == 0:
        raise utils.ASMError("Trying to delete a movement that does not exist")
    db.execute(dbo, "UPDATE ownerdonation SET MovementID = 0 WHERE MovementID = %d" % int(mid))
    audit.delete(dbo, username, "adoption", str(db.query(dbo, "SELECT * FROM adoption WHERE ID=%d" % int(mid))))
    db.execute(dbo, "DELETE FROM adoption WHERE ID = %d" % int(mid))
    animal.update_animal_status(dbo, animalid)
    animal.update_variable_animal_data(dbo, animalid)
예제 #7
0
def insert_movement_from_form(dbo, username, data):
    """
    Creates a movement record from posted form data 
    """
    movementid = db.get_id(dbo, "adoption")
    adoptionno = utils.df_ks(data, "adoptionno")
    animalid = utils.df_ki(data, "animal")
    if adoptionno == "":
        # No adoption number was supplied, generate a
        # unique number from the movementid
        idx = movementid
        while True:
            adoptionno = utils.padleft(idx, 6)
            data["adoptionno"] = adoptionno
            if 0 == db.query_int(
                    dbo,
                    "SELECT COUNT(*) FROM adoption WHERE AdoptionNumber LIKE '%s'"
                    % adoptionno):
                break
            else:
                idx += 1

    validate_movement_form_data(dbo, data)
    l = dbo.locale
    sql = db.make_insert_user_sql(
        dbo, "adoption", username,
        (("ID", db.di(movementid)), ("AdoptionNumber", db.ds(adoptionno)),
         ("OwnerID", db.di(utils.df_ki(data, "person"))),
         ("RetailerID", db.di(utils.df_ki(data, "retailer"))),
         ("AnimalID", db.di(utils.df_ki(data, "animal"))),
         ("OriginalRetailerMovementID",
          db.di(utils.df_ki(data, "originalretailermovement"))),
         ("MovementDate", utils.df_d(data, "movementdate", l)),
         ("MovementType", utils.df_s(data, "type")),
         ("ReturnDate", utils.df_d(data, "returndate", l)),
         ("ReturnedReasonID", utils.df_s(data, "returncategory")),
         ("Donation", utils.df_m(data, "donation", l)),
         ("InsuranceNumber", utils.df_t(data, "insurance")),
         ("ReasonForReturn", utils.df_t(data, "reason")),
         ("ReservationDate", utils.df_d(data, "reservationdate", l)),
         ("ReservationCancelledDate",
          utils.df_d(data, "reservationcancelled",
                     l)), ("IsTrial", utils.df_c(data, "trial")),
         ("IsPermanentFoster", utils.df_c(data, "permanentfoster")),
         ("TrialEndDate", utils.df_d(data, "trialenddate", l)),
         ("Comments", utils.df_t(data, "comments"))))
    db.execute(dbo, sql)
    audit.create(dbo, username, "adoption", str(movementid))
    animal.update_animal_status(dbo, animalid)
    animal.update_variable_animal_data(dbo, animalid)
    update_movement_donation(dbo, movementid)
    return movementid
예제 #8
0
파일: movement.py 프로젝트: tgage/asm3
def insert_movement_from_form(dbo, username, post):
    """
    Creates a movement record from posted form data 
    """
    movementid = dbo.get_id("adoption")
    adoptionno = post["adoptionno"]
    animalid = post.integer("animal")

    if adoptionno == "": 
        # No adoption number was supplied, generate a
        # unique number from the movementid
        idx = movementid
        while True:
            adoptionno = utils.padleft(idx, 6)
            post.data["adoptionno"] = adoptionno
            if 0 == dbo.query_int("SELECT COUNT(*) FROM adoption WHERE AdoptionNumber LIKE ?", [adoptionno]):
                break
            else:
                idx += 1

    validate_movement_form_data(dbo, post)

    dbo.insert("adoption", {
        "ID":                           movementid,
        "AdoptionNumber":               adoptionno,
        "OwnerID":                      post.integer("person"),
        "RetailerID":                   post.integer("retailer"),
        "AnimalID":                     post.integer("animal"),
        "OriginalRetailerMovementID":   post.integer("originalretailermovement"),
        "MovementDate":                 post.date("movementdate"),
        "MovementType":                 post.integer("type"),
        "ReturnDate":                   post.date("returndate"),
        "ReturnedReasonID":             post.integer("returncategory"),
        "Donation":                     post.integer("donation"),
        "InsuranceNumber":              post["insurance"],
        "ReasonForReturn":              post["reason"],
        "ReturnedByOwnerID":            post.integer("returnedby"),
        "ReservationDate":              post.date("reservationdate"),
        "ReservationCancelledDate":     post.date("reservationcancelled"),
        "ReservationStatusID":          post.integer("reservationstatus"),
        "IsTrial":                      post.boolean("trial"),
        "IsPermanentFoster":            post.boolean("permanentfoster"),
        "TrialEndDate":                 post.date("trialenddate"),
        "Comments":                     post["comments"]
    }, username, generateID=False)

    animal.update_animal_status(dbo, animalid)
    animal.update_variable_animal_data(dbo, animalid)
    update_movement_donation(dbo, movementid)

    return movementid
예제 #9
0
def delete_person(dbo, username, personid):
    """
    Deletes a person and all its satellite records.
    """
    l = dbo.locale
    if db.query_int(
            dbo,
            "SELECT COUNT(ID) FROM adoption WHERE OwnerID=%d OR RetailerID=%d"
            % (personid, personid)):
        raise utils.ASMValidationError(
            _("This person has movements and cannot be removed.", l))
    if db.query_int(
            dbo,
            "SELECT COUNT(ID) FROM animal WHERE BroughtInByOwnerID=%d OR OriginalOwnerID=%d OR CurrentVetID=%d OR OwnersVetID=%d"
            % (personid, personid, personid, personid)):
        raise utils.ASMValidationError(
            _("This person is linked to an animal and cannot be removed.", l))
    if db.query_int(
            dbo,
            "SELECT COUNT(ID) FROM ownerdonation WHERE OwnerID=%d" % personid):
        raise utils.ASMValidationError(
            _("This person has donations and cannot be removed.", l))
    animals = db.query(
        dbo, "SELECT AnimalID FROM adoption WHERE OwnerID = %d" % personid)
    audit.delete(
        dbo, username, "owner",
        str(db.query(dbo, "SELECT * FROM owner WHERE ID=%d" % personid)))
    db.execute(
        dbo, "DELETE FROM media WHERE LinkID = %d AND LinkTypeID = %d" %
        (personid, 1))
    db.execute(
        dbo, "DELETE FROM diary WHERE LinkID = %d AND LinkType = %d" %
        (personid, 2))
    db.execute(
        dbo,
        "DELETE FROM log WHERE LinkID = %d AND LinkType = %d" % (personid, 1))
    db.execute(
        dbo, "DELETE FROM additional WHERE LinkID = %d AND LinkType IN (%s)" %
        (personid, additional.PERSON_IN))
    db.execute(dbo, "DELETE FROM adoption WHERE OwnerID = %d" % personid)
    db.execute(dbo, "DELETE FROM ownerdonation WHERE OwnerID = %d" % personid)
    db.execute(dbo, "DELETE FROM ownervoucher WHERE OwnerID = %d" % personid)
    dbfs.delete_path(dbo, "/owner/%d" % personid)
    db.execute(dbo, "DELETE FROM owner WHERE ID = %d" % personid)
    # Now that we've removed the person, update any animals that were previously
    # attached to it so that they return to the shelter.
    for a in animals:
        animal.update_animal_status(dbo, int(a["ANIMALID"]))
        animal.update_variable_animal_data(dbo, int(a["ANIMALID"]))
예제 #10
0
def insert_movement_from_form(dbo, username, data):
    """
    Creates a movement record from posted form data 
    """
    movementid = db.get_id(dbo, "adoption")
    adoptionno = utils.df_ks(data, "adoptionno")
    animalid = utils.df_ki(data, "animal")
    if adoptionno == "": 
        # No adoption number was supplied, generate a
        # unique number from the movementid
        idx = movementid
        while True:
            adoptionno = utils.padleft(idx, 6)
            data["adoptionno"] = adoptionno
            if 0 == db.query_int(dbo, "SELECT COUNT(*) FROM adoption WHERE AdoptionNumber LIKE '%s'" % adoptionno):
                break
            else:
                idx += 1

    validate_movement_form_data(dbo, data)
    l = dbo.locale
    sql = db.make_insert_user_sql(dbo, "adoption", username, ( 
        ( "ID", db.di(movementid)),
        ( "AdoptionNumber", db.ds(adoptionno)),
        ( "OwnerID", db.di(utils.df_ki(data, "person"))),
        ( "RetailerID", db.di(utils.df_ki(data, "retailer"))),
        ( "AnimalID", db.di(utils.df_ki(data, "animal"))),
        ( "OriginalRetailerMovementID", db.di(utils.df_ki(data, "originalretailermovement"))),
        ( "MovementDate", utils.df_d(data, "movementdate", l)),
        ( "MovementType", utils.df_s(data, "type")),
        ( "ReturnDate", utils.df_d(data, "returndate", l)),
        ( "ReturnedReasonID", utils.df_s(data, "returncategory")),
        ( "Donation", utils.df_m(data, "donation", l)),
        ( "InsuranceNumber", utils.df_t(data, "insurance")),
        ( "ReasonForReturn", utils.df_t(data, "reason")),
        ( "ReservationDate", utils.df_d(data, "reservationdate", l)),
        ( "ReservationCancelledDate", utils.df_d(data, "reservationcancelled", l)),
        ( "IsTrial", utils.df_c(data, "trial")),
        ( "IsPermanentFoster", utils.df_c(data, "permanentfoster")),
        ( "TrialEndDate", utils.df_d(data, "trialenddate", l)),
        ( "Comments", utils.df_t(data, "comments"))
        ))
    db.execute(dbo, sql)
    audit.create(dbo, username, "adoption", str(movementid))
    animal.update_animal_status(dbo, animalid)
    animal.update_variable_animal_data(dbo, animalid)
    update_movement_donation(dbo, movementid)
    return movementid
예제 #11
0
def delete_movement(dbo, username, mid):
    """
    Deletes a movement record
    """
    animalid = db.query_int(
        dbo, "SELECT AnimalID FROM adoption WHERE ID = %d" % int(mid))
    if animalid == 0:
        raise utils.ASMError("Trying to delete a movement that does not exist")
    db.execute(
        dbo, "UPDATE ownerdonation SET MovementID = 0 WHERE MovementID = %d" %
        int(mid))
    audit.delete(
        dbo, username, "adoption",
        str(db.query(dbo, "SELECT * FROM adoption WHERE ID=%d" % int(mid))))
    db.execute(dbo, "DELETE FROM adoption WHERE ID = %d" % int(mid))
    animal.update_animal_status(dbo, animalid)
    animal.update_variable_animal_data(dbo, animalid)
예제 #12
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)