add a view which accepts hours as arguments

This views allows to select various timeranges which the site then can display.
This commit is contained in:
Andreas Zweili 2019-10-24 22:35:12 +02:00
parent 8ded8def06
commit e4ccc594af
4 changed files with 31 additions and 1 deletions

View File

@ -8,7 +8,20 @@
</head>
<body>
<div class="ui container">
<h1>{% block section_title %}Environment Sensors{% endblock %}</h1>
<div class="ui menu">
<div class="header item">
<a href="{% url 'index' %}">Home</a>
</div>
<div class="item">
<a href="{% url 'history' '72' %}">3 Days</a>
</div>
<div class="item">
<a href="{% url 'history' '168' %}">1 Week</a>
</div>
<div class="item">
<a href="{% url 'history' '720' %}">1 Month</a>
</div>
</div>
<h2>Temperature</h2>
{% autoescape off %}
{{ plot_temp }}

View File

@ -12,3 +12,8 @@ def test_index_temperature():
response = Client().get('/')
assert response.status_code == 200
def test_history_view():
response = Client().get('/history/36')
assert response.status_code == 200

View File

@ -5,4 +5,5 @@ from . import views
urlpatterns = [
path('', views.index_view, name='index'),
path('history/<int:hours>', views.history_view, name='history'),
]

View File

@ -11,3 +11,14 @@ def index_view(request):
context={'plot_temp': plot_temp,
'plot_humidity': plot_humidity,
'plot_pressure': plot_pressure})
def history_view(request, hours):
start_time = datetime.now() - timedelta(hours=hours)
plot_temp = plot.temperature(start_time)
plot_humidity = plot.humidity(start_time)
plot_pressure = plot.pressure(start_time)
return render(request, "collector/index.html",
context={'plot_temp': plot_temp,
'plot_humidity': plot_humidity,
'plot_pressure': plot_pressure})