Skip to content

Commit

Permalink
Fix some details in time series group detail redesign
Browse files Browse the repository at this point in the history
- Fixes unit tests
- Removes stale placeholder text below "Download data" heading
- Does not show "Download data" form if there's no data to download
- Fixes map
  • Loading branch information
aptiko committed Jun 1, 2021
1 parent e15989e commit 745ccc4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
{% load rules %}

<div class="station-download">
<p><b>Download data</b></p>
<p>Total observation period: 9 years 6 months 23 days</p>

{% has_perm "enhydris.view_timeseries_data" request.user timeseries as can_view_timeseries_data %}
{% if can_view_timeseries_data %}
<div>
{% if object.timeseries_set.exists %}
{% include "enhydris/timeseries_group_detail/download_button/button_active.html" %}
{% else %}
{% include "enhydris/timeseries_group_detail/download_button/button_disabled.html" %}
<p><b>Download data</b></p>
<p></p>
{% include "enhydris/timeseries_group_detail/download_button.html" %}
{% endif %}
</div>
{% else %}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ <h1>{{ object.gentity.name }}</h1>
</section>
{% endblock %}

{% block map_js %}
{{ block.super }}
<script type="text/javascript">
enhydris.mapMode = 'single-station';
enhydris.agentityId = {{ object.gentity.id }};
</script>
{% endblock %}

{% block extrajs %}
{{ block.super }}
<script>
Expand Down
1 change: 1 addition & 0 deletions enhydris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def create_timeseries(self):
time_zone=self.time_zone,
precision=2,
variable=self.variable,
unit_of_measurement__symbol="beauton",
)
self.timeseries = mommy.make(
models.Timeseries,
Expand Down
20 changes: 9 additions & 11 deletions enhydris/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ def test_when_no_dates(self):
class TimeseriesDownloadButtonTestCase(TestCase, TimeseriesDataMixin):
def setUp(self):
self.create_timeseries()
self.download_button = '<input type="submit" value="Download">'
self.download_button = (
'<button type="submit" class="btn form-btn-download">download</button>'
)

def _get_response(self):
self.response = self.client.get(
Expand Down Expand Up @@ -465,12 +467,12 @@ def test_timeseries_group_without_timeseries(self):
self.response = self.client.get(
f"/stations/{self.station.id}/timeseriesgroups/{self.timeseries_group.id}/"
)
self.assertNotContains(self.response, "data_holder")
self.assertContains(self.response, "message-no-data")
self.assertNotContains(self.response, "form-item-download")
self.assertContains(self.response, "alert-info") # "No data" message

def test_timeseries_group_with_timeseries(self):
self.assertContains(self.response, "data_holder")
self.assertNotContains(self.response, "message-no-data")
self.assertContains(self.response, "form-item-download")
self.assertNotContains(self.response, "alert-info") # "No data" message

def test_title(self):
self.assertContains(
Expand All @@ -479,16 +481,12 @@ def test_title(self):

def test_heading(self):
self.assertContains(
self.response, '<p class="my-0">Komboti - Beauty</p>', html=True
self.response, "<h2>Beauty <span>(beauton)</span></h2>", html=True
)

def test_download_form(self):
self.assertContains(
self.response,
f'<input type="radio" name="timeseries_id" value="{self.timeseries.id}" '
'id="id_timeseries_id_0" class="form-check-input" checked>'
'<label class="form-check-label" for="id_timeseries_id_0">Initial</label>',
html=True,
self.response, '<label for="id_timeseries_id_0">Initial</label>', html=True
)


Expand Down
17 changes: 11 additions & 6 deletions enhydris/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,29 @@ def render_to_response(self, *args, **kwargs):
return super().render_to_response(*args, **kwargs)


class StationDetail(DetailView):
model = models.Station
template_name = "enhydris/station_detail/main.html"

class MapWithSingleStationBaseView(DetailView):
def render_to_response(self, *args, **kwargs):
p = self.object.geom
try:
p = self.object.geom
except AttributeError:
p = self.object.gentity.geom
map_extent = [p.x, p.y, p.x, p.y]
ensure_extent_is_large_enough(map_extent)
self.request.map_viewport = map_extent
return super().render_to_response(*args, **kwargs)


class StationDetail(MapWithSingleStationBaseView):
model = models.Station
template_name = "enhydris/station_detail/main.html"


class StationEdit(RedirectView):
def get_redirect_url(self, *args, **kwargs):
return reverse("admin:enhydris_station_change", args=(kwargs["pk"],))


class TimeseriesGroupDetail(DetailView):
class TimeseriesGroupDetail(MapWithSingleStationBaseView):
model = models.TimeseriesGroup
template_name = "enhydris/timeseries_group_detail/main.html"

Expand Down

0 comments on commit 745ccc4

Please sign in to comment.