Skip to content

Commit

Permalink
- added more options for default date range on sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
rptmat57 committed Jun 13, 2022
1 parent 27b0931 commit 681dd40
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ <h3 class="customization-section-title">Sensor data settings</h3>
<label><input type="radio" id="sensor_default_daterange" name="sensor_default_daterange" {% if not sensor_default_daterange %}checked{% endif %} value=""> Last 24 hrs</label>
<label><input type="radio" name="sensor_default_daterange" {% if sensor_default_daterange == 'last_72hrs' %}checked{% endif %} value="last_72hrs"> Last 72 hrs</label>
<label><input type="radio" name="sensor_default_daterange" {% if sensor_default_daterange == 'last_week' %}checked{% endif %} value="last_week"> Last week</label>
<label><input type="radio" name="sensor_default_daterange" {% if sensor_default_daterange == 'last_month' %}checked{% endif %} value="last_month"> Last month</label>
<label><input type="radio" name="sensor_default_daterange" {% if sensor_default_daterange == 'last_year' %}checked{% endif %} value="last_year"> Last year</label>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion NEMO/apps/sensors/templates/sensors/sensors.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{% if not sensors and not categories %}
<div class="dashboard-no-group-items">
no items to display.
{% if user.is_superuser %}
{% if user.is_superuser and not selected_category %}
<br/><br/>You can add sensors, categories and alerts by navigating to<br>
<a href="{% url 'admin:app_list' 'sensors' %}">
Administration -> Detailed Administration -> Sensors
Expand Down
6 changes: 5 additions & 1 deletion NEMO/apps/sensors/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ def get_sensor_data(request, sensor) -> (QuerySet, datetime, datetime):
now = timezone.now().replace(second=0, microsecond=0).astimezone()
sensor_default_daterange = SensorCustomization.get("sensor_default_daterange")
if not start:
if sensor_default_daterange == "last_week":
if sensor_default_daterange == "last_year":
start = now - timedelta(days=365)
elif sensor_default_daterange == "last_month":
start = now - timedelta(days=30)
elif sensor_default_daterange == "last_week":
start = now - timedelta(weeks=1)
elif sensor_default_daterange == "last_72hrs":
start = now - timedelta(days=3)
Expand Down

0 comments on commit 681dd40

Please sign in to comment.