0001-dashboard-raise-on-missing-parameters-in-auto-tile-4.patch
combo/apps/dashboard/views.py | ||
---|---|---|
21 | 21 |
from django.core.exceptions import PermissionDenied |
22 | 22 |
from django.urls import reverse |
23 | 23 |
from django.db.models import Max, Min |
24 |
from django.http import Http404, HttpResponse, HttpResponseRedirect |
|
24 |
from django.http import Http404, HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
|
|
25 | 25 |
from django.utils.encoding import force_text |
26 | 26 |
from django.views.decorators.csrf import csrf_exempt |
27 | 27 |
from django.views.generic import View |
... | ... | |
116 | 116 |
page_id=dashboard.page_id, placeholder='_auto_tile') |
117 | 117 | |
118 | 118 |
# only keep parameters that are actually defined for this cell type. |
119 |
cell_form_keys = [x['varname'] for x in settings.JSON_CELL_TYPES[cell.key].get('form') or {}] |
|
120 | 119 |
cell.parameters = {} |
121 | 120 |
request_body = json.loads(force_text(request.body)) |
122 |
for key in cell_form_keys: |
|
121 |
for field in settings.JSON_CELL_TYPES[cell.key].get('form') or []: |
|
122 |
key = field['varname'] |
|
123 | 123 |
cell.parameters[key] = request_body.get(key) |
124 |
if cell.parameters[key] is None and field.get('required', True): |
|
125 |
return HttpResponseBadRequest('missing key: %s' % key) |
|
124 | 126 | |
125 | 127 |
# save cell so it can be reused later, for example to be added to |
126 | 128 |
# dashboard, or to be used as reference in another page, etc. |
tests/test_dashboard.py | ||
---|---|---|
209 | 209 |
content_type='application/json') |
210 | 210 |
assert resp.text.strip() == '/var1=one/var2=/' |
211 | 211 | |
212 |
# with missing data |
|
213 |
resp = app.post(reverse('combo-dashboard-auto-tile', kwargs={'key': 'test-config-json-cell'}), |
|
214 |
params=json.dumps({'var2': 'two'}), |
|
215 |
content_type='application/json', status=400) |
|
216 | ||
217 | ||
212 | 218 |
def test_clean_autotiles(app, site): |
213 | 219 |
appconfig = apps.get_app_config('dashboard') |
214 | 220 |
appconfig.clean_autotiles() |
215 |
- |