Exemple #1
0
def match_report(dbo, username = "******", lostanimalid = 0, foundanimalid = 0, animalid = 0, limit = 0):
    """
    Generates the match report and returns it as a string
    """
    l = dbo.locale
    title = _("Match lost and found animals", l)
    h = []
    h.append(reports.get_report_header(dbo, title, username))
    if limit > 0:
        h.append("<p>(" + _("Limited to {0} matches", l).format(limit) + ")</p>")
    def p(s): 
        return "<p>%s</p>" % s
    def td(s): 
        return "<td>%s</td>" % s
    def hr(): 
        return "<hr />"
    lastid = 0
    matches = match(dbo, lostanimalid, foundanimalid, animalid, limit)
    if len(matches) > 0:
        for m in matches:
            if lastid != m.lid:
                if lastid != 0:
                    h.append("</tr></table>")
                    h.append(hr())
                h.append(p(_("{0} - {1} {2} ({3}), contact {4} ({5}) - lost in {6}, postcode {7}, on {8}", l).format( \
                    m.lid, "%s %s %s" % (m.lagegroup, m.lbasecolourname, m.lsexname), \
                    "%s/%s" % (m.lspeciesname,m.lbreedname), \
                    m.ldistinguishingfeatures, m.lcontactname, m.lcontactnumber, m.larealost, m.lareapostcode,
                    python2display(l, m.ldatelost))))
                h.append("<table border=\"1\" width=\"100%\"><tr>")
                h.append("<th>%s</th>" % _("Reference", l))
                h.append("<th>%s</th>" % _("Description", l))
                h.append("<th>%s</th>" % _("Area Found", l))
                h.append("<th>%s</th>" % _("Area Postcode", l))
                h.append("<th>%s</th>" % _("Date Found", l))
                h.append("<th>%s</th>" % _("Contact", l))
                h.append("<th>%s</th>" % _("Number", l))
                h.append("<th>%s</th>" % _("Match", l))
                h.append("</tr>")
                lastid = m.lid
            h.append("<tr>")
            h.append(td(str(m.fid)))
            h.append(td("%s %s %s %s %s" % (m.fagegroup, m.fbasecolourname, m.fsexname, m.fspeciesname, m.fbreedname)))
            h.append(td(m.fareafound))
            h.append(td(m.fareapostcode))
            h.append(td(python2display(l, m.fdatefound)))
            h.append(td(m.fcontactname))
            h.append(td(m.fcontactnumber))
            h.append(td(str(m.matchpoints) + "%"))
            h.append("</tr>")
        h.append("</tr></table>")
    else:
        h.append(p(_("No matches found.", l)))
    h.append(reports.get_report_footer(dbo, title, username))
    return "\n".join(h)
Exemple #2
0
def match_report(dbo, username = "******", lostanimalid = 0, foundanimalid = 0, animalid = 0):
    """
    Same interface as match above, but generates the match report
    """
    l = dbo.locale
    title = _("Match lost and found animals", l)
    h = []
    h.append(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 />"
    lastid = 0
    matches = match(dbo, lostanimalid, foundanimalid, animalid)
    if len(matches) > 0:
        for m in matches:
            if lastid != m.lid:
                if lastid != 0:
                    h.append("</tr></table>")
                    h.append(hr())
                h.append(p(_("{0} - {1} {2} ({3}), contact {4} ({5}) - lost in {6}, postcode {7}, on {8}", l).format( \
                    m.lid, "%s %s %s" % (m.lagegroup, m.lbasecolourname, m.lsexname), \
                    "%s/%s" % (m.lspeciesname,m.lbreedname), \
                    m.ldistinguishingfeatures, m.lcontactname, m.lcontactnumber, m.larealost, m.lareapostcode,
                    python2display(l, m.ldatelost))))
                h.append("<table border=\"1\" width=\"100%\"><tr>")
                h.append("<th>%s</th>" % _("Reference", l))
                h.append("<th>%s</th>" % _("Description", l))
                h.append("<th>%s</th>" % _("Area Found", l))
                h.append("<th>%s</th>" % _("Area Postcode", l))
                h.append("<th>%s</th>" % _("Date Found", l))
                h.append("<th>%s</th>" % _("Contact", l))
                h.append("<th>%s</th>" % _("Number", l))
                h.append("<th>%s</th>" % _("Match", l))
                h.append("</tr>")
                lastid = m.lid
            h.append("<tr>")
            h.append(td(str(m.fid)))
            h.append(td("%s %s %s %s %s" % (m.fagegroup, m.fbasecolourname, m.fsexname, m.fspeciesname, m.fbreedname)))
            h.append(td(m.fareafound))
            h.append(td(m.fareapostcode))
            h.append(td(python2display(l, m.fdatefound)))
            h.append(td(m.fcontactname))
            h.append(td(m.fcontactnumber))
            h.append(td(str(m.matchpoints) + "%"))
            h.append("</tr>")
        h.append("</tr></table>")
    else:
        h.append(p(_("No matches found.", l)))
    h.append(reports.get_report_footer(dbo, title, username))
    return "\n".join(h)
Exemple #3
0
 def test_getters(self):
     fakesession = web.utils.storage(user="******",
                                     roles="",
                                     locale="en",
                                     dbo=base.get_dbo(),
                                     superuser=1,
                                     mobileapp=False)
     assert "" != reports.get_report_header(base.get_dbo(), "Test Report",
                                            "test")
     assert "" != reports.get_report_footer(base.get_dbo(), "Test Report",
                                            "test")
     assert len(reports.get_categories(base.get_dbo())) > 0
     assert "Test Report" == reports.get_title(base.get_dbo(), self.nid)
     assert self.nid == reports.get_id(base.get_dbo(), "Test Report")
     assert False == reports.is_mailmerge(base.get_dbo(), self.nid)
     assert True == reports.check_view_permission(fakesession, self.nid)
     reports.check_sql(base.get_dbo(), "test", TEST_QUERY)
     assert True == reports.is_valid_query(TEST_QUERY)
     assert "" != reports.generate_html(base.get_dbo(), "test", TEST_QUERY)
     assert "" != reports.get_reports_menu(base.get_dbo())
     reports.get_mailmerges_menu(base.get_dbo())
Exemple #4
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
Exemple #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