Skip to content

Commit

Permalink
Retrieve the current energycontract for the statistics page #485
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Jun 27, 2018
1 parent 05edd2b commit 6037c1c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ v1.20.0 - 2018-xx-xx
**Tickets resolved in this release:**

- [`#484 <https://github.com/dennissiemensma/dsmr-reader/issues/484>`_] API call om huidige versie terug te geven
- [`#485 <https://github.com/dennissiemensma/dsmr-reader/issues/485>`_] Retrieve the current energycontract for the statistics page - helmo



Expand Down
1 change: 1 addition & 0 deletions dsmr_frontend/tests/webinterface/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_statistics(self, now_mock):
)
self.assertEqual(response.status_code, 200)
self.assertIn('capabilities', response.context)
self.assertIn('energy_prices', response.context)

if DsmrReading.objects.exists():
self.assertIn('latest_reading', response.context)
Expand Down
9 changes: 9 additions & 0 deletions dsmr_frontend/views/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from django.contrib.humanize.templatetags.humanize import intcomma
from django.views.generic.base import TemplateView, View
from django.http.response import HttpResponse
from django.utils import timezone

from dsmr_datalogger.models.reading import DsmrReading
from dsmr_datalogger.models.statistics import MeterStatistics
from dsmr_consumption.models.energysupplier import EnergySupplierPrice
from dsmr_datalogger.models.settings import DataloggerSettings
import dsmr_backend.services
import dsmr_consumption.services
Expand All @@ -32,6 +34,13 @@ def get_context_data(self, **kwargs):
context_data['datalogger_settings'] = DataloggerSettings.get_solo()
context_data['meter_statistics'] = MeterStatistics.get_solo()

today = timezone.localtime(timezone.now()).date()

try:
context_data['energy_prices'] = EnergySupplierPrice.objects.by_date(today)
except EnergySupplierPrice.DoesNotExist:
context_data['energy_prices'] = []

return context_data


Expand Down
2 changes: 1 addition & 1 deletion dsmrreader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
from django.utils.version import get_version


VERSION = (1, 20, 0, 'beta', 1)
VERSION = (1, 20, 0, 'beta', 2)

__version__ = get_version(VERSION)

0 comments on commit 6037c1c

Please sign in to comment.