Skip to content
Snippets Groups Projects
Commit b31416e7 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[plotters][views] Cleanup plot_sample

Better handling of "default". The current code didn't properly
handled absence of defaults.
parent adb495ba
No related branches found
No related tags found
2 merge requests!2551.4.x,!249Web fixes
......@@ -407,29 +407,28 @@ def plot_sample(request):
# Collect the data for the plot, check compatibility
default = None
# check compatibility, fill up defaults
if default is None:
default = DefaultPlotter.objects.filter(plotter=final_plotter)
default = DefaultPlotter.objects.filter(plotter=final_plotter)
if not default and not final_plotter:
message = 'No plotter specified and no default for plot format %s' % final_plotter.fullname()
return HttpResponseBadRequest(message)
if not default.count() and not final_plotter:
message = 'No plotter specified and no default for plot format %s' % final_plotter.fullname()
return HttpResponseBadRequest(message)
# check compatibility, fill up defaults
if default.count():
default = default[0] #get the first and only
# set defaults, if specific values have not already been set
if not final_plotter: final_plotter = default.plotter
else:
default = None
if corefmt is None: #loads it once
corefmt = final_plotter.core_format()
if corefmt is None: #loads it once
corefmt = final_plotter.core_format()
## loads the data, for that particular result
parsed = simplejson.loads(use['sample_data'])
sample_data = corefmt.type().from_dict(parsed, casting='unsafe')
# checks the plotter is valid
core_plotter = final_plotter.core()
if not core_plotter.valid:
......@@ -439,7 +438,7 @@ def plot_sample(request):
# resolves parameters, in order of priority
final_parameters = {}
if default.parameter: #fills-up defaults for the type
if default and default.parameter: #fills-up defaults for the type
final_parameters.update(simplejson.loads(default.parameter.data))
if user_parameter: #fills-up defaults from the user set
final_parameters.update(simplejson.loads(user_parameter.data))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment