Skip to content

Commit

Permalink
test url params & view descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Nov 8, 2016
1 parent 61691e2 commit 98f3939
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions rest_pandas/mustache/rest_pandas.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ <h1>{{name}}</h1>
{{/description}}
<div data-role="controlgroup" data-type="horizontal" data-mini="true">
{{#available_formats}}
<a href="{{url}}.{{.}}" rel="external" class="ui-btn ui-corner-all">
<a href="{{url}}.{{.}}{{url_params}}" rel="external" class="ui-btn ui-corner-all">
{{.}}
</a>
{{/available_formats}}
</div>
{{#wq_chart_type}}
<hr>
<svg data-wq-url="{{url}}.csv" data-wq-type="{{wq_chart_type}}"></svg>
<svg data-wq-url="{{url}}.csv{{url_params}}" data-wq-type="{{wq_chart_type}}"></svg>
{{/wq_chart_type}}
<hr>
{{{table}}}
Expand Down
3 changes: 3 additions & 0 deletions rest_pandas/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def get_template_context(self, data, renderer_context):
data['name'] = view.get_view_name()
data['description'] = view.get_view_description(html=True)
data['url'] = request.path.replace('.html', '')
full_path = request.get_full_path()
if '?' in full_path:
data['url_params'] = full_path[full_path.index('?'):]
data['available_formats'] = [
cls.format for cls in view.renderer_classes
if cls.format != 'html'
Expand Down
2 changes: 1 addition & 1 deletion tests/files/multitimeseries.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>Multi Time Series</h1>
</div>
<div role="main" class="ui-content">
<h1>Multi Time Series</h1>
<p></p>
<p>Multiple time series.</p>
<div data-role="controlgroup" data-type="horizontal" data-mini="true">
<a href="/multitimeseries.csv" rel="external" class="ui-btn ui-corner-all">
csv
Expand Down
16 changes: 8 additions & 8 deletions tests/files/timeseries.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ <h1>Time Series</h1>
</div>
<div role="main" class="ui-content">
<h1>Time Series</h1>
<p></p>
<p>A simple time series view.</p>
<div data-role="controlgroup" data-type="horizontal" data-mini="true">
<a href="/timeseries.csv" rel="external" class="ui-btn ui-corner-all">
<a href="/timeseries.csv?test=1" rel="external" class="ui-btn ui-corner-all">
csv
</a>
<a href="/timeseries.txt" rel="external" class="ui-btn ui-corner-all">
<a href="/timeseries.txt?test=1" rel="external" class="ui-btn ui-corner-all">
txt
</a>
<a href="/timeseries.json" rel="external" class="ui-btn ui-corner-all">
<a href="/timeseries.json?test=1" rel="external" class="ui-btn ui-corner-all">
json
</a>
<a href="/timeseries.xlsx" rel="external" class="ui-btn ui-corner-all">
<a href="/timeseries.xlsx?test=1" rel="external" class="ui-btn ui-corner-all">
xlsx
</a>
<a href="/timeseries.xls" rel="external" class="ui-btn ui-corner-all">
<a href="/timeseries.xls?test=1" rel="external" class="ui-btn ui-corner-all">
xls
</a>
<a href="/timeseries.png" rel="external" class="ui-btn ui-corner-all">
<a href="/timeseries.png?test=1" rel="external" class="ui-btn ui-corner-all">
png
</a>
<a href="/timeseries.svg" rel="external" class="ui-btn ui-corner-all">
<a href="/timeseries.svg?test=1" rel="external" class="ui-btn ui-corner-all">
svg
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_view_json_kwargs(self):
self.assertEqual(date, datetime.datetime(2014, 1, 1))

def test_view_html(self):
response = self.client.get("/timeseries")
response = self.client.get("/timeseries?test=1")
expected = open(
os.path.join(os.path.dirname(__file__), 'files', 'timeseries.html')
).read()
Expand Down
6 changes: 6 additions & 0 deletions tests/testapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def get_data(self, request, *args, **kwargs):


class TimeSeriesView(PandasView):
"""
A simple time series view.
"""
queryset = TimeSeries.objects.all()
serializer_class = TimeSeriesSerializer

Expand All @@ -41,6 +44,9 @@ class TimeSeriesViewSet(PandasViewSet):


class MultiTimeSeriesView(PandasView):
"""
Multiple time series.
"""
queryset = MultiTimeSeries.objects.all()
serializer_class = MultiTimeSeriesSerializer
pandas_serializer_class = PandasUnstackedSerializer
Expand Down

0 comments on commit 98f3939

Please sign in to comment.