Skip to content

Commit

Permalink
added short list of latest obs to home page #45
Browse files Browse the repository at this point in the history
  • Loading branch information
stringfellow committed Sep 28, 2013
1 parent 5f41645 commit a408e74
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions observations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ def _observed_as_string(self):
return ", ".join([
test.parameter.name for test in self.parameters.all()])

def get_timestamp(self):
"""Return the most useful timestamp."""
return self.reference_timestamp or self.created_timestamp

def get_location(self):
"""Return a nice location name."""
return self.location_reference or "{0:0.2f}, {1:0.2f}".format(
self.location.x, self.location.y)


class TestValue(models.Model):
"""A Test, as measured during a Measurement, resulting in a Value."""
Expand Down
10 changes: 10 additions & 0 deletions openwater/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ <h5>{{ entry.title }}</h5>
</div>
</div><!--/span-->
<div class="span4">
<div class="well">
<h4>Latest measurements</h4>
<ul>
{% for m in measurement_list %}
<li><a href="{% url "observations-detail" m.id %}">
{{ m.get_timestamp|date }} &mdash; {{ m.get_location }}</a>
</li>
{% endfor %}
</ul>
</div>
<a class="twitter-timeline" href="https://twitter.com/H2OReally" data-widget-id="379269796728025088">Tweets</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
Expand Down
2 changes: 2 additions & 0 deletions openwater/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.views.generic.base import TemplateView

from diario.models import Entry
from observations.models import Measurement


class HomePageView(TemplateView):
Expand All @@ -13,4 +14,5 @@ class HomePageView(TemplateView):
def get_context_data(self, **kwargs):
context = super(HomePageView, self).get_context_data(**kwargs)
context['entry_list'] = Entry.objects.all()[:3]
context['measurement_list'] = Measurement.objects.order_by('-created_timestamp')[:5]
return context

0 comments on commit a408e74

Please sign in to comment.