Merge "Filter action respects HTTP method. Fixes bug 931272."
This commit is contained in:
commit
75053c8222
@ -285,7 +285,11 @@ class FilterAction(BaseAction):
|
||||
A string representing the name of the request parameter used for the
|
||||
search term. Default: ``"q"``.
|
||||
"""
|
||||
method = "GET"
|
||||
# TODO(gabriel): The method for a filter action should be a GET,
|
||||
# but given the form structure of the table that's currently impossible.
|
||||
# At some future date this needs to be reworked to get the filter action
|
||||
# separated from the table's POST form.
|
||||
method = "POST"
|
||||
name = "filter"
|
||||
|
||||
def __init__(self, verbose_name=None, param_name=None):
|
||||
|
@ -673,10 +673,6 @@ class DataTable(object):
|
||||
# Associate these actions with this table
|
||||
for action in self.base_actions.values():
|
||||
action.table = self
|
||||
if self._meta._filter_action:
|
||||
param_name = self._meta._filter_action.get_param_name()
|
||||
q = self._meta.request.POST.get(param_name, '')
|
||||
self._meta._filter_action.filter_string = q
|
||||
|
||||
def __unicode__(self):
|
||||
return self._meta.verbose_name
|
||||
@ -706,11 +702,20 @@ class DataTable(object):
|
||||
self._filtered_data = self.data
|
||||
if self._meta.filter and self._meta._filter_action:
|
||||
action = self._meta._filter_action
|
||||
filter_string = self.get_filter_string()
|
||||
request_method = self._meta.request.method
|
||||
if filter_string and request_method == action.method:
|
||||
self._filtered_data = action.filter(self,
|
||||
self.data,
|
||||
action.filter_string)
|
||||
filter_string)
|
||||
return self._filtered_data
|
||||
|
||||
def get_filter_string(self):
|
||||
filter_action = self._meta._filter_action
|
||||
param_name = filter_action.get_param_name()
|
||||
filter_string = self._meta.request.POST.get(param_name, '')
|
||||
return filter_string
|
||||
|
||||
def _populate_data_cache(self):
|
||||
self._data_cache = {}
|
||||
# Set up hash tables to store data points for each column
|
||||
|
@ -502,6 +502,16 @@ class DataTableTests(test.TestCase):
|
||||
self.assertQuerysetEqual(self.table.filtered_data,
|
||||
['<FakeObject: object_2>'])
|
||||
|
||||
# Ensure fitering respects the request method, e.g. no filter here
|
||||
req = self.factory.get('/my_url/', {action_string: '2'})
|
||||
self.table = MyTable(req, TEST_DATA)
|
||||
handled = self.table.maybe_handle()
|
||||
self.assertEqual(handled, None)
|
||||
self.assertQuerysetEqual(self.table.filtered_data,
|
||||
['<FakeObject: object_1>',
|
||||
'<FakeObject: object_2>',
|
||||
'<FakeObject: object_3>'])
|
||||
|
||||
# Updating and preemptive actions
|
||||
params = {"table": "my_table", "action": "row_update", "obj_id": "1"}
|
||||
req = self.factory.get('/my_url/',
|
||||
|
Loading…
x
Reference in New Issue
Block a user