Пример #1
0
def create_animal_from_found(dbo, username, aid):
    """
    Creates an animal record from a found animal with the id given
    """
    a = db.query(dbo, "SELECT * FROM animalfound WHERE ID = %d" % int(aid))[0]
    l = dbo.locale
    data = {
        "animalname":           _("Found Animal {0}", l).format(aid),
        "markings":             str(a["DISTFEAT"]),
        "species":              str(a["ANIMALTYPEID"]),
        "comments":             str(a["COMMENTS"]),
        "broughtinby":          str(a["OWNERID"]),
        "originalowner":        str(a["OWNERID"]),
        "animaltype":           configuration.default_type(dbo),
        "breed1":               a["BREEDID"],
        "breed2":               a["BREEDID"],
        "basecolour":           str(a["BASECOLOURID"]),
        "size":                 configuration.default_size(dbo),
        "internallocation":     configuration.default_location(dbo),
        "dateofbirth":          python2display(l, subtract_years(now(dbo.timezone))),
        "estimateddob":         "1",
    }
    # If we're creating shelter codes manually, we need to put something unique
    # in there for now. Use the id
    if configuration.manual_codes(dbo):
        data["sheltercode"] = "FA" + str(aid)
        data["shortcode"] = "FA" + str(aid)
    nextid, code = animal.insert_animal_from_form(dbo, data, username)
    return nextid
Пример #2
0
def create_animal_from_found(dbo, username, aid):
    """
    Creates an animal record from a found animal with the id given
    """
    a = dbo.first_row( dbo.query("SELECT * FROM animalfound WHERE ID = %d" % int(aid)) )
    l = dbo.locale
    data = {
        "animalname":           _("Found Animal {0}", l).format(aid),
        "markings":             str(a["DISTFEAT"]),
        "species":              str(a["ANIMALTYPEID"]),
        "comments":             str(a["COMMENTS"]),
        "broughtinby":          str(a["OWNERID"]),
        "originalowner":        str(a["OWNERID"]),
        "animaltype":           configuration.default_type(dbo),
        "breed1":               a["BREEDID"],
        "breed2":               a["BREEDID"],
        "basecolour":           str(a["BASECOLOURID"]),
        "size":                 configuration.default_size(dbo),
        "internallocation":     configuration.default_location(dbo),
        "dateofbirth":          python2display(l, subtract_years(now(dbo.timezone))),
        "estimateddob":         "1",
    }
    # If we're creating shelter codes manually, we need to put something unique
    # in there for now. Use the id
    if configuration.manual_codes(dbo):
        data["sheltercode"] = "FA" + str(aid)
        data["shortcode"] = "FA" + str(aid)
    nextid, code = animal.insert_animal_from_form(dbo, utils.PostedData(data, l), username)
    return nextid
Пример #3
0
def create_animal(dbo, username, wlid):
    """
    Creates an animal record from a waiting list entry with the id given
    """
    a = db.query(dbo,
                 "SELECT * FROM animalwaitinglist WHERE ID = %d" % wlid)[0]
    l = dbo.locale
    data = {
        "animalname": _("Waiting List {0}", l).format(wlid),
        "markings": str(a["ANIMALDESCRIPTION"]),
        "reasonforentry": str(a["REASONFORWANTINGTOPART"]),
        "species": str(a["SPECIESID"]),
        "comments": str(a["COMMENTS"]),
        "broughtinby": str(a["OWNERID"]),
        "originalowner": str(a["OWNERID"]),
        "animaltype": configuration.default_type(dbo),
        "breed1": configuration.default_breed(dbo),
        "breed2": configuration.default_breed(dbo),
        "basecolour": configuration.default_colour(dbo),
        "size": configuration.default_size(dbo),
        "internallocation": configuration.default_location(dbo),
        "dateofbirth": python2display(l, subtract_years(now(dbo.timezone))),
        "estimateddob": "1"
    }
    # If we're creating shelter codes manually, we need to put something unique
    # in there for now. Use the id
    if configuration.manual_codes(dbo):
        data["sheltercode"] = "WL" + str(wlid)
        data["shortcode"] = "WL" + str(wlid)
    nextid, code = animal.insert_animal_from_form(dbo, data, username)
    # Now that we've created our animal, we should remove this entry from the waiting list
    db.execute(dbo, "UPDATE animalwaitinglist SET DateRemovedFromList = %s, ReasonForRemoval = %s " \
        "WHERE ID = %d" % (
        db.dd(now(dbo.timezone)),
        db.ds(_("Moved to animal record {0}", l).format(code)),
        wlid))
    return nextid
Пример #4
0
def create_animal(dbo, username, wlid):
    """
    Creates an animal record from a waiting list entry with the id given
    """
    a = db.query(dbo, "SELECT * FROM animalwaitinglist WHERE ID = %d" % wlid)[0]
    l = dbo.locale
    data = {
        "animalname":           _("Waiting List {0}", l).format(wlid),
        "markings":             str(a["ANIMALDESCRIPTION"]),
        "reasonforentry":       str(a["REASONFORWANTINGTOPART"]),
        "species":              str(a["SPECIESID"]),
        "comments":             str(a["COMMENTS"]),
        "broughtinby":          str(a["OWNERID"]),
        "originalowner":        str(a["OWNERID"]),
        "animaltype":           configuration.default_type(dbo),
        "breed1":               configuration.default_breed(dbo),
        "breed2":               configuration.default_breed(dbo),
        "basecolour":           configuration.default_colour(dbo),
        "size":                 configuration.default_size(dbo),
        "internallocation":     configuration.default_location(dbo),
        "dateofbirth":          python2display(l, subtract_years(now(dbo.timezone))),
        "estimateddob":         "1"
    }
    # If we're creating shelter codes manually, we need to put something unique
    # in there for now. Use the id
    if configuration.manual_codes(dbo):
        data["sheltercode"] = "WL" + str(wlid)
        data["shortcode"] = "WL" + str(wlid)
    nextid, code = animal.insert_animal_from_form(dbo, data, username)
    # Now that we've created our animal, we should remove this entry from the waiting list
    db.execute(dbo, "UPDATE animalwaitinglist SET DateRemovedFromList = %s, ReasonForRemoval = %s " \
        "WHERE ID = %d" % ( 
        db.dd(now(dbo.timezone)), 
        db.ds(_("Moved to animal record {0}", l).format(code)),
        wlid))
    return nextid
Пример #5
0
def lookingfor_report(dbo, username="******"):
    """
    Generates the person looking for report
    """
    l = dbo.locale
    title = _("People Looking For", l)
    h = reports.get_report_header(dbo, title, username)

    def p(s):
        return "<p>%s</p>" % s

    def td(s):
        return "<td>%s</td>" % s

    def hr():
        return "<hr />"

    people = db.query(dbo, "SELECT owner.*, " \
        "(SELECT Size FROM lksize WHERE ID = owner.MatchSize) AS MatchSizeName, " \
        "(SELECT BaseColour FROM basecolour WHERE ID = owner.MatchColour) AS MatchColourName, " \
        "(SELECT Sex FROM lksex WHERE ID = owner.MatchSex) AS MatchSexName, " \
        "(SELECT BreedName FROM breed WHERE ID = owner.MatchBreed) AS MatchBreedName, " \
        "(SELECT AnimalType FROM animaltype WHERE ID = owner.MatchAnimalType) AS MatchAnimalTypeName, " \
        "(SELECT SpeciesName FROM species WHERE ID = owner.MatchSpecies) AS MatchSpeciesName " \
        "FROM owner WHERE MatchActive = 1 AND " \
        "(MatchExpires Is Null OR MatchExpires > %s)" \
        "ORDER BY OwnerName" % db.dd(now(dbo.timezone)))

    ah = hr()
    ah += "<table border=\"1\" width=\"100%\"><tr>"
    ah += "<th>%s</th>" % _("Code", l)
    ah += "<th>%s</th>" % _("Name", l)
    ah += "<th>%s</th>" % _("Age", l)
    ah += "<th>%s</th>" % _("Sex", l)
    ah += "<th>%s</th>" % _("Size", l)
    ah += "<th>%s</th>" % _("Color", l)
    ah += "<th>%s</th>" % _("Species", l)
    ah += "<th>%s</th>" % _("Breed", l)
    ah += "<th>%s</th>" % _("Good with cats", l)
    ah += "<th>%s</th>" % _("Good with dogs", l)
    ah += "<th>%s</th>" % _("Good with children", l)
    ah += "<th>%s</th>" % _("Housetrained", l)
    ah += "<th>%s</th>" % _("Comments", l)
    ah += "</tr>"

    totalmatches = 0
    for p in people:
        sql = ""
        if p["MATCHANIMALTYPE"] > 0:
            sql += " AND a.AnimalTypeID = %d" % int(p["MATCHANIMALTYPE"])
        if p["MATCHSPECIES"] > 0:
            sql += " AND a.SpeciesID = %d" % int(p["MATCHSPECIES"])
        if p["MATCHBREED"] > 0:
            sql += " AND (a.BreedID = %d OR a.Breed2ID = %d)" % (int(
                p["MATCHBREED"]), int(p["MATCHBREED"]))
        if p["MATCHSEX"] > -1: sql += " AND a.Sex = %d" % int(p["MATCHSEX"])
        if p["MATCHSIZE"] > -1: sql += " AND a.Size = %d" % int(p["MATCHSIZE"])
        if p["MATCHCOLOUR"] > -1:
            sql += " AND a.BaseColourID = %d" % int(p["MATCHCOLOUR"])
        if p["MATCHGOODWITHCHILDREN"] == 0:
            sql += " AND a.IsGoodWithChildren = 0"
        if p["MATCHGOODWITHCATS"] == 0: sql += " AND a.IsGoodWithCats = 0"
        if p["MATCHGOODWITHDOGS"] == 0: sql += " AND a.IsGoodWithDogs = 0"
        if p["MATCHHOUSETRAINED"] == 0: sql += " AND a.IsHouseTrained = 0"
        if p["MATCHAGEFROM"] >= 0 and p["MATCHAGETO"] > 0:
            sql += " AND a.DateOfBirth BETWEEN %s AND %s" % (db.dd(subtract_years(now(dbo.timezone), p["MATCHAGETO"])), \
                db.dd(subtract_years(now(dbo.timezone), p["MATCHAGEFROM"])))
        if p["MATCHCOMMENTSCONTAIN"] is not None and p[
                "MATCHCOMMENTSCONTAIN"] != "":
            for w in str(p["MATCHCOMMENTSCONTAIN"]).split(" "):
                sql += " AND a.AnimalComments Like '%%%s%%'" % w.replace(
                    "'", "`")
        sql = animal.get_animal_query(
        ) + " WHERE a.Archived=0 AND a.DeceasedDate Is Null" + sql
        animals = db.query(dbo, sql)

        h += "<h2>%s (%s) %s</h2>" % (p["OWNERNAME"], p["OWNERADDRESS"],
                                      p["HOMETELEPHONE"])
        c = []
        if p["MATCHSIZE"] != -1: c.append(p["MATCHSIZENAME"])
        if p["MATCHCOLOUR"] != -1: c.append(p["MATCHCOLOURNAME"])
        if p["MATCHSEX"] != -1: c.append(p["MATCHSEXNAME"])
        if p["MATCHBREED"] != -1: c.append(p["MATCHBREEDNAME"])
        if p["MATCHSPECIES"] != -1: c.append(p["MATCHSPECIESNAME"])
        if p["MATCHANIMALTYPE"] != -1: c.append(p["MATCHANIMALTYPENAME"])
        if p["MATCHGOODWITHCHILDREN"] == 0: c.append(_("Good with kids", l))
        if p["MATCHGOODWITHCATS"] == 0: c.append(_("Good with cats", l))
        if p["MATCHGOODWITHDOGS"] == 0: c.append(_("Good with dogs", l))
        if p["MATCHHOUSETRAINED"] == 0: c.append(_("Housetrained", l))
        if p["MATCHAGEFROM"] >= 0 and p["MATCHAGETO"] > 0:
            c.append(
                _("Age", l) + (" %0.2f - %0.2f" %
                               (p["MATCHAGEFROM"], p["MATCHAGETO"])))
        if p["MATCHCOMMENTSCONTAIN"] is not None and p[
                "MATCHCOMMENTSCONTAIN"] != "":
            c.append(
                _("Comments Contain", l) + ": " + p["MATCHCOMMENTSCONTAIN"])
        if len(c) > 0:
            h += "<p style='font-size: 8pt'>(%s: %s)</p>" % (_(
                "Looking for", l), ", ".join(c))

        outputheader = False
        for a in animals:
            if not outputheader:
                outputheader = True
                h += ah
            totalmatches += 1
            h += "<tr>"
            h += td(a["CODE"])
            h += td(a["ANIMALNAME"])
            h += td(a["ANIMALAGE"])
            h += td(a["SEXNAME"])
            h += td(a["SIZENAME"])
            h += td(a["COLOURNAME"])
            h += td(a["SPECIESNAME"])
            h += td(a["BREEDNAME"])
            h += td(a["ISGOODWITHCATSNAME"])
            h += td(a["ISGOODWITHDOGSNAME"])
            h += td(a["ISGOODWITHCHILDRENNAME"])
            h += td(a["ISHOUSETRAINEDNAME"])
            h += td(a["ANIMALCOMMENTS"])

        if outputheader:
            h += "</table>"
        h += hr()

    if len(people) == 0:
        h += p(_("No matches found.", l))

    h += "<!-- $AM%d^ animal matches -->" % totalmatches
    h += reports.get_report_footer(dbo, title, username)
    return h
Пример #6
0
def create_animal(dbo, username, wlid):
    """
    Creates an animal record from a waiting list entry with the id given
    """
    l = dbo.locale
    a = dbo.first_row(
        dbo.query("SELECT * FROM animalwaitinglist WHERE ID = ?", [wlid]))

    data = {
        "animalname": _("Waiting List {0}", l).format(wlid),
        "markings": str(a["ANIMALDESCRIPTION"]),
        "reasonforentry": str(a["REASONFORWANTINGTOPART"]),
        "species": str(a["SPECIESID"]),
        "hiddenanimaldetails": str(a["COMMENTS"]),
        "broughtinby": str(a["OWNERID"]),
        "originalowner": str(a["OWNERID"]),
        "animaltype": configuration.default_type(dbo),
        "breed1": configuration.default_breed(dbo),
        "breed2": configuration.default_breed(dbo),
        "basecolour": configuration.default_colour(dbo),
        "size": configuration.default_size(dbo),
        "internallocation": configuration.default_location(dbo),
        "dateofbirth": python2display(l, subtract_years(now(dbo.timezone))),
        "estimateddob": "1"
    }
    # If we aren't showing the time brought in, set it to midnight
    if not configuration.add_animals_show_time_brought_in(dbo):
        data["timebroughtin"] = "00:00:00"

    # If we're creating shelter codes manually, we need to put something unique
    # in there for now. Use the id
    if configuration.manual_codes(dbo):
        data["sheltercode"] = "WL" + str(wlid)
        data["shortcode"] = "WL" + str(wlid)
    nextid, code = animal.insert_animal_from_form(dbo,
                                                  utils.PostedData(data, l),
                                                  username)

    # Now that we've created our animal, we should remove this entry from the waiting list
    dbo.update(
        "animalwaitinglist", wlid, {
            "DateRemovedFromList": dbo.today(),
            "ReasonForRemoval": _("Moved to animal record {0}", l).format(code)
        }, username)

    # If there were any logs and media entries on the waiting list, create them on the animal

    # Media
    for me in dbo.query(
            "SELECT * FROM media WHERE LinkTypeID = ? AND LinkID = ?",
        (media.WAITINGLIST, wlid)):
        ext = me.medianame
        ext = ext[ext.rfind("."):].lower()
        mediaid = dbo.get_id("media")
        medianame = "%d%s" % (mediaid, ext)
        dbo.insert(
            "media",
            {
                "ID": mediaid,
                "DBFSID": 0,
                "MediaSize": 0,
                "MediaName": medianame,
                "MediaMimeType": media.mime_type(medianame),
                "MediaType": me.mediatype,
                "MediaNotes": me.medianotes,
                "WebsitePhoto": me.websitephoto,
                "WebsiteVideo": me.websitevideo,
                "DocPhoto": me.docphoto,
                "ExcludeFromPublish": me.excludefrompublish,
                # ASM2_COMPATIBILITY
                "NewSinceLastPublish": 1,
                "UpdatedSinceLastPublish": 0,
                # ASM2_COMPATIBILITY
                "LinkID": nextid,
                "LinkTypeID": media.ANIMAL,
                "Date": me.date,
                "RetainUntil": me.retainuntil
            },
            generateID=False)

        # Now clone the dbfs item pointed to by this media item if it's a file
        if me.mediatype == media.MEDIATYPE_FILE:
            filedata = dbfs.get_string(dbo, me.medianame)
            dbfsid = dbfs.put_string(dbo, medianame, "/animal/%d" % nextid,
                                     filedata)
            dbo.execute(
                "UPDATE media SET DBFSID = ?, MediaSize = ? WHERE ID = ?",
                (dbfsid, len(filedata), mediaid))

    # Logs
    for lo in dbo.query("SELECT * FROM log WHERE LinkType = ? AND LinkID = ?",
                        (log.WAITINGLIST, wlid)):
        dbo.insert(
            "log", {
                "LinkID": nextid,
                "LinkType": log.ANIMAL,
                "LogTypeID": lo.LOGTYPEID,
                "Date": lo.DATE,
                "Comments": lo.COMMENTS
            }, username)

    return nextid
Пример #7
0
def lookingfor_report(dbo, username = "******"):
    """
    Generates the person looking for report
    """
    l = dbo.locale
    title = _("People Looking For", l)
    h = reports.get_report_header(dbo, title, username)
    def p(s): return "<p>%s</p>" % s
    def td(s): return "<td>%s</td>" % s
    def hr(): return "<hr />"
  
    people = db.query(dbo, "SELECT owner.*, " \
        "(SELECT Size FROM lksize WHERE ID = owner.MatchSize) AS MatchSizeName, " \
        "(SELECT BaseColour FROM basecolour WHERE ID = owner.MatchColour) AS MatchColourName, " \
        "(SELECT Sex FROM lksex WHERE ID = owner.MatchSex) AS MatchSexName, " \
        "(SELECT BreedName FROM breed WHERE ID = owner.MatchBreed) AS MatchBreedName, " \
        "(SELECT AnimalType FROM animaltype WHERE ID = owner.MatchAnimalType) AS MatchAnimalTypeName, " \
        "(SELECT SpeciesName FROM species WHERE ID = owner.MatchSpecies) AS MatchSpeciesName " \
        "FROM owner WHERE MatchActive = 1 AND " \
        "(MatchExpires Is Null OR MatchExpires > %s)" \
        "ORDER BY OwnerName" % db.dd(now(dbo.timezone)))

    ah = hr()
    ah += "<table border=\"1\" width=\"100%\"><tr>"
    ah += "<th>%s</th>" % _("Code", l)
    ah += "<th>%s</th>" % _("Name", l)
    ah += "<th>%s</th>" % _("Age", l)
    ah += "<th>%s</th>" % _("Sex", l)
    ah += "<th>%s</th>" % _("Size", l)
    ah += "<th>%s</th>" % _("Color", l)
    ah += "<th>%s</th>" % _("Species", l)
    ah += "<th>%s</th>" % _("Breed", l)
    ah += "<th>%s</th>" % _("Good with cats", l)
    ah += "<th>%s</th>" % _("Good with dogs", l)
    ah += "<th>%s</th>" % _("Good with children", l)
    ah += "<th>%s</th>" % _("Housetrained", l)
    ah += "<th>%s</th>" % _("Comments", l)
    ah += "</tr>"

    totalmatches = 0
    for p in people:
        sql = ""
        if p["MATCHANIMALTYPE"] > 0: sql += " AND a.AnimalTypeID = %d" % int(p["MATCHANIMALTYPE"])
        if p["MATCHSPECIES"] > 0: sql += " AND a.SpeciesID = %d" % int(p["MATCHSPECIES"])
        if p["MATCHBREED"] > 0: sql += " AND (a.BreedID = %d OR a.Breed2ID = %d)" % (int(p["MATCHBREED"]), int(p["MATCHBREED"]))
        if p["MATCHSEX"] > -1: sql += " AND a.Sex = %d" % int(p["MATCHSEX"])
        if p["MATCHSIZE"] > -1: sql += " AND a.Size = %d" % int(p["MATCHSIZE"])
        if p["MATCHCOLOUR"] > -1: sql += " AND a.BaseColourID = %d" % int(p["MATCHCOLOUR"])
        if p["MATCHGOODWITHCHILDREN"] == 0: sql += " AND a.IsGoodWithChildren = 0"
        if p["MATCHGOODWITHCATS"] == 0: sql += " AND a.IsGoodWithCats = 0"
        if p["MATCHGOODWITHDOGS"] == 0: sql += " AND a.IsGoodWithDogs = 0"
        if p["MATCHHOUSETRAINED"] == 0: sql += " AND a.IsHouseTrained = 0"
        if p["MATCHAGEFROM"] >= 0 and p["MATCHAGETO"] > 0: 
            sql += " AND a.DateOfBirth BETWEEN %s AND %s" % (db.dd(subtract_years(now(dbo.timezone), p["MATCHAGETO"])), \
                db.dd(subtract_years(now(dbo.timezone), p["MATCHAGEFROM"])))
        if p["MATCHCOMMENTSCONTAIN"] is not None and p["MATCHCOMMENTSCONTAIN"] != "":
            for w in str(p["MATCHCOMMENTSCONTAIN"]).split(" "):
                sql += " AND a.AnimalComments Like '%%%s%%'" % w.replace("'", "`")
        sql = animal.get_animal_query() + " WHERE a.Archived=0 AND a.DeceasedDate Is Null" + sql
        animals = db.query(dbo, sql)

        h += "<h2>%s (%s) %s</h2>" % (p["OWNERNAME"], p["OWNERADDRESS"], p["HOMETELEPHONE"])
        c = []
        if p["MATCHSIZE"] != -1: c.append(p["MATCHSIZENAME"])
        if p["MATCHCOLOUR"] != -1: c.append(p["MATCHCOLOURNAME"])
        if p["MATCHSEX"] != -1: c.append(p["MATCHSEXNAME"])
        if p["MATCHBREED"] != -1: c.append(p["MATCHBREEDNAME"])
        if p["MATCHSPECIES"] != -1: c.append(p["MATCHSPECIESNAME"])
        if p["MATCHANIMALTYPE"] != -1: c.append(p["MATCHANIMALTYPENAME"])
        if p["MATCHGOODWITHCHILDREN"] == 0: c.append(_("Good with kids", l))
        if p["MATCHGOODWITHCATS"] == 0: c.append(_("Good with cats", l))
        if p["MATCHGOODWITHDOGS"] == 0: c.append(_("Good with dogs", l))
        if p["MATCHHOUSETRAINED"] == 0: c.append(_("Housetrained", l))
        if p["MATCHAGEFROM"] >= 0 and p["MATCHAGETO"] > 0: c.append(_("Age", l) + (" %0.2f - %0.2f" % (p["MATCHAGEFROM"], p["MATCHAGETO"])))
        if p["MATCHCOMMENTSCONTAIN"] is not None and p["MATCHCOMMENTSCONTAIN"] != "": c.append(_("Comments Contain", l) + ": " + p["MATCHCOMMENTSCONTAIN"])
        if len(c) > 0:
            h += "<p style='font-size: 8pt'>(%s: %s)</p>" % (_("Looking for", l), ", ".join(c))

        outputheader = False
        for a in animals:
            if not outputheader:
                outputheader = True
                h += ah
            totalmatches += 1
            h += "<tr>"
            h += td(a["CODE"])
            h += td(a["ANIMALNAME"])
            h += td(a["ANIMALAGE"])
            h += td(a["SEXNAME"])
            h += td(a["SIZENAME"])
            h += td(a["COLOURNAME"])
            h += td(a["SPECIESNAME"])
            h += td(a["BREEDNAME"])
            h += td(a["ISGOODWITHCATSNAME"])
            h += td(a["ISGOODWITHDOGSNAME"])
            h += td(a["ISGOODWITHCHILDRENNAME"])
            h += td(a["ISHOUSETRAINEDNAME"])
            h += td(a["ANIMALCOMMENTS"])

        if outputheader:
            h += "</table>"
        h += hr()

    if len(people) == 0:
        h += p(_("No matches found.", l))

    h += "<!-- $AM%d^ animal matches -->" % totalmatches
    h += reports.get_report_footer(dbo, title, username)
    return h