Permalink
Browse files

factsheet link to plates, admin sorting options, readable stats, brow…

…se styling
  • Loading branch information...
philipbjorge committed Jun 28, 2012
1 parent c339a67 commit 4389bbfea352e87ef2f297feb0d6b23115513213
@@ -115,6 +115,7 @@
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
+ 'django.contrib.humanize',
'cms',
'cms.plugins.text',
'cms.plugins.picture',
@@ -134,6 +135,8 @@
'south',
'reversion',
'ajax_select',
+ 'paging',
+ 'admin_sentry',
)
CMS_TEMPLATES = (
@@ -142,6 +145,7 @@
('cms/home.html', gettext('home')),
('cms/browse.html', gettext('browse')),
('cms/factsheet.html', gettext('factsheet')),
+ ('cms/plateimages.html', gettext('imageplates')),
)
CMS_SHOW_END_DATE = True
CMS_SHOW_START_DATE = True
@@ -33,7 +33,7 @@ class AuthorAdmin(VersionAdmin, admin.ModelAdmin):
class SpeciesAdmin(VersionAdmin, admin.ModelAdmin):
filter_horizontal = ("similar",)
- list_display = ("__unicode__", "noc_id", "factsheet", "common_name")
+ list_display = ("__unicode__", "noc_id", "factsheet", "authority", "common_name")
list_editable = ("common_name",)
search_fields = ("genus", "species")
admin.site.register(Species, SpeciesAdmin)
@@ -48,10 +48,16 @@ def noc_id(self):
return self.species.noc_id
noc_id.admin_order_field = 'species__noc_id'
+ def collection(self):
+ return self.record.collection
+ collection.admin_order_field = 'record__collection'
+
list_display = (
noc_id,
"species",
"image",
+ collection,
+ "photographer",
"weight"
)
list_editable = ("weight",)
@@ -71,13 +77,14 @@ def noc_id(self):
noc_id.admin_order_field = 'species__noc_id'
def thumb(self):
- t = self.speciesimage_set.all()
+ t = self.speciesimage_set.all()[:1].get()
if t:
- pk = t[0].pk
- t = get_thumbnail(t[0].image,"70x46")
+ pk = t.pk
+ t = get_thumbnail(t.image,"70x46")
return u'<a href="%s" target="_blank"><img src="%s" /></a>' % (urlresolvers.reverse('admin:species_speciesimage_change', args=(pk,)), t.url)
else:
return u"None"
+ thumb.admin_order_field = 'speciesimage'
thumb.short_description = 'Photo'
thumb.allow_tags = True
@@ -327,19 +327,24 @@ def clean(self):
genus = None
if genus and species:
- species_instance, created = Species.objects.get_or_create(
- genus=genus,
- species=species
- )
- cleaned_data["species"] = species_instance
-
- # If a Species instance doesn't exist for the given data, alert the
- # user.
- if not isinstance(cleaned_data.get("species"), Species):
- # Delete the species entry from cleaned data if it is defined.
- if cleaned_data.get("species"):
- del cleaned_data["species"]
- raise forms.ValidationError("Species isn't defined.")
+ try:
+ species_instance = Species.objects.get(
+ genus=genus,
+ species=species
+ )
+ cleaned_data["species"] = species_instance
+ except Exception:
+ if cleaned_data.get("genus"):
+ del self.cleaned_data["genus"]
+ if cleaned_data.get("species"):
+ del self.cleaned_data["species"]
+ raise forms.ValidationError("Species does not exist.")
+ else:
+ if cleaned_data.get("genus"):
+ del self.cleaned_data["genus"]
+ if cleaned_data.get("species"):
+ del self.cleaned_data["species"]
+ raise forms.ValidationError("Need a genus and species")
if cleaned_data.get("county") is not None:
county = cleaned_data.get("county").strip()
@@ -0,0 +1,18 @@
+from django.core.management.base import NoArgsCommand, CommandError
+from cms.plugins.text.models import Text
+from reversion import revision
+import re
+
+class Command(NoArgsCommand):
+
+ @revision.create_on_success
+ def handle_noargs(self, **options):
+ """
+ Removes inline styles from wymeditor text to make it simpler
+ to fix the bug in wym that adds a checkered background to content.
+ """
+ text_objs = Text.objects.all()
+ for obj in text_objs:
+ # Removes inline styles
+ obj.body = re.sub(' style=("|\')(.*?)("|\')', "", obj.body)
+ obj.save()
@@ -1,6 +1,6 @@
from django import template
from pnwmoths.species.models import State, SpeciesRecord
-import json
+import json, re
register = template.Library()
@@ -30,6 +30,10 @@ def filters_json(value, arg):
"""
Returns Array with extra values removed based on species
"""
+ def _human_key(key):
+ parts = re.split('(\d*\.\d+|\d+)', key)
+ return tuple((e.swapcase() if i % 2 == 0 else float(e)) for i, e in enumerate(parts))
+
if arg == "county":
states = list(State.objects.all().values_list())
state_lookup = dict()
@@ -38,4 +42,5 @@ def filters_json(value, arg):
state_lookup[s_id] = code
return str(sorted([str("%s (%s)" % (item[0], state_lookup.get(item[1], "CANADA"))) for item in set(value.speciesrecord_set.all().values_list('county__name', 'county__state'))])).replace("'", '"')
- return str(sorted([str(item) for item in set(value.speciesrecord_set.all().values_list(arg, flat=True))])).replace("'", '"')
+ # filter removes None elements, human sort sorts in expected order
+ return str(sorted([str(str(item)[0].capitalize() + str(item)[1:]) for item in set(filter(None, value.speciesrecord_set.all().values_list(arg, flat=True)))], key=_human_key)).replace("'", '"')
@@ -2,6 +2,7 @@
from django.db.models import F
from cms.models.pagemodel import Page
from django.db.models.loading import get_model
+from django.contrib.humanize.templatetags.humanize import intcomma
register = template.Library()
@register.filter
@@ -13,7 +14,10 @@ def species_stat_count(value):
"""
try:
if value == 'SpeciesRecord':
- return get_model('species', value).records.count()
- return get_model('species', value).objects.count()
+ r_count = get_model('species', value).records.count()
+ else:
+ r_count = get_model('species', value).objects.count()
+ # return formatted count
+ return intcomma(r_count)
except (Exception):
return ""
@@ -68,7 +68,7 @@ <h1 id="header-text">Pacific Northwest <span id="header-green">Moths</span></h1>
</div>
<div class="col_4 last">
<form method="get" action="/search/">
- <input type="text" name="search" id="search_box" class="inputBox" />
+ <input type="text" name="q" id="search_box" class="inputBox" />
<input type="submit" value="search" id="search_button" class="submitButton" />
</form>
</div>
@@ -71,6 +71,7 @@ <h2 style="display: inline" class="fs_title"><em>{{ species.name }}</em> {% if s
</div>
<div class="col_4 last">
{% if species.noc_id %}<h3 class="fs_subtitle">{{ species.noc_id }}</h3>{% endif %}
+ {% if species.image_plate %}<h3 class="fs_subtitle"><a href="/photographic-plates/{{ species.image_plate.pk }}/" target="_blank">View Photographic Plate</a></h3>{% endif %}
</div>
</div>
<div id="fs_yui-g" class="row">
@@ -163,15 +164,17 @@ <h3>
<div id="chartpseudotooltip"></div>
<div id="factsheet-filters">
<h4>Data Filters</h4>
- <select class="third" id="f-county" multiple="multiple">
+ <select class="half" id="f-county" multiple="multiple">
</select>
- <select class="third" id="f-state" multiple="multiple">
+ <select class="half" id="f-state" multiple="multiple">
</select>
- <select class="third" id="f-collection" multiple="multiple">
+ <select class="half" id="f-collection" multiple="multiple">
</select>
- <select class="third" id="f-year" multiple="multiple"><option value="2012">2012</option><option value="2011">2011</option><option value="2010">2010</option><option value="2009">2009</option><option value="2008">2008</option><option value="2007">2007</option><option value="2006">2006</option><option value="2005">2005</option><option value="2004">2004</option><option value="2003">2003</option><option value="2002">2002</option><option value="2001">2001</option><option value="2000">2000</option><option value="1999">1999</option><option value="1998">1998</option><option value="1997">1997</option><option value="1996">1996</option><option value="1995">1995</option><option value="1994">1994</option><option value="1993">1993</option><option value="1992">1992</option><option value="1991">1991</option><option value="1990">1990</option><option value="1989">1989</option><option value="1988">1988</option><option value="1987">1987</option><option value="1986">1986</option><option value="1985">1985</option><option value="1984">1984</option><option value="1983">1983</option><option value="1982">1982</option><option value="1981">1981</option><option value="1980">1980</option><option value="1979">1979</option><option value="1978">1978</option><option value="1977">1977</option><option value="1976">1976</option><option value="1975">1975</option><option value="1974">1974</option><option value="1973">1973</option><option value="1972">1972</option><option value="1971">1971</option><option value="1970">1970</option><option value="1969">1969</option><option value="1968">1968</option><option value="1967">1967</option><option value="1966">1966</option><option value="1965">1965</option><option value="1964">1964</option><option value="1963">1963</option><option value="1962">1962</option><option value="1961">1961</option><option value="1960">1960</option><option value="1959">1959</option><option value="1958">1958</option><option value="1957">1957</option><option value="1956">1956</option><option value="1955">1955</option><option value="1954">1954</option><option value="1953">1953</option><option value="1952">1952</option><option value="1951">1951</option><option value="1950">1950</option><option value="1949">1949</option><option value="1948">1948</option><option value="1947">1947</option><option value="1946">1946</option><option value="1945">1945</option><option value="1944">1944</option><option value="1943">1943</option><option value="1942">1942</option><option value="1941">1941</option><option value="1940">1940</option><option value="1939">1939</option><option value="1938">1938</option><option value="1937">1937</option><option value="1936">1936</option><option value="1935">1935</option><option value="1934">1934</option><option value="1933">1933</option><option value="1932">1932</option><option value="1931">1931</option><option value="1930">1930</option><option value="1929">1929</option><option value="1928">1928</option><option value="1927">1927</option><option value="1926">1926</option><option value="1925">1925</option><option value="1924">1924</option><option value="1923">1923</option><option value="1922">1922</option><option value="1921">1921</option><option value="1920">1920</option><option value="1919">1919</option><option value="1918">1918</option><option value="1917">1917</option><option value="1916">1916</option><option value="1915">1915</option><option value="1914">1914</option><option value="1913">1913</option><option value="1912">1912</option><option value="1911">1911</option><option value="1910">1910</option><option value="1909">1909</option><option value="1908">1908</option><option value="1907">1907</option><option value="1906">1906</option><option value="1905">1905</option><option value="1904">1904</option><option value="1903">1903</option><option value="1902">1902</option><option value="1901">1901</option><option value="1900">1900</option></select>
- <select class="third" id="f-month" multiple="multiple"><option value='01'>January</option><option value='02'>February</option><option value='03'>March</option><option value='04'>April</option><option value='05'>May</option><option value='06'>June</option><option value='07'>July</option><option value='08'>August</option><option value='09'>September</option><option value='10'>October</option><option value='11'>November</option><option value='12'>December</option></select>
- <select class="third" id="f-day" multiple="multiple"><option value='01'>01</option><option value='02'>02</option><option value='03'>03</option><option value='04'>04</option><option value='05'>05</option><option value='06'>06</option><option value='07'>07</option><option value='08'>08</option><option value='09'>09</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option><option value='23'>23</option><option value='24'>24</option><option value='25'>25</option><option value='26'>26</option><option value='27'>27</option><option value='28'>28</option><option value='29'>29</option><option value='30'>30</option><option value='31'>31</option></select>
+ <select class="half" id="f-record_type" multiple="multiple">
+ </select>
+ <select class="third" id="f-year" multiple="multiple"></select>
+ <select class="third" id="f-month" multiple="multiple"></select>
+ <select class="third" id="f-day" multiple="multiple"></select>
<div id="date-filter-1" class="whole" style="padding-top: 50px">
<div id="f-date"></div>
</div>
@@ -213,6 +216,18 @@ <h6 style="color: grey; margin-top: 0; margin-left: 30px">Elevation (ft)</h6>
<span class="dokuwiki-data" id="collection-data">
{{ species|filters_json:"collection__name"|safe }}
</span>
+ <span class="dokuwiki-data" id="record_type-data">
+ {{ species|filters_json:"record_type"|safe }}
+ </span>
+ <span class="dokuwiki-data" id="year-data">
+ {{ species|filters_json:"year"|safe }}
+ </span>
+ <span class="dokuwiki-data" id="month-data">
+ {{ species|filters_json:"month"|safe }}
+ </span>
+ <span class="dokuwiki-data" id="day-data">
+ {{ species|filters_json:"day"|safe }}
+ </span>
{% endcache %}
{% endif %}
<!-- data stop -->
@@ -1,5 +1,5 @@
{% extends "cms/base.html" %}
-{% load cache cms_tags menu_tags species_tags browse_filters stats_filters %}
+{% load cache cms_tags menu_tags humanize species_tags browse_filters stats_filters %}
{% block scripts %}
{{ block.super }}
@@ -31,10 +31,10 @@ <h3>Quick Stats</h3>
<div id="googlemap"></div>
<ul id="stats_list">
{% cache 0 homepage_stats %}
- <li><strong>{{ "Browse"|navnode_species_count }}</strong> Specimen Profiles</li>
+ <li><strong>{{ "Browse"|navnode_species_count|intcomma }}</strong> Species Profiles</li>
{# SpeciesRecord is a slow query as we join it against images to filter out labels #}
- <li><strong>{{ "SpeciesRecord"|species_stat_count }}</strong> Specimen Records</li>
- <li><strong>{{ "SpeciesImage"|species_stat_count }}</strong> Specimen Images</li>
+ <li><strong>{{ "SpeciesRecord"|species_stat_count|intcomma }}</strong> Specimen Records</li>
+ <li><strong>{{ "SpeciesImage"|species_stat_count|intcomma }}</strong> Specimen Images</li>
{% endcache %}
</ul>
</div>
@@ -1,6 +1,13 @@
{% load menu_tags thumbnail species_tags browse_filters %}
+<div class="browse_items">
{% for child in children %}
+{% if forloop.counter0|divisibleby:"2" %}
+{% if child.is_leaf_node %}
+<div class="browse_item_row">
+{% endif %}
+{% endif %}
+
{# Added on an ajax request for the tree's horizontal depth lines #}
{% if request.is_ajax %}
<div class="browse_item_wrapper">
@@ -34,4 +41,12 @@ <h3 {% if child|navnode_is_species_or_genus %}class="browse_genus_species"{% end
</div>
{% endif %}
+{% if forloop.counter|divisibleby:"2" or forloop.last %}
+{% if child.is_leaf_node %}
+<div style="clear: both; height: 0px"></div>
+</div>
+{% endif %}
+{% endif %}
+
{% endfor %}
+</div>
Oops, something went wrong.

0 comments on commit 4389bbf

Please sign in to comment.