示例#1
0
def generate_person_doc(dbo, template, personid, username):
    """
    Generates a person document from a template
    template: The path/name of the template to use
    personid: The person to generate for
    """
    s = dbfs.get_string_id(dbo, template)
    p = person.get_person(dbo, personid)
    if p is None: raise utils.ASMValidationError("%d is not a valid person ID" % personid)
    tags = person_tags(dbo, p)
    tags = append_tags(tags, org_tags(dbo, username))
    s = substitute_tags(s, tags)
    return s
示例#2
0
def generate_donation_doc(dbo, template, donationid, username):
    """
    Generates a donation document from a template
    template: The path/name of the template to use
    donationid: The donation to generate for
    """
    s = dbfs.get_string_id(dbo, template)
    d = financial.get_donation(dbo, donationid)
    if d is None: raise utils.ASMValidationError("%d is not a valid donation ID" % donationid)
    tags = donation_tags(dbo, d)
    tags = append_tags(tags, person_tags(dbo, person.get_person(dbo, int(d["OWNERID"]))))
    if d["ANIMALID"] is not None and d["ANIMALID"] != 0:
        tags = append_tags(tags, animal_tags(dbo, animal.get_animal(dbo, d["ANIMALID"])))
    tags = append_tags(tags, org_tags(dbo, username))
    s = substitute_tags(s, tags)
    return s
示例#3
0
def generate_animal_doc(dbo, template, animalid, username):
    """
    Generates an animal document from a template using animal keys and
    (if a currentowner is available) person keys
    template: The path/name of the template to use
    animalid: The animal to generate for
    """
    s = dbfs.get_string_id(dbo, template)
    a = animal.get_animal(dbo, animalid)
    if a is None: raise utils.ASMValidationError("%d is not a valid animal ID" % animalid)
    tags = animal_tags(dbo, a)
    if a["CURRENTOWNERID"] is not None and a["CURRENTOWNERID"] != 0:
        tags = append_tags(tags, person_tags(dbo, person.get_person(dbo, int(a["CURRENTOWNERID"]))))
    tags = append_tags(tags, org_tags(dbo, username))
    s = substitute_tags(s, tags)
    return s
示例#4
0
def scale_all_pdf(dbo):
    """
    Goes through all PDFs in the database and attempts to scale them down.
    """
    mp = dbo.query("SELECT ID, MediaName FROM media WHERE MediaMimeType = 'application/pdf' ORDER BY ID DESC")
    total = 0
    for i, m in enumerate(mp):
        dbfsid = dbo.query_string("SELECT ID FROM dbfs WHERE Name = ?", [m.MEDIANAME])
        odata = dbfs.get_string_id(dbo, dbfsid)
        data = scale_pdf(odata)
        al.debug("scaling %s (%d of %d): old size %d, new size %d" % (m.MEDIANAME, i, len(mp), len(odata), len(data)), "check_and_scale_pdfs", dbo)
        # Store the new compressed PDF file data - if it's smaller
        if len(data) < len(odata):
            dbfs.put_string_id(dbo, dbfsid, m.MEDIANAME, data)
            dbo.update("media", m.ID, { "MediaSize": len(data) })
            total += 1
    al.debug("scaled %d of %d pdfs" % (total, len(mp)), "media.scale_all_pdf", dbo)