示例#1
0
def merge_person(dbo, username, personid, mergepersonid):
    """
    Reparents all satellite records of mergepersonid onto
    personid and then deletes it.
    """
    l = dbo.locale
    if personid == mergepersonid:
        raise utils.ASMValidationError(_("The person record to merge must be different from the original.", l))
    if personid == 0 or mergepersonid == 0:
        raise utils.ASMValidationError("Internal error: Cannot merge ID 0")
    def reparent(table, field, linktypefield = "", linktype = -1):
        if linktype >= 0:
            db.execute(dbo, "UPDATE %s SET %s = %d WHERE %s = %d AND %s = %d" % (table, field, personid, field, mergepersonid, linktypefield, linktype))
        else:
            db.execute(dbo, "UPDATE %s SET %s = %d WHERE %s = %d" % (table, field, personid, field, mergepersonid))
    reparent("adoption", "OwnerID")
    reparent("adoption", "RetailerID")
    reparent("animal", "OriginalOwnerID")
    reparent("animal", "BroughtInByOwnerID")
    reparent("animal", "OwnersVetID")
    reparent("animal", "CurrentVetID")
    reparent("animallost", "OwnerID")
    reparent("animalfound", "OwnerID")
    reparent("animalwaitinglist", "OwnerID")
    reparent("ownerdonation", "OwnerID")
    reparent("ownervoucher", "OwnerID")
    reparent("users", "OwnerID")
    reparent("media", "LinkID", "LinkTypeID", media.PERSON)
    reparent("diary", "LinkID", "LinkType", diary.PERSON)
    reparent("log", "LinkID", "LinkType", log.PERSON)
    audit.delete(dbo, username, "owner", str(db.query(dbo, "SELECT * FROM owner WHERE ID=%d" % mergepersonid)))
    db.execute(dbo, "DELETE FROM owner WHERE ID = %d" % mergepersonid)
示例#2
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"]))
示例#3
0
def delete_user(dbo, username, uid):
    """
    Deletes the selected user
    """
    audit.delete(dbo, username, "users", str(db.query(dbo, "SELECT * FROM users WHERE ID=%d" % int(uid))))
    db.execute(dbo, "DELETE FROM users WHERE ID = %d" % int(uid))
    db.execute(dbo, "DELETE FROM userrole WHERE UserID = %d" % int(uid))
示例#4
0
def delete_onlineform(dbo, username, formid):
    """
    Deletes the specified onlineform and fields
    """
    audit.delete(dbo, username, "onlineform", str(db.query(dbo, "SELECT * FROM onlineform WHERE ID=%d" % int(formid))))
    db.execute(dbo, "DELETE FROM onlineformfield WHERE OnlineFormID = %d" % int(formid))
    db.execute(dbo, "DELETE FROM onlineform WHERE ID = %d" % int(formid))
示例#5
0
def delete_media(dbo, username, mid):
    """
    Deletes a media record from the system
    """
    mr = db.query(dbo, "SELECT * FROM media WHERE ID=%d" % int(mid))
    if len(mr) == 0: return
    mr = mr[0]
    mn = mr["MEDIANAME"]
    audit.delete(dbo, username, "media", str(mr))
    dbfs.delete(dbo, mn)
    db.execute(dbo, "DELETE FROM media WHERE ID = %d" % int(mid))
    # Was it the web or doc preferred? If so, make the first image for the link
    # the web or doc preferred instead
    if mr["WEBSITEPHOTO"] == 1:
        ml = db.query(dbo, "SELECT * FROM media WHERE LinkID=%d AND LinkTypeID=%d " \
            "AND (LOWER(MediaName) LIKE '%%.jpg' OR LOWER(MediaName) LIKE '%%.jpeg') " \
            "ORDER BY ID" % ( mr["LINKID"], mr["LINKTYPEID"] ))
        if len(ml) > 0:
            db.execute(
                dbo, "UPDATE media SET WebsitePhoto = 1 WHERE ID = %d" %
                ml[0]["ID"])
    if mr["DOCPHOTO"] == 1:
        ml = db.query(dbo, "SELECT * FROM media WHERE LinkID=%d AND LinkTypeID=%d " \
            "AND (LOWER(MediaName) LIKE '%%.jpg' OR LOWER(MediaName) LIKE '%%.jpeg') " \
            "ORDER BY ID" % ( mr["LINKID"], mr["LINKTYPEID"] ))
        if len(ml) > 0:
            db.execute(
                dbo,
                "UPDATE media SET DocPhoto = 1 WHERE ID = %d" % ml[0]["ID"])
示例#6
0
def delete_document_template(dbo, username, dtid):
    """
    Deletes a document template
    """
    name = get_document_template_name(dbo, dtid)
    dbo.delete("templatedocument", dtid, username, writeAudit=False)
    audit.delete(dbo, username, "templatedocument", dtid, "", "delete template %d (%s)" % (dtid, name))
示例#7
0
def delete_onlineform(dbo, username, formid):
    """
    Deletes the specified onlineform and fields
    """
    audit.delete(dbo, username, "onlineform", str(db.query(dbo, "SELECT * FROM onlineform WHERE ID=%d" % int(formid))))
    db.execute(dbo, "DELETE FROM onlineformfield WHERE OnlineFormID = %d" % int(formid))
    db.execute(dbo, "DELETE FROM onlineform WHERE ID = %d" % int(formid))
示例#8
0
文件: users.py 项目: magul/asm3
def delete_user(dbo, username, uid):
    """
    Deletes the selected user
    """
    audit.delete(dbo, username, "users", uid, audit.dump_row(dbo, "users", uid))
    db.execute(dbo, "DELETE FROM users WHERE ID = %d" % int(uid))
    db.execute(dbo, "DELETE FROM userrole WHERE UserID = %d" % int(uid))
示例#9
0
def delete_diarytask(dbo, username, taskid):
    """
    Deletes a diary task
    """
    audit.delete(dbo, username, "diarytaskhead", str(db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID = %d" % int(taskid))))
    db.execute(dbo, "DELETE FROM diarytaskdetail WHERE DiaryTaskHeadID = %d" % int(taskid))
    db.execute(dbo, "DELETE FROM diarytaskhead WHERE ID = %d" % int(taskid))
示例#10
0
文件: additional.py 项目: magul/asm3
def delete_field(dbo, username, fid):
    """
    Deletes the selected additional field, along with all data held by it.
    """
    audit.delete(dbo, username, "additionalfield", fid, audit.dump_row(dbo, "additionalfield", fid))
    db.execute(dbo, "DELETE FROM additionalfield WHERE ID = %d" % int(fid))
    db.execute(dbo, "DELETE FROM additional WHERE AdditionalFieldID = %d" % int(fid))
示例#11
0
文件: stock.py 项目: magul/asm3
def delete_stocklevel(dbo, username, slid):
    """
    Deletes a stocklevel record
    """
    audit.delete(dbo, username, "stocklevel", slid, audit.dump_row(dbo, "stocklevel", slid))
    db.execute(dbo, "DELETE FROM stockusage WHERE StockLevelID = %d" % slid)
    db.execute(dbo, "DELETE FROM stocklevel WHERE ID = %d" % slid)
示例#12
0
文件: diary.py 项目: magul/asm3
def delete_diarytask(dbo, username, taskid):
    """
    Deletes a diary task
    """
    audit.delete(dbo, username, "diarytaskhead", taskid, audit.dump_row(dbo, "diarytaskhead", taskid))
    db.execute(dbo, "DELETE FROM diarytaskdetail WHERE DiaryTaskHeadID = %d" % int(taskid))
    db.execute(dbo, "DELETE FROM diarytaskhead WHERE ID = %d" % int(taskid))
示例#13
0
def delete_regimen(dbo, username, amid):
    """
    Deletes a regimen
    """
    audit.delete(dbo, username, "animalmedical", str(db.query(dbo, "SELECT * FROM animalmedical WHERE ID = %d" % int(amid))))
    db.execute(dbo, "DELETE FROM animalmedicaltreatment WHERE AnimalMedicalID = %d" % amid)
    db.execute(dbo, "DELETE FROM animalmedical WHERE ID = %d" % amid)
示例#14
0
def delete_media(dbo, username, mid):
    """
    Deletes a media record from the system
    """
    mr = db.query(dbo, "SELECT * FROM media WHERE ID=%d" % int(mid))
    if len(mr) == 0: return
    mr = mr[0]
    mn = mr["MEDIANAME"]
    audit.delete(dbo, username, "media", str(mr))
    dbfs.delete(dbo, mn)
    db.execute(dbo, "DELETE FROM media WHERE ID = %d" % int(mid))
    # Was it the web or doc preferred? If so, make the first image for the link
    # the web or doc preferred instead
    if mr["WEBSITEPHOTO"] == 1:
        ml = db.query(dbo, "SELECT * FROM media WHERE LinkID=%d AND LinkTypeID=%d " \
            "AND (LOWER(MediaName) LIKE '%%.jpg' OR LOWER(MediaName) LIKE '%%.jpeg') " \
            "ORDER BY ID" % ( mr["LINKID"], mr["LINKTYPEID"] ))
        if len(ml) > 0:
            db.execute(dbo, "UPDATE media SET WebsitePhoto = 1 WHERE ID = %d" % ml[0]["ID"])
    if mr["DOCPHOTO"] == 1:
        ml = db.query(dbo, "SELECT * FROM media WHERE LinkID=%d AND LinkTypeID=%d " \
            "AND (LOWER(MediaName) LIKE '%%.jpg' OR LOWER(MediaName) LIKE '%%.jpeg') " \
            "ORDER BY ID" % ( mr["LINKID"], mr["LINKTYPEID"] ))
        if len(ml) > 0:
            db.execute(dbo, "UPDATE media SET DocPhoto = 1 WHERE ID = %d" % ml[0]["ID"])
示例#15
0
def delete_log(dbo, username, logid):
    """
    Deletes a log
    """
    audit.delete(
        dbo, username, "log",
        str(db.query(dbo, "SELECT * FROM log WHERE ID = %d" % int(logid))))
    db.execute(dbo, "DELETE FROM log WHERE ID = %d" % int(logid))
def delete_foundanimal(dbo, username, aid):
    """
    Deletes a found animal
    """
    audit.delete(
        dbo, username, "animalfound",
        str(db.query(dbo, "SELECT * FROM animalfound WHERE ID=%d" % aid)))
    db.execute(dbo, "DELETE FROM animalfound WHERE ID = %d" % aid)
def delete_animalcontrol(dbo, username, acid):
    """
    Deletes an animal control record
    """
    audit.delete(
        dbo, username, "animalcontrol",
        str(db.query(dbo, "SELECT * FROM animalcontrol WHERE ID=%d" % acid)))
    db.execute(dbo, "DELETE FROM animalcontrol WHERE ID = %d" % acid)
示例#18
0
def delete_account(dbo, username, aid):
    """
    Deletes an account
    """
    audit.delete(dbo, username, "accounts", str(db.query(dbo, "SELECT * FROM accounts WHERE ID=%d" % int(aid))))
    db.execute(dbo, "DELETE FROM accountstrx WHERE SourceAccountID = %d OR DestinationAccountID = %d" % ( int(aid), int(aid) ))
    db.execute(dbo, "DELETE FROM accountsrole WHERE AccountID = %d" % int(aid))
    db.execute(dbo, "DELETE FROM accounts WHERE ID = %d" % int(aid))
示例#19
0
def delete_diary(dbo, username, diaryid):
    """
    Deletes a diary record
    """
    audit.delete(
        dbo, username, "diary",
        str(db.query(dbo, "SELECT * FROM diary WHERE ID = %d" % int(diaryid))))
    db.execute(dbo, "DELETE FROM diary WHERE ID = %d" % int(diaryid))
def delete_lostanimal(dbo, username, aid):
    """
    Deletes a lost animal
    """
    audit.delete(
        dbo, username, "animallost",
        str(db.query(dbo, "SELECT * FROM animallost WHERE ID=%d" % aid)))
    db.execute(dbo, "DELETE FROM animallost WHERE ID = %d" % aid)
示例#21
0
def delete_trx(dbo, username, tid):
    """
    Deletes a transaction
    """
    audit.delete(
        dbo, username, "accountstrx",
        str(db.query(dbo, "SELECT * FROM accountstrx WHERE ID=%d" % int(tid))))
    db.execute(dbo, "DELETE FROM accountstrx WHERE ID = %d" % int(tid))
示例#22
0
def delete_treatment(dbo, username, amtid):
    """
    Deletes a treatment record
    """
    audit.delete(dbo, username, "animalmedicaltreatment", str(db.query(dbo, "SELECT * FROM animalmedicaltreatment WHERE ID = %d" % int(amtid))))
    amid = db.query_int(dbo, "SELECT AnimalMedicalID FROM animalmedicaltreatment WHERE ID = %d" % int(amtid))
    db.execute(dbo, "DELETE FROM animalmedicaltreatment WHERE ID = %d" % amtid)
    calculate_given_remaining(dbo, amid)
    update_medical_treatments(dbo, username, amid)
def delete_traploan(dbo, username, tid):
    """
    Deletes a traploan record
    """
    audit.delete(
        dbo, username, "ownertraploan",
        str(db.query(dbo,
                     "SELECT * FROM ownertraploan WHERE ID=%d" % int(tid))))
    db.execute(dbo, "DELETE FROM ownertraploan WHERE ID = %d" % int(tid))
示例#24
0
文件: movement.py 项目: magul/asm3
def delete_transport(dbo, username, tid):
    """
    Deletes a transport record
    """
    animalid = db.query_int(dbo, "SELECT AnimalID FROM animaltransport WHERE ID = %d" % int(tid))
    if animalid == 0:
        raise utils.ASMError("Trying to delete a transport that does not exist")
    audit.delete(dbo, username, "animaltransport", tid, audit.dump_row(dbo, "animaltransport", tid))
    db.execute(dbo, "DELETE FROM animaltransport WHERE ID = %d" % int(tid))
示例#25
0
def delete_profile(dbo, username, pfid):
    """
    Deletes a profile
    """
    audit.delete(
        dbo, username, "medicalprofile",
        str(db.query(dbo,
                     "SELECT * FROM medicalprofile WHERE ID = %d" % pfid)))
    db.execute(dbo, "DELETE FROM medicalprofile WHERE ID = %d" % pfid)
示例#26
0
def delete_user(dbo, username, uid):
    """
    Deletes the selected user
    """
    audit.delete(
        dbo, username, "users",
        str(db.query(dbo, "SELECT * FROM users WHERE ID=%d" % int(uid))))
    db.execute(dbo, "DELETE FROM users WHERE ID = %d" % int(uid))
    db.execute(dbo, "DELETE FROM userrole WHERE UserID = %d" % int(uid))
示例#27
0
def delete_voucher(dbo, username, vid):
    """
    Deletes a voucher record
    """
    audit.delete(
        dbo, username, "ownervoucher",
        str(db.query(dbo,
                     "SELECT * FROM ownervoucher WHERE ID=%d" % int(vid))))
    db.execute(dbo, "DELETE FROM ownervoucher WHERE ID = %d" % int(vid))
示例#28
0
def delete_waitinglist(dbo, username, wid):
    """
    Deletes a waiting list record
    """
    audit.delete(
        dbo, username, "animalwaitinglist",
        str(db.query(dbo,
                     "SELECT * FROM animalwaitinglist WHERE ID=%d" % wid)))
    db.execute(dbo, "DELETE FROM animalwaitinglist WHERE ID = %d" % wid)
示例#29
0
文件: lostfound.py 项目: magul/asm3
def delete_lostanimal(dbo, username, aid):
    """
    Deletes a lost animal
    """
    audit.delete(dbo, username, "animallost", aid, audit.dump_row(dbo, "animallost", aid))
    db.execute(dbo, "DELETE FROM animallost WHERE ID = %d" % aid)
    db.execute(dbo, "DELETE FROM media WHERE LinkID = %d AND LinkTypeID = %d" % (aid, media.LOSTANIMAL))
    db.execute(dbo, "DELETE FROM diary WHERE LinkID = %d AND LinkType = %d" % (aid, diary.LOSTANIMAL))
    db.execute(dbo, "DELETE FROM log WHERE LinkID = %d AND LinkType = %d" % (aid, log.LOSTANIMAL))
    db.execute(dbo, "DELETE FROM additional WHERE LinkID = %d AND LinkType IN (%s)" % (aid, additional.LOSTANIMAL_IN))
示例#30
0
def delete_animalcontrol(dbo, username, acid):
    """
    Deletes an animal control record
    """
    audit.delete(dbo, username, "animalcontrol", acid, audit.dump_row(dbo, "animalcontrol", acid))
    db.execute(dbo, "DELETE FROM animalcontrol WHERE ID = %d" % acid)
    db.execute(dbo, "DELETE FROM media WHERE LinkID = %d AND LinkTypeID = %d" % (acid, media.ANIMALCONTROL))
    db.execute(dbo, "DELETE FROM diary WHERE LinkID = %d AND LinkType = %d" % (acid, diary.ANIMALCONTROL))
    db.execute(dbo, "DELETE FROM log WHERE LinkID = %d AND LinkType = %d" % (acid, log.ANIMALCONTROL))
    db.execute(dbo, "DELETE FROM additional WHERE LinkID = %d AND LinkType IN (%s)" % (acid, additional.INCIDENT_IN))
示例#31
0
文件: lostfound.py 项目: magul/asm3
def delete_foundanimal(dbo, username, aid):
    """
    Deletes a found animal
    """
    audit.delete(dbo, username, "animalfound", aid, audit.dump_row(dbo, "animalfound", aid))
    db.execute(dbo, "DELETE FROM animalfound WHERE ID = %d" % aid)
    db.execute(dbo, "DELETE FROM media WHERE LinkID = %d AND LinkTypeID = %d" % (aid, media.FOUNDANIMAL))
    db.execute(dbo, "DELETE FROM diary WHERE LinkID = %d AND LinkType = %d" % (aid, diary.FOUNDANIMAL))
    db.execute(dbo, "DELETE FROM log WHERE LinkID = %d AND LinkType = %d" % (aid, log.FOUNDANIMAL))
    db.execute(dbo, "DELETE FROM additional WHERE LinkID = %d AND LinkType IN (%s)" % (aid, additional.FOUNDANIMAL_IN))
示例#32
0
def update_animalcontrol_removelink(dbo, username, acid, animalid):
    """
    Removes a link between an animal and an incident.
    """
    dbo.execute(
        "DELETE FROM animalcontrolanimal WHERE AnimalControlID = ? AND AnimalID = ?",
        (acid, animalid))
    audit.delete(
        dbo, username, "animalcontrolanimal", acid, "",
        "incident %d no longer linked to animal %d" % (acid, animalid))
示例#33
0
def delete_test(dbo, username, testid):
    """
    Deletes a test record
    """
    audit.delete(
        dbo, username, "animaltest",
        str(
            db.query(dbo,
                     "SELECT * FROM animaltest WHERE ID = %d" % int(testid))))
    db.execute(dbo, "DELETE FROM animaltest WHERE ID = %d" % testid)
示例#34
0
def delete_investigation(dbo, username, iid):
    """
    Deletes the selected investigation record
    """
    audit.delete(
        dbo, username, "ownerinvestigation",
        str(
            db.query(dbo, "SELECT * FROM ownerinvestigation WHERE ID=%d" %
                     int(iid))))
    db.execute(dbo, "DELETE FROM ownerinvestigation WHERE ID = %d" % int(iid))
示例#35
0
def delete_donation(dbo, username, did):
    """
    Deletes a donation record
    """
    audit.delete(dbo, username, "ownerdonation", str(db.query(dbo, "SELECT * FROM ownerdonation WHERE ID=%d" % int(did))))
    movementid = db.query_int(dbo, "SELECT MovementID FROM ownerdonation WHERE ID = %d" % int(did))
    db.execute(dbo, "DELETE FROM ownerdonation WHERE ID = %d" % int(did))
    # Delete any existing transaction for this donation if there is one
    db.execute(dbo, "DELETE FROM accountstrx WHERE OwnerDonationID = %d" % int(did))
    movement.update_movement_donation(dbo, movementid)
示例#36
0
def delete_onlineformfield(dbo, username, fieldid):
    """
    Deletes the specified onlineformfield
    """
    audit.delete(
        dbo, username, "onlineformfield",
        str(
            db.query(
                dbo,
                "SELECT * FROM onlineformfield WHERE ID=%d" % int(fieldid))))
    db.execute(dbo, "DELETE FROM onlineformfield WHERE ID = %d" % int(fieldid))
示例#37
0
文件: users.py 项目: magul/asm3
def delete_role(dbo, username, rid):
    """
    Deletes the selected role. If it's in use, throws an ASMValidationError
    """
    l = dbo.locale
    if db.query_int(dbo, "SELECT COUNT(*) FROM userrole WHERE RoleID = %d" % int(rid)) > 0:
        raise utils.ASMValidationError(i18n._("Role is in use and cannot be deleted.", l))
    audit.delete(dbo, username, "role", rid, audit.dump_row(dbo, "role", rid))
    db.execute(dbo, "DELETE FROM accountsrole WHERE RoleID = %d" % int(rid))
    db.execute(dbo, "DELETE FROM customreportrole WHERE RoleID = %d" % int(rid))
    db.execute(dbo, "DELETE FROM role WHERE ID = %d" % int(rid))
示例#38
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)
def delete_field(dbo, username, fid):
    """
    Deletes the selected additional field, along with all data held by it.
    """
    audit.delete(
        dbo, username, "additionalfield",
        str(
            db.query(dbo,
                     "SELECT * FROM additionalfield WHERE ID=%d" % int(fid))))
    db.execute(dbo, "DELETE FROM additionalfield WHERE ID = %d" % int(fid))
    db.execute(
        dbo, "DELETE FROM additional WHERE AdditionalFieldID = %d" % int(fid))
示例#40
0
def delete_vaccination(dbo, username, vaccinationid):
    """
    Deletes a vaccination record
    """
    audit.delete(
        dbo, username, "animalvaccination",
        str(
            db.query(
                dbo, "SELECT * FROM animalvaccination WHERE ID = %d" %
                int(vaccinationid))))
    db.execute(dbo,
               "DELETE FROM animalvaccination WHERE ID = %d" % vaccinationid)
示例#41
0
def delete_onlineformincoming(dbo, username, collationid):
    """
    Deletes the specified onlineformincoming set
    """
    audit.delete(
        dbo, username, "onlineformincoming",
        str(
            db.query(
                dbo, "SELECT * FROM onlineformincoming WHERE CollationID=%d" %
                int(collationid))))
    db.execute(
        dbo, "DELETE FROM onlineformincoming WHERE CollationID = %d" %
        int(collationid))
示例#42
0
def delete_diarytask(dbo, username, taskid):
    """
    Deletes a diary task
    """
    audit.delete(
        dbo, username, "diarytaskhead",
        str(
            db.query(dbo, "SELECT * FROM diarytaskhead WHERE ID = %d" %
                     int(taskid))))
    db.execute(
        dbo,
        "DELETE FROM diarytaskdetail WHERE DiaryTaskHeadID = %d" % int(taskid))
    db.execute(dbo, "DELETE FROM diarytaskhead WHERE ID = %d" % int(taskid))
示例#43
0
def delete_account(dbo, username, aid):
    """
    Deletes an account
    """
    audit.delete(
        dbo, username, "accounts",
        str(db.query(dbo, "SELECT * FROM accounts WHERE ID=%d" % int(aid))))
    db.execute(
        dbo,
        "DELETE FROM accountstrx WHERE SourceAccountID = %d OR DestinationAccountID = %d"
        % (int(aid), int(aid)))
    db.execute(dbo, "DELETE FROM accountsrole WHERE AccountID = %d" % int(aid))
    db.execute(dbo, "DELETE FROM accounts WHERE ID = %d" % int(aid))
示例#44
0
def delete_regimen(dbo, username, amid):
    """
    Deletes a regimen
    """
    audit.delete(
        dbo, username, "animalmedical",
        str(
            db.query(dbo,
                     "SELECT * FROM animalmedical WHERE ID = %d" % int(amid))))
    db.execute(
        dbo,
        "DELETE FROM animalmedicaltreatment WHERE AnimalMedicalID = %d" % amid)
    db.execute(dbo, "DELETE FROM animalmedical WHERE ID = %d" % amid)
示例#45
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"]))
示例#46
0
def delete_donation(dbo, username, did):
    """
    Deletes a donation record
    """
    audit.delete(
        dbo, username, "ownerdonation",
        str(db.query(dbo,
                     "SELECT * FROM ownerdonation WHERE ID=%d" % int(did))))
    movementid = db.query_int(
        dbo, "SELECT MovementID FROM ownerdonation WHERE ID = %d" % int(did))
    db.execute(dbo, "DELETE FROM ownerdonation WHERE ID = %d" % int(did))
    # Delete any existing transaction for this donation if there is one
    db.execute(dbo,
               "DELETE FROM accountstrx WHERE OwnerDonationID = %d" % int(did))
    movement.update_movement_donation(dbo, movementid)
示例#47
0
def delete_treatment(dbo, username, amtid):
    """
    Deletes a treatment record
    """
    audit.delete(
        dbo, username, "animalmedicaltreatment",
        str(
            db.query(
                dbo, "SELECT * FROM animalmedicaltreatment WHERE ID = %d" %
                int(amtid))))
    amid = db.query_int(
        dbo,
        "SELECT AnimalMedicalID FROM animalmedicaltreatment WHERE ID = %d" %
        int(amtid))
    db.execute(dbo, "DELETE FROM animalmedicaltreatment WHERE ID = %d" % amtid)
    calculate_given_remaining(dbo, amid)
    update_medical_treatments(dbo, username, amid)
示例#48
0
def delete_role(dbo, username, rid):
    """
    Deletes the selected role. If it's in use, throws an ASMValidationError
    """
    l = dbo.locale
    if db.query_int(
            dbo,
            "SELECT COUNT(*) FROM userrole WHERE RoleID = %d" % int(rid)) > 0:
        raise utils.ASMValidationError(
            i18n._("Role is in use and cannot be deleted.", l))
    audit.delete(
        dbo, username, "role",
        str(db.query(dbo, "SELECT * FROM role WHERE ID=%d" % int(rid))))
    db.execute(dbo, "DELETE FROM accountsrole WHERE RoleID = %d" % int(rid))
    db.execute(dbo,
               "DELETE FROM customreportrole WHERE RoleID = %d" % int(rid))
    db.execute(dbo, "DELETE FROM role WHERE ID = %d" % int(rid))
示例#49
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)
示例#50
0
def merge_person(dbo, username, personid, mergepersonid):
    """
    Reparents all satellite records of mergepersonid onto
    personid and then deletes it.
    """
    l = dbo.locale
    if personid == mergepersonid:
        raise utils.ASMValidationError(
            _(
                "The person record to merge must be different from the original.",
                l))
    if personid == 0 or mergepersonid == 0:
        raise utils.ASMValidationError("Internal error: Cannot merge ID 0")

    def reparent(table, field, linktypefield="", linktype=-1):
        if linktype >= 0:
            db.execute(
                dbo, "UPDATE %s SET %s = %d WHERE %s = %d AND %s = %d" %
                (table, field, personid, field, mergepersonid, linktypefield,
                 linktype))
        else:
            db.execute(
                dbo, "UPDATE %s SET %s = %d WHERE %s = %d" %
                (table, field, personid, field, mergepersonid))

    reparent("adoption", "OwnerID")
    reparent("adoption", "RetailerID")
    reparent("animal", "OriginalOwnerID")
    reparent("animal", "BroughtInByOwnerID")
    reparent("animal", "OwnersVetID")
    reparent("animal", "CurrentVetID")
    reparent("animallost", "OwnerID")
    reparent("animalfound", "OwnerID")
    reparent("animalwaitinglist", "OwnerID")
    reparent("ownerdonation", "OwnerID")
    reparent("ownervoucher", "OwnerID")
    reparent("users", "OwnerID")
    reparent("media", "LinkID", "LinkTypeID", media.PERSON)
    reparent("diary", "LinkID", "LinkType", diary.PERSON)
    reparent("log", "LinkID", "LinkType", log.PERSON)
    audit.delete(
        dbo, username, "owner",
        str(db.query(dbo, "SELECT * FROM owner WHERE ID=%d" % mergepersonid)))
    db.execute(dbo, "DELETE FROM owner WHERE ID = %d" % mergepersonid)
示例#51
0
def delete_onlineformfield(dbo, username, fieldid):
    """
    Deletes the specified onlineformfield
    """
    audit.delete(dbo, username, "onlineformfield", str(db.query(dbo, "SELECT * FROM onlineformfield WHERE ID=%d" % int(fieldid))))
    db.execute(dbo, "DELETE FROM onlineformfield WHERE ID = %d" % int(fieldid))
示例#52
0
def delete_diarytaskdetail(dbo, username, did):
    """
    Deletes a diary task detail record
    """
    audit.delete(dbo, username, "diarytaskdetail", str(db.query(dbo, "SELECT * FROM diarytaskdetail WHERE ID = %d" % int(did))))
    db.execute(dbo, "DELETE FROM diarytaskdetail WHERE ID = %d" % int(did))
示例#53
0
def delete_lostanimal(dbo, username, aid):
    """
    Deletes a lost animal
    """
    audit.delete(dbo, username, "animallost", str(db.query(dbo, "SELECT * FROM animallost WHERE ID=%d" % aid)))
    db.execute(dbo, "DELETE FROM animallost WHERE ID = %d" % aid)
示例#54
0
def delete_foundanimal(dbo, username, aid):
    """
    Deletes a found animal
    """
    audit.delete(dbo, username, "animalfound", str(db.query(dbo, "SELECT * FROM animalfound WHERE ID=%d" % aid)))
    db.execute(dbo, "DELETE FROM animalfound WHERE ID = %d" % aid)
示例#55
0
def delete_trx(dbo, username, tid):
    """
    Deletes a transaction
    """
    audit.delete(dbo, username, "accountstrx", str(db.query(dbo, "SELECT * FROM accountstrx WHERE ID=%d" % int(tid))))
    db.execute(dbo, "DELETE FROM accountstrx WHERE ID = %d" % int(tid))
示例#56
0
def delete_voucher(dbo, username, vid):
    """
    Deletes a voucher record
    """
    audit.delete(dbo, username, "ownervoucher", str(db.query(dbo, "SELECT * FROM ownervoucher WHERE ID=%d" % int(vid))))
    db.execute(dbo, "DELETE FROM ownervoucher WHERE ID = %d" % int(vid))
示例#57
0
def delete_profile(dbo, username, pfid):
    """
    Deletes a profile
    """
    audit.delete(dbo, username, "medicalprofile", str(db.query(dbo, "SELECT * FROM medicalprofile WHERE ID = %d" % pfid)))
    db.execute(dbo, "DELETE FROM medicalprofile WHERE ID = %d" % pfid)
示例#58
0
def delete_onlineformincoming(dbo, username, collationid):
    """
    Deletes the specified onlineformincoming set
    """
    audit.delete(dbo, username, "onlineformincoming", str(db.query(dbo, "SELECT * FROM onlineformincoming WHERE CollationID=%d" % int(collationid))))
    db.execute(dbo, "DELETE FROM onlineformincoming WHERE CollationID = %d" % int(collationid))
示例#59
0
def delete_waitinglist(dbo, username, wid):
    """
    Deletes a waiting list record
    """
    audit.delete(dbo, username, "animalwaitinglist", str(db.query(dbo, "SELECT * FROM animalwaitinglist WHERE ID=%d" % wid)))
    db.execute(dbo, "DELETE FROM animalwaitinglist WHERE ID = %d" % wid)
示例#60
0
def delete_log(dbo, username, logid):
    """
    Deletes a log
    """
    audit.delete(dbo, username, "log", str(db.query(dbo, "SELECT * FROM log WHERE ID = %d" % int(logid))))
    db.execute(dbo, "DELETE FROM log WHERE ID = %d" % int(logid))