dashboard: only include relevant parameters when creating a tile (#18070)
This commit is contained in:
parent
d208991cb4
commit
7f51084382
|
@ -96,7 +96,14 @@ def dashboard_auto_tile(request, *args, **kwargs):
|
|||
dashboard = DashboardCell.objects.all()[0]
|
||||
cell = ConfigJsonCell(key=kwargs.get('key'), order=1,
|
||||
page_id=dashboard.page_id, placeholder='_auto_tile')
|
||||
cell.parameters = json.loads(request.body)
|
||||
|
||||
# only keep parameters that are actually defined for this cell type.
|
||||
cell_form_keys = [x['varname'] for x in settings.JSON_CELL_TYPES[cell.key].get('form') or {}]
|
||||
cell.parameters = {}
|
||||
request_body = json.loads(request.body)
|
||||
for key in cell_form_keys:
|
||||
cell.parameters[key] = request_body.get(key)
|
||||
|
||||
if request.user.is_authenticated():
|
||||
# save cell if the user is connected, so it can be added to the
|
||||
# dashboard
|
||||
|
|
|
@ -148,7 +148,16 @@ def test_reorder_dashboard(app, site):
|
|||
assert new_order == ','.join([str(x.id) for x in tiles])
|
||||
|
||||
def test_auto_tile(app, site):
|
||||
with override_settings(JSON_CELL_TYPES={'test-config-json-cell': {'name': 'Foobar', 'url': 'http://test/'}},
|
||||
with override_settings(JSON_CELL_TYPES={
|
||||
'test-config-json-cell': {
|
||||
'name': 'Foobar',
|
||||
'url': 'http://test/',
|
||||
'form': [
|
||||
{
|
||||
'varname': 'var1',
|
||||
}
|
||||
]
|
||||
}},
|
||||
TEMPLATE_DIRS=['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]):
|
||||
with mock.patch('combo.utils.requests.get') as requests_get:
|
||||
# logged out
|
||||
|
@ -156,11 +165,11 @@ def test_auto_tile(app, site):
|
|||
resp = app.post(reverse('combo-dashboard-auto-tile', kwargs={'key': 'test-config-json-cell'}),
|
||||
params=json.dumps({'var1': 'one', 'var2': 'two'}),
|
||||
content_type='application/json')
|
||||
assert resp.body.strip() == '/var1=one/var2=two/'
|
||||
assert resp.body.strip() == '/var1=one/var2=/'
|
||||
|
||||
# and logged in
|
||||
app = login(app)
|
||||
resp = app.post(reverse('combo-dashboard-auto-tile', kwargs={'key': 'test-config-json-cell'}),
|
||||
params=json.dumps({'var1': 'one', 'var2': 'two'}),
|
||||
content_type='application/json')
|
||||
assert resp.body.strip() == '/var1=one/var2=two/'
|
||||
assert resp.body.strip() == '/var1=one/var2=/'
|
||||
|
|
Loading…
Reference in New Issue