Commit 762c6dd3 authored by Alan Trick's avatar Alan Trick

fix autocomplete options for tracstats criteria

parent b4f133f1
Pipeline #38975352 passed with stage
in 1 minute and 49 seconds
......@@ -125,5 +125,10 @@ class MetricRegistration(Registration):
"""Given a filter string, return the next options"""
if self.model is None:
return []
part = qs.QuerySpecPart(text, is_filter=is_filter)
return part.options(self.model)
if text.startswith('object'):
text = text[len('object')+2:]
part = qs.QuerySpecPart(text, is_filter=is_filter)
return ['object__' + item for item in part.options(self.model)]
part = qs.QuerySpecPart(text, is_filter=is_filter)
return part.options(trackstats.models.StatisticByDateAndObject)
from django_adminstats import qs
from django_adminstats import qs, registry
from . import models
......@@ -121,3 +121,39 @@ def test_pageview_lookup_filter_options():
qsp = qs.QuerySpecPart('ip_address__iexact', is_filter=True)
expected = ['ip_address__iexact=', 'ip_address__iexact:count=']
assert expected == qsp.options(models.PageView)
def test_trackstats_nomodel_options():
reg = registry.REGISTRY['trackstats:page.view']
assert [] == reg.query_options('', is_filter=False)
def test_trackstats_base_options():
reg = registry.REGISTRY['']
expected = ['id', 'metric', 'value', 'period', 'object_type',
'object_id', 'date', 'object']
assert expected == reg.query_options('', is_filter=False)
def test_trackstats_object_options():
reg = registry.REGISTRY['']
expected = ['object__id', 'object__path', 'object__category']
assert expected == reg.query_options('object', is_filter=False)
def test_trackstats_object_under_options():
reg = registry.REGISTRY['']
expected = ['object__id', 'object__path', 'object__category']
assert expected == reg.query_options('object_', is_filter=False)
def test_trackstats_object_partial_options():
reg = registry.REGISTRY['']
expected = ['object__path']
assert expected == reg.query_options('object__p', is_filter=False)
def test_trackstats_object_path_options():
reg = registry.REGISTRY['']
expected = ['object__path', 'object__path:count']
assert expected == reg.query_options('object__path', is_filter=False)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment