Exemple #1
0
def genus_view(request, genus_slug):

    genus_name = genus_slug.capitalize()
    genus = get_object_or_404(Genus, name=genus_name)

    # If it is decided that common names will not be required, change the
    # default below to None so the template will omit the name if missing.
    DEFAULT_COMMON_NAME = 'common name here'
    common_name = genus.common_name or DEFAULT_COMMON_NAME

    genus_drawings = genus.images.filter(image_type__name='example drawing')
    if not genus_drawings:
        # No example drawings for this genus were specified.
        # Use 2 images from the genus's species instead.
        species = genus.taxa.all()
        genus_drawings = []
        for s in species:
            species_images = botany.species_images(s, image_types='flowers,inflorescences')
            if len(species_images):
                genus_drawings.append(species_images[0])
                if len(genus_drawings) == 2:
                    break
    genus_drawings = _images_with_copyright_holders(genus_drawings)

    pile = genus.taxa.all()[0].piles.all()[0]
    pilegroup = pile.pilegroup

    return render_to_response('gobotany/genus.html', {
        'genus': genus,
        'common_name': common_name,
        'genus_drawings': genus_drawings,
        'pilegroup': pilegroup,
        'pile': pile,
        }, context_instance=RequestContext(request))
Exemple #2
0
def level1(request, key):
    short_name = partner_short_name(request)
    groups_list_page = GroupsListPage.objects.get()

    pilegroups = []
    for pilegroup in ordered_pilegroups():
        images = _images_with_copyright_holders(
            ContentImage.objects.filter(
                pilegroupimage__pile_group=pilegroup)
            .select_related('image_type'))
        pilegroups.append((pilegroup, images, get_simple_url(key, pilegroup)))

    return render_per_partner('simple.html', {
                'partner_site': short_name,
                'groups_list_page': groups_list_page,
                'key': key,
                'pilegroups': pilegroups
                }, request)
Exemple #3
0
def level1(request, key):
    short_name = partner_short_name(request)
    groups_list_page = GroupsListPage.objects.get()

    pilegroups = []
    for pilegroup in ordered_pilegroups():
        images = _images_with_copyright_holders(
            ContentImage.objects.filter(pilegroupimage__pile_group=pilegroup).
            select_related('image_type'))
        pilegroups.append((pilegroup, images, get_simple_url(key, pilegroup)))

    return render_per_partner(
        'simple.html', {
            'partner_site': short_name,
            'groups_list_page': groups_list_page,
            'key': key,
            'pilegroups': pilegroups
        }, request)
Exemple #4
0
def level2(request, key, pilegroup_slug):
    pilegroup = get_object_or_404(PileGroup, slug=pilegroup_slug)

    short_name = partner_short_name(request)
    subgroups_list_page = SubgroupsListPage.objects.get(group=pilegroup)

    piles = []
    for pile in ordered_piles(pilegroup):
        images = _images_with_copyright_holders(
            ContentImage.objects.filter(pileimage__pile=pile)
            .select_related('image_type'))
        piles.append((pile, images, get_simple_url(key, pilegroup, pile)))

    return render_per_partner('pilegroup.html', {
                'partner_site': short_name,
                'subgroups_list_page': subgroups_list_page,
                'key': key,
                'pilegroup': pilegroup,
                'piles': piles
                }, request)
Exemple #5
0
def level2(request, key, pilegroup_slug):
    pilegroup = get_object_or_404(PileGroup, slug=pilegroup_slug)

    short_name = partner_short_name(request)
    subgroups_list_page = SubgroupsListPage.objects.get(group=pilegroup)

    piles = []
    for pile in ordered_piles(pilegroup):
        images = _images_with_copyright_holders(
            ContentImage.objects.filter(
                pileimage__pile=pile).select_related('image_type'))
        piles.append((pile, images, get_simple_url(key, pilegroup, pile)))

    return render_per_partner(
        'pilegroup.html', {
            'partner_site': short_name,
            'subgroups_list_page': subgroups_list_page,
            'key': key,
            'pilegroup': pilegroup,
            'piles': piles
        }, request)
Exemple #6
0
def family_view(request, family_slug):

    family_name = family_slug.capitalize()
    family = get_object_or_404(Family, name=family_name)

    # If it is decided that common names will not be required, change the
    # default below to None so the template will omit the name if missing.
    DEFAULT_COMMON_NAME = 'common name here'
    common_name = family.common_name or DEFAULT_COMMON_NAME

    family_drawings = (family.images.filter(
        image_type__name='example drawing'))
    if not family_drawings:
        # No example drawings for this family were specified.
        # Use 2 images from the family's species instead.
        species = family.taxa.all()
        family_drawings = []
        for s in species:
            species_images = botany.species_images(
                s, image_types='flowers,inflorescences')
            if len(species_images):
                family_drawings.append(species_images[0])
                if len(family_drawings) == 2:
                    break
    family_drawings = _images_with_copyright_holders(family_drawings)

    pile = family.taxa.all()[0].piles.all()[0]
    pilegroup = pile.pilegroup

    return render_to_response('gobotany/family.html', {
        'family': family,
        'common_name': common_name,
        'family_drawings': family_drawings,
        'pilegroup': pilegroup,
        'pile': pile,
    },
                              context_instance=RequestContext(request))
Exemple #7
0
def species_view(request, genus_slug, epithet):

    COMPACT_MULTIVALUE_CHARACTERS = ['Habitat', 'New England state',
                                     'Specific Habitat']

    genus_name = genus_slug.capitalize()
    scientific_name = '%s %s' % (genus_name, epithet)
    taxon = get_object_or_404(GoOrchidTaxon, scientific_name=scientific_name)

    scientific_name_short = '%s. %s' % (scientific_name[0], epithet)

    pile_slug = request.GET.get('pile')
    if pile_slug:
        pile = get_object_or_404(Pile, slug=pile_slug)
    else:
        # Randomly grab the first pile from the species
        pile = taxon.piles.order_by('id')[0]
    pilegroup = pile.pilegroup

    partner = which_partner(request)
    partner_species = None
    if partner:
        rows = PartnerSpecies.objects.filter(
            species=taxon, partner=partner).all()
        if rows:
            partner_species = rows[0]

    species_in_simple_key = (partner_species and partner_species.simple_key)
    key = request.GET.get('key')
    if not key:
        if species_in_simple_key:
            key = 'simple'
        else:
            key = 'full'

    if hasattr(taxon, 'taxon_ptr'):
        species_images = botany.species_images(taxon.taxon_ptr)
    if len(species_images) == 0:
        species_images = botany.species_images(taxon)

    images = _images_with_copyright_holders(species_images)

    # Get the set of preview characteristics.

    plant_preview_characters = {
        ppc.character_id: ppc.order for ppc in
        PlantPreviewCharacter.objects.filter(pile=pile, partner_site=partner)
    }

    # Select ALL character values for this taxon.

    character_values = list(taxon.character_values.select_related(
        'character', 'character__character_group'))

    # Throw away values for characters that are not part of this pile.

    pile_ids = (None, pile.id)  # characters like 'habitat' have pile_id None
    character_values = [v for v in character_values
                        if v.character.pile_id in pile_ids]

    # Create a tree of character groups, characters, and values.

    get_group_name = lambda v: v.character.character_group.name
    get_character_name = lambda v: v.character.friendly_name

    character_values.sort(key=get_character_name)
    character_values.sort(key=get_group_name)

    all_characteristics = []
    for group_name, seq1 in groupby(character_values, get_group_name):
        characters = []

        for character_name, seq2 in groupby(seq1, get_character_name):
            seq2 = list(seq2)
            character = seq2[0].character  # arbitrary; all look the same
            characters.append({
                'group': character.character_group.name,
                'name': character.friendly_name,
                'values': sorted((_format_character_value(v) for v in seq2),
                                 cmp=_compare_character_values),
                'in_preview': character.id in plant_preview_characters,
                'preview_order': plant_preview_characters.get(character.id, -1),
            })

        all_characteristics.append({
            'name': group_name,
            'characters': characters
        })

    # Pick out the few preview characters for separate display.

    preview_characters = sorted((
        character
        for group in all_characteristics
        for character in group['characters']
        if character['in_preview']
    ), key=itemgetter('preview_order'))

    native_to_north_america = _native_to_north_america_status(taxon)

    return render_to_response('gobotany/species.html', {
        'pilegroup': pilegroup,
        'pile': pile,
        'scientific_name': scientific_name,
        'scientific_name_short': scientific_name_short,
        'taxon': taxon,
        'key': key,
        'species_in_simple_key': species_in_simple_key,
        'common_names': taxon.common_names.all(),  # view uses this 3 times
        'images': images,
        'partner_heading': partner_species.species_page_heading
            if partner_species else None,
        'partner_blurb': partner_species.species_page_blurb
            if partner_species else None,
        'ready_for_display': taxon.ready_for_display,
        'compact_multivalue_characters': COMPACT_MULTIVALUE_CHARACTERS,
        'brief_characteristics': preview_characters,
        'all_characteristics': all_characteristics,
        'epithet': epithet,
        'native_to_north_america': native_to_north_america
    }, context_instance=RequestContext(request))
Exemple #8
0
def species_view(request, genus_slug, epithet):

    COMPACT_MULTIVALUE_CHARACTERS = [
        'Habitat', 'New England state', 'Specific Habitat'
    ]

    genus_name = genus_slug.capitalize()
    scientific_name = '%s %s' % (genus_name, epithet)
    taxon = get_object_or_404(GoOrchidTaxon, scientific_name=scientific_name)

    scientific_name_short = '%s. %s' % (scientific_name[0], epithet)

    pile_slug = request.GET.get('pile')
    if pile_slug:
        pile = get_object_or_404(Pile, slug=pile_slug)
    else:
        # Randomly grab the first pile from the species
        pile = taxon.piles.order_by('id')[0]
    pilegroup = pile.pilegroup

    partner = which_partner(request)
    partner_species = None
    if partner:
        rows = PartnerSpecies.objects.filter(species=taxon,
                                             partner=partner).all()
        if rows:
            partner_species = rows[0]

    species_in_simple_key = (partner_species and partner_species.simple_key)
    key = request.GET.get('key')
    if not key:
        if species_in_simple_key:
            key = 'simple'
        else:
            key = 'full'

    if hasattr(taxon, 'taxon_ptr'):
        species_images = botany.species_images(taxon.taxon_ptr)
    if len(species_images) == 0:
        species_images = botany.species_images(taxon)

    images = _images_with_copyright_holders(species_images)

    # Get the set of preview characteristics.

    plant_preview_characters = {
        ppc.character_id: ppc.order
        for ppc in PlantPreviewCharacter.objects.filter(pile=pile,
                                                        partner_site=partner)
    }

    # Select ALL character values for this taxon.

    character_values = list(
        taxon.character_values.select_related('character',
                                              'character__character_group'))

    # Throw away values for characters that are not part of this pile.

    pile_ids = (None, pile.id)  # characters like 'habitat' have pile_id None
    character_values = [
        v for v in character_values if v.character.pile_id in pile_ids
    ]

    # Create a tree of character groups, characters, and values.

    get_group_name = lambda v: v.character.character_group.name
    get_character_name = lambda v: v.character.friendly_name

    character_values.sort(key=get_character_name)
    character_values.sort(key=get_group_name)

    all_characteristics = []
    for group_name, seq1 in groupby(character_values, get_group_name):
        characters = []

        for character_name, seq2 in groupby(seq1, get_character_name):
            seq2 = list(seq2)
            character = seq2[0].character  # arbitrary; all look the same
            characters.append({
                'group':
                character.character_group.name,
                'name':
                character.friendly_name,
                'values':
                sorted((_format_character_value(v) for v in seq2),
                       cmp=_compare_character_values),
                'in_preview':
                character.id in plant_preview_characters,
                'preview_order':
                plant_preview_characters.get(character.id, -1),
            })

        all_characteristics.append({
            'name': group_name,
            'characters': characters
        })

    # Pick out the few preview characters for separate display.

    preview_characters = sorted(
        (character for group in all_characteristics
         for character in group['characters'] if character['in_preview']),
        key=itemgetter('preview_order'))

    native_to_north_america = _native_to_north_america_status(taxon)

    return render_to_response(
        'gobotany/species.html',
        {
            'pilegroup':
            pilegroup,
            'pile':
            pile,
            'scientific_name':
            scientific_name,
            'scientific_name_short':
            scientific_name_short,
            'taxon':
            taxon,
            'key':
            key,
            'species_in_simple_key':
            species_in_simple_key,
            'common_names':
            taxon.common_names.all(),  # view uses this 3 times
            'images':
            images,
            'partner_heading':
            partner_species.species_page_heading if partner_species else None,
            'partner_blurb':
            partner_species.species_page_blurb if partner_species else None,
            'ready_for_display':
            taxon.ready_for_display,
            'compact_multivalue_characters':
            COMPACT_MULTIVALUE_CHARACTERS,
            'brief_characteristics':
            preview_characters,
            'all_characteristics':
            all_characteristics,
            'epithet':
            epithet,
            'native_to_north_america':
            native_to_north_america
        },
        context_instance=RequestContext(request))