def checkup_view(request): # Do some checks that can be presented on an unlinked page to be # verified either manually or by an automated functional test. # Check the number of images that have valid copyright holders. total_images = ContentImage.objects.count() copyright_holders = CopyrightHolder.objects.values_list('coded_name', flat=True) images_without_copyright = [] images = ContentImage.objects.all() for image in images: image_url = image.image.url copyright_holder = image_url.split('.')[-2] if re.search('-[a-z0-9]?$', copyright_holder): copyright_holder = copyright_holder[:-2] copyright_holder = copyright_holder.split('-')[-1] if copyright_holder not in copyright_holders: images_without_copyright.append(image_url) # To see which images do not have valid copyright holders, # temporarily enable this statement: #print 'Copyright holder %s not found: %s' % (copyright_holder, # image_url) images_copyright = total_images - len(images_without_copyright) return render_per_partner('checkup.html', { 'images_copyright': images_copyright, 'total_images': total_images, }, request)
def home_view(request): """View for the home page of the Go Botany site.""" partner = which_partner(request) # Get home page images for the partner home_page_images = HomePageImage.objects.filter(partner_site=partner) # Get or generate today's Plant of the Day, if appropriate. plant_of_the_day = PlantOfTheDay.get_by_date.for_day(date.today(), partner.short_name) plant_of_the_day_taxon = None if plant_of_the_day: # Get the Taxon record of the Plant of the Day. try: plant_of_the_day_taxon = Taxon.objects.get(scientific_name=plant_of_the_day.scientific_name) except ObjectDoesNotExist: pass plant_of_the_day_image = None species_images = botany.species_images(plant_of_the_day_taxon) if species_images: plant_of_the_day_image = botany.species_images(plant_of_the_day_taxon)[0] return render_per_partner( "home.html", { "home_page_images": home_page_images, "plant_of_the_day": plant_of_the_day_taxon, "plant_of_the_day_image": plant_of_the_day_image, }, request, )
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. Including # drawings here was planned early on but not finished for the # initial release. In the meantime, the first two species # images from the genus are shown. species = genus.taxa.all() for s in species: species_images = botany.species_images(s) if len(species_images) > 1: genus_drawings = species_images[0:2] break genus_drawings = _images_with_copyright_holders(genus_drawings) pile = genus.taxa.all()[0].piles.all()[0] pilegroup = pile.pilegroup return render_per_partner('genus.html', { 'genus': genus, 'common_name': common_name, 'genus_drawings': genus_drawings, 'pilegroup': pilegroup, 'pile': pile, }, request)
def getting_started_view(request): youtube_id = "" getting_started_video = Video.objects.get(title="Getting Started") if getting_started_video: youtube_id = getting_started_video.youtube_id return render_per_partner("getting_started.html", {"getting_started_youtube_id": youtube_id}, request)
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. Including # drawings here was planned early on but not finished for the # initial release. In the meantime, the first two species # images from the genus are shown. species = genus.taxa.all() for s in species: species_images = botany.species_images(s) if len(species_images) > 1: genus_drawings = species_images[0:2] break genus_drawings = _images_with_copyright_holders(genus_drawings) pile = genus.taxa.all()[0].piles.all()[0] pilegroup = pile.pilegroup return render_per_partner( 'genus.html', { 'genus': genus, 'common_name': common_name, 'genus_drawings': genus_drawings, 'pilegroup': pilegroup, 'pile': pile, }, request)
def checkup_view(request): # Do some checks that can be presented on an unlinked page to be # verified either manually or by an automated functional test. # Check the number of images that have valid copyright holders. total_images = ContentImage.objects.count() copyright_holders = CopyrightHolder.objects.values_list("coded_name", flat=True) images_without_copyright = [] images = ContentImage.objects.all() for image in images: image_url = image.image.url copyright_holder = image_url.split(".")[-2] if re.search("-[a-z0-9]?$", copyright_holder): copyright_holder = copyright_holder[:-2] copyright_holder = copyright_holder.split("-")[-1] if copyright_holder not in copyright_holders: images_without_copyright.append(image_url) # To see which images do not have valid copyright holders, # temporarily enable this statement: # print 'Copyright holder %s not found: %s' % (copyright_holder, # image_url) images_copyright = total_images - len(images_without_copyright) return render_per_partner( "checkup.html", {"images_copyright": images_copyright, "total_images": total_images}, request )
def home_view(request): """View for the home page of the Go Botany site.""" partner = which_partner(request) # Get home page images for the partner home_page_images = HomePageImage.objects.filter(partner_site=partner) # Get or generate today's Plant of the Day, if appropriate. plant_of_the_day = PlantOfTheDay.get_by_date.for_day( date.today(), partner.short_name) plant_of_the_day_taxon = None if plant_of_the_day: # Get the Taxon record of the Plant of the Day. try: plant_of_the_day_taxon = Taxon.objects.get( scientific_name=plant_of_the_day.scientific_name) except ObjectDoesNotExist: pass plant_of_the_day_image = None species_images = botany.species_images(plant_of_the_day_taxon) if species_images: plant_of_the_day_image = botany.species_images( plant_of_the_day_taxon)[0] return render_per_partner( 'home.html', { 'home_page_images': home_page_images, 'plant_of_the_day': plant_of_the_day_taxon, 'plant_of_the_day_image': plant_of_the_day_image, }, request)
def getting_started_view(request): youtube_id = '' getting_started_video = Video.objects.get(title='Getting Started') if getting_started_video: youtube_id = getting_started_video.youtube_id return render_per_partner('getting_started.html', { 'getting_started_youtube_id': youtube_id, }, request)
def atom_view(request): MAX_NUMBER_PLANTS = 15 partner_short_name = which_partner(request) plants_of_the_day = _get_plants_of_the_day(MAX_NUMBER_PLANTS, partner_short_name) return render_per_partner( "atom.xml", {"plants_of_the_day": plants_of_the_day}, request, content_type="application/atom+xml" )
def atom_view(request): MAX_NUMBER_PLANTS = 15 partner_short_name = which_partner(request) plants_of_the_day = _get_plants_of_the_day(MAX_NUMBER_PLANTS, partner_short_name) return render_per_partner('atom.xml', { 'plants_of_the_day': plants_of_the_day }, request, content_type='application/atom+xml')
def video_view(request): # The Getting Started video is first, followed by videos for the pile # groups and piles in the order that they are presented in the stepwise # pages at the beginning of plant identification. videos = [] getting_started_video = Video.objects.get(title="Getting Started") if getting_started_video: videos.append({"title": getting_started_video.title, "youtube_id": getting_started_video.youtube_id}) for pilegroup in ordered_pilegroups(): videos.append(_get_video_dict(pilegroup.friendly_title, pilegroup.video)) for pile in ordered_piles(pilegroup): videos.append(_get_video_dict(pile.friendly_title, pile.video)) return render_per_partner("video.html", {"videos": videos}, request)
def level3(request, key, pilegroup_slug, pile_slug): pile = get_object_or_404(Pile, slug=pile_slug) if pile.pilegroup.slug != pilegroup_slug: raise Http404 short_name = partner_short_name(request) subgroup_results_page = SubgroupResultsPage.objects.get(subgroup=pile) return render_per_partner('results.html', { 'dev_flag': 1 if request.GET.has_key('dev') else 0, 'key': key, 'partner_site': short_name, 'subgroup_results_page': subgroup_results_page, 'pilegroup': pile.pilegroup, 'pile': pile, }, request)
def level3(request, key, pilegroup_slug, pile_slug): pile = get_object_or_404(Pile, slug=pile_slug) if pile.pilegroup.slug != pilegroup_slug: raise Http404 short_name = partner_short_name(request) subgroup_results_page = SubgroupResultsPage.objects.get(subgroup=pile) return render_per_partner( 'results.html', { 'dev_flag': 1 if request.GET.has_key('dev') else 0, 'key': key, 'partner_site': short_name, 'subgroup_results_page': subgroup_results_page, 'pilegroup': pile.pilegroup, 'pile': pile, }, request)
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)
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)
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)
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)
def video_view(request): # The Getting Started video is first, followed by videos for the pile # groups and piles in the order that they are presented in the stepwise # pages at the beginning of plant identification. videos = [] getting_started_video = Video.objects.get(title='Getting Started') if getting_started_video: videos.append({ 'title': getting_started_video.title, 'youtube_id': getting_started_video.youtube_id }) for pilegroup in ordered_pilegroups(): videos.append( _get_video_dict(pilegroup.friendly_title, pilegroup.video)) for pile in ordered_piles(pilegroup): videos.append(_get_video_dict(pile.friendly_title, pile.video)) return render_per_partner('video.html', { 'videos': videos, }, request)
def glossary_view(request, letter): glossary = ( GlossaryTerm.objects.filter(visible=True).extra(select={"lower_term": "lower(term)"}).order_by("lower_term") ) terms = glossary.values_list("lower_term", flat=True) letters_in_glossary = [term[0] for term in terms] # Skip any glossary terms that start with a number, and filter to the # desired letter. glossary = glossary.filter(Q(term__startswith=letter) | Q(term__startswith=letter.upper()), term__gte="A") return render_per_partner( "glossary.html", { "this_letter": letter, "letters": string.ascii_lowercase, "letters_in_glossary": letters_in_glossary, "glossary": glossary, }, request, )
def glossary_view(request, letter): glossary = GlossaryTerm.objects.filter(visible=True).extra( select={ 'lower_term': 'lower(term)' }).order_by('lower_term') terms = glossary.values_list('lower_term', flat=True) letters_in_glossary = [term[0] for term in terms] # Skip any glossary terms that start with a number, and filter to the # desired letter. glossary = glossary.filter(Q(term__startswith=letter) | Q(term__startswith=letter.upper()), term__gte='A') return render_per_partner( 'glossary.html', { 'this_letter': letter, 'letters': string.ascii_lowercase, 'letters_in_glossary': letters_in_glossary, 'glossary': glossary, }, request)
def teaching_view(request): return render_per_partner('teaching.html', {}, request)
def species_list_view(request): partner = which_partner(request) plants_list = list( PartnerSpecies.objects.values( 'species__id', 'species__scientific_name', 'species__family__name', 'species__north_american_native', 'species__north_american_introduced', 'species__wetland_indicator_code', ).filter(partner=partner).order_by('species__scientific_name')) # Strip off the species__ prefix from the list's dictionary keys. for plant in plants_list: for key in plant: if '__' in key: new_key = key.replace('species__', '') plant[new_key] = plant.pop(key) # We build these three related lists manually instead of tempting # _get_plants() to return N * M copies of each plant. for plantdict in plants_list: plantdict['common_names'] = [] plantdict['pile_titles'] = [] plantdict['pilegroup_titles'] = [] plantdict['states'] = set() scientific_name = plantdict['scientific_name'] plantdict['genus'], plantdict['epithet'] = scientific_name.split()[:2] plantdict['lowgenus'] = plantdict['genus'].lower() plantmap = {plantdict['id']: plantdict for plantdict in plants_list} q = CommonName.objects.values_list('common_name', 'taxon_id') for common_name, taxon_id in q: if taxon_id in plantmap: plantmap[taxon_id]['common_names'].append(common_name) # Populate states from Distribution data. taxon_ids = list(plantmap.keys()) t = Taxon.objects.filter(id__in=taxon_ids).values_list( 'id', 'scientific_name') sci_names = list(set([name for id, name in t])) states = [state.upper() for state in list(settings.STATE_NAMES.keys())] d = Distribution.objects.filter(present=True).filter( county__exact='').filter(state__in=states).filter( species_name__in=sci_names).values_list('species_name', 'state') ids_by_name = {name: id for id, name in t} for scientific_name, state in d: taxon_id = ids_by_name[scientific_name] plantmap[taxon_id]['states'].add(state) q = Pile.species.through.objects.values_list( 'taxon_id', 'pile__friendly_title', 'pile__pilegroup__friendly_title', ) for taxon_id, pile_title, pilegroup_title in q: if taxon_id in plantmap: # Skip adding the "big Remaining Non-Monocots" pile's title, # since that pile has been split from the user's standpoint. # (Once the pile is fully split in the database, this check # can be removed.) if pile_title != 'All other herbaceous, flowering dicots': plantmap[taxon_id]['pile_titles'].append(pile_title) plantmap[taxon_id]['pilegroup_titles'].append(pilegroup_title) for plantdict in plants_list: plantdict['states'] = ' '.join(sorted(plantdict['states'])).upper() return render_per_partner('species_list.html', { 'plants': plants_list, }, request)
def contributors_view(request): return render_per_partner("contributors.html", {}, request)
def maps_test_view(request): return render_per_partner('maps_test.html', {}, request)
def species_list_view(request): partner = which_partner(request) plants_list = list( PartnerSpecies.objects.values( "species__id", "species__scientific_name", "species__family__name", "species__north_american_native", "species__north_american_introduced", "species__wetland_indicator_code", ) .filter(partner=partner) .order_by("species__scientific_name") ) # Strip off the species__ prefix from the list's dictionary keys. for plant in plants_list: for key in plant: if "__" in key: new_key = key.replace("species__", "") plant[new_key] = plant.pop(key) # We build these three related lists manually instead of tempting # _get_plants() to return N * M copies of each plant. for plantdict in plants_list: plantdict["common_names"] = [] plantdict["pile_titles"] = [] plantdict["pilegroup_titles"] = [] plantdict["states"] = set() scientific_name = plantdict["scientific_name"] plantdict["genus"], plantdict["epithet"] = scientific_name.split()[:2] plantdict["lowgenus"] = plantdict["genus"].lower() plantmap = {plantdict["id"]: plantdict for plantdict in plants_list} q = CommonName.objects.values_list("common_name", "taxon_id") for common_name, taxon_id in q: if taxon_id in plantmap: plantmap[taxon_id]["common_names"].append(common_name) # Populate states from Distribution data. taxon_ids = plantmap.keys() t = Taxon.objects.filter(id__in=taxon_ids).values_list("id", "scientific_name") sci_names = list(set([name for id, name in t])) states = [state.upper() for state in settings.STATE_NAMES.keys()] d = ( Distribution.objects.filter(present=True) .filter(county__exact="") .filter(state__in=states) .filter(species_name__in=sci_names) .values_list("species_name", "state") ) ids_by_name = {name: id for id, name in t} for scientific_name, state in d: taxon_id = ids_by_name[scientific_name] plantmap[taxon_id]["states"].add(state) q = Pile.species.through.objects.values_list("taxon_id", "pile__friendly_title", "pile__pilegroup__friendly_title") for taxon_id, pile_title, pilegroup_title in q: if taxon_id in plantmap: # Skip adding the "big Remaining Non-Monocots" pile's title, # since that pile has been split from the user's standpoint. # (Once the pile is fully split in the database, this check # can be removed.) if pile_title != "All other herbaceous, flowering dicots": plantmap[taxon_id]["pile_titles"].append(pile_title) plantmap[taxon_id]["pilegroup_titles"].append(pilegroup_title) for plantdict in plants_list: plantdict["states"] = " ".join(sorted(plantdict["states"])).upper() return render_per_partner("species_list.html", {"plants": plants_list}, request)
def system_requirements_view(request): return render_per_partner('system_requirements.html', {}, request)
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(Taxon, 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] dkey_pages = dkey_models.Page.objects.filter(title=scientific_name) dkey_page = dkey_pages[0] if dkey_pages else None dkey_hybrids = (dkey_models.Hybrid.objects.filter( Q(scientific_name1=scientific_name) | Q(scientific_name2=scientific_name)).order_by('number1', 'number2')) 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' 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) } # If no preview characteristics are defined for a partner, use the # ones defined for Go Botany. if len(plant_preview_characters) == 0: gobotany = PartnerSite.objects.get(short_name='gobotany') plant_preview_characters = { ppc.character_id: ppc.order for ppc in PlantPreviewCharacter.objects.filter( pile=pile, partner_site=gobotany) } # 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 # TODO: eventually remove this temporary code after the Remaining # Non-Monocots pile character value data is split and assigned. if pile.name.find('Remaining Non-Monocots') > -1: try: # Include the big pile which has the character value data. big_pile = Pile.objects.get(name='Remaining Non-Monocots') pile_ids = pile_ids + (big_pile.id, ) except models.Pile.DoesNotExist: pass # (end of temporary code) 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), '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) statuses = taxon.conservation_statuses.values_list( 'variety_subspecies_hybrid', 'region', 's_rank', 'endangerment_code') statuses_state_names = [{ 'variety_subspecies_hybrid': variety_subspecies_hybrid, 'state': settings.STATE_NAMES[region.lower()], 's_rank': s_rank, 'endangerment_code': endangerment_code } for (variety_subspecies_hybrid, region, s_rank, endangerment_code) in statuses] conservation_statuses = sorted( statuses_state_names, key=lambda k: (k['variety_subspecies_hybrid'], k['state'])) return render_per_partner( '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 'dkey_hybrids': dkey_hybrids, 'dkey_page': dkey_page, '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, 'compact_multivalue_characters': COMPACT_MULTIVALUE_CHARACTERS, 'brief_characteristics': preview_characters, 'all_characteristics': all_characteristics, 'epithet': epithet, 'native_to_north_america': native_to_north_america, 'conservation_statuses': conservation_statuses, 'prior_signup_detected': prior_signup_detected(request), }, request)
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(Taxon, 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] dkey_pages = dkey_models.Page.objects.filter(title=scientific_name) dkey_page = dkey_pages[0] if dkey_pages else None dkey_hybrids = (dkey_models.Hybrid.objects .filter(Q(scientific_name1=scientific_name) | Q(scientific_name2=scientific_name)) .order_by('number1', 'number2')) 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' 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) } # If no preview characteristics are defined for a partner, use the # ones defined for Go Botany. if len(plant_preview_characters) == 0: gobotany = PartnerSite.objects.get(short_name='gobotany') plant_preview_characters = { ppc.character_id: ppc.order for ppc in PlantPreviewCharacter.objects.filter(pile=pile, partner_site=gobotany) } # 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 # TODO: eventually remove this temporary code after the Remaining # Non-Monocots pile character value data is split and assigned. if pile.name.find('Remaining Non-Monocots') > -1: try: # Include the big pile which has the character value data. big_pile = Pile.objects.get(name='Remaining Non-Monocots') pile_ids = pile_ids + (big_pile.id,) except models.Pile.DoesNotExist: pass # (end of temporary code) 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), '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) statuses = taxon.conservation_statuses.values_list( 'variety_subspecies_hybrid', 'region', 's_rank', 'endangerment_code') statuses_state_names = [ {'variety_subspecies_hybrid': variety_subspecies_hybrid, 'state': settings.STATE_NAMES[region.lower()], 's_rank': s_rank, 'endangerment_code': endangerment_code} for (variety_subspecies_hybrid, region, s_rank, endangerment_code) in statuses] conservation_statuses = sorted(statuses_state_names, key=lambda k: (k['variety_subspecies_hybrid'], k['state'])) return render_per_partner('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 'dkey_hybrids': dkey_hybrids, 'dkey_page': dkey_page, '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, 'compact_multivalue_characters': COMPACT_MULTIVALUE_CHARACTERS, 'brief_characteristics': preview_characters, 'all_characteristics': all_characteristics, 'epithet': epithet, 'native_to_north_america': native_to_north_america, 'conservation_statuses': conservation_statuses, 'prior_signup_detected': prior_signup_detected(request), }, request)
def help_view(request): return render_per_partner('help.html', {}, request)
def contact_view(request): return render_per_partner("contact.html", {}, request)
def privacy_view(request): return render_per_partner("privacy.html", {}, request)
def updates_family_view(request): updates = Update.objects.all().order_by('family', '-date') return render_per_partner('updates_family.html', { 'updates': updates, }, request)
def updates_date_view(request): updates = Update.objects.all() return render_per_partner('updates.html', { 'updates': updates, }, request)
def about_view(request): return render_per_partner('about.html', {}, request)
def contributors_view(request): return render_per_partner('contributors.html', {}, request)
def terms_of_use_view(request): site_url = request.build_absolute_uri(reverse("site-home")) return render_per_partner("terms.html", {"site_url": site_url}, request)
def advanced_map_view(request): pilegroups = [(pilegroup, ordered_piles(pilegroup)) for pilegroup in ordered_pilegroups()] return render_per_partner("advanced_map.html", {"pilegroups": pilegroups}, request)
def help_dkey_view(request): return render_per_partner("help_dkey.html", {}, request)
def about_view(request): return render_per_partner("about.html", {}, request)
def system_requirements_view(request): return render_per_partner("system_requirements.html", {}, request)
def contact_view(request): return render_per_partner('contact.html', {}, request)
def teaching_view(request): return render_per_partner("teaching.html", {}, request)
def privacy_view(request): return render_per_partner('privacy.html', {}, request)
def terms_of_use_view(request): site_url = request.build_absolute_uri('/') return render_per_partner('terms.html', { 'site_url': site_url, }, request)
def advanced_map_view(request): pilegroups = [(pilegroup, ordered_piles(pilegroup)) for pilegroup in ordered_pilegroups()] return render_per_partner('advanced_map.html', {'pilegroups': pilegroups}, request)
def maps_test_view(request): return render_per_partner("maps_test.html", {}, request)