Beispiel #1
0
def get_animal_view_adoptable_js(dbo):
    """ Returns js that outputs adoptable animals into a host div """
    js = utils.read_text_file("%s/static/js/animal_view_adoptable.js" %
                              dbo.installpath)
    # inject adoptable animals, account and base url
    pc = PublishCriteria(configuration.publisher_presets(dbo))
    js = js.replace("{TOKEN_ACCOUNT}", dbo.database)
    js = js.replace("{TOKEN_BASE_URL}", BASE_URL)
    js = js.replace(
        "\"{TOKEN_ADOPTABLES}\"",
        utils.json(
            get_animal_data(dbo,
                            pc,
                            include_additional_fields=True,
                            strip_personal_data=True)))
    return js
Beispiel #2
0
def get_adoptable_animals(dbo,
                          style="",
                          speciesid=0,
                          animaltypeid=0,
                          locationid=0):
    """ Returns a page of adoptable animals.
    style: The HTML publishing template to use
    speciesid: 0 for all species, or a specific one
    animaltypeid: 0 for all animal types or a specific one
    locationid: 0 for all internal locations or a specific one
    """
    animals = get_animal_data(dbo, include_additional_fields=True)
    return animals_to_page(dbo,
                           animals,
                           style=style,
                           speciesid=speciesid,
                           animaltypeid=animaltypeid,
                           locationid=locationid)
Beispiel #3
0
def get_animal_view(dbo, animalid):
    """ Constructs the animal view page to the template. """
    a = dbo.first_row(
        get_animal_data(dbo,
                        animalid=animalid,
                        include_additional_fields=True,
                        strip_personal_data=True))
    # If the animal is not adoptable, bail out
    if a is None:
        raise utils.ASMPermissionError("animal is not adoptable (None)")
    if not is_animal_adoptable(dbo, a):
        raise utils.ASMPermissionError("animal is not adoptable (False)")
    # If the option is on, use animal comments as the notes
    if configuration.publisher_use_comments(dbo):
        a.WEBSITEMEDIANOTES = a.ANIMALCOMMENTS
    head, body, foot = get_animal_view_template(dbo)
    if head == "":
        head = "<!DOCTYPE html>\n<html>\n<head>\n<title>$$SHELTERCODE$$ - $$ANIMALNAME$$</title></head>\n<body>"
        body = "<h2>$$SHELTERCODE$$ - $$ANIMALNAME$$</h2><p><img src='$$WEBMEDIAFILENAME$$'/></p><p>$$WEBMEDIANOTES$$</p>"
        foot = "</body>\n</html>"
    if smcom.active():
        a.WEBSITEMEDIANAME = "%s?account=%s&method=animal_image&animalid=%d" % (
            SERVICE_URL, dbo.database, animalid)
    else:
        a.WEBSITEMEDIANAME = "%s?method=animal_image&animalid=%d" % (
            SERVICE_URL, animalid)
    s = head + body + foot
    tags = wordprocessor.animal_tags_publisher(dbo, a)
    tags = wordprocessor.append_tags(tags,
                                     wordprocessor.org_tags(dbo, "system"))
    # Add extra tags for websitemedianame2-10 if they exist
    for x in range(2, 11):
        if a.WEBSITEIMAGECOUNT > x - 1:
            tags["WEBMEDIAFILENAME%d" %
                 x] = "%s&seq=%d" % (a.WEBSITEMEDIANAME, x)
    # Add extra publishing text, preserving the line endings
    notes = utils.nulltostr(a.WEBSITEMEDIANOTES)
    notes += configuration.third_party_publisher_sig(dbo)
    notes = notes.replace("\n", "**le**")
    tags["WEBMEDIANOTES"] = notes
    tags["WEBSITEMEDIANOTES"] = notes
    s = wordprocessor.substitute_tags(s, tags, True, "$$", "$$")
    s = s.replace("**le**", "<br />")
    return s