File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
openwisp_controller/config Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -230,11 +230,14 @@ def preview_view(self, request):
230
230
template_ids = request .POST .get ('templates' )
231
231
if template_ids :
232
232
template_model = config_model .get_template_model ()
233
+ template_ids = template_ids .split (',' )
233
234
try :
234
- templates = template_model .objects .filter (
235
- pk__in = template_ids .split (',' )
236
- )
235
+ templates = template_model .objects .filter (pk__in = template_ids )
237
236
templates = list (templates ) # evaluating queryset performs query
237
+ # ensure the order of templates is maintained
238
+ templates .sort (
239
+ key = lambda template : template_ids .index (str (template .id ))
240
+ )
238
241
except ValidationError as e :
239
242
logger .exception (error_msg , extra = {'request' : request })
240
243
return HttpResponse (str (e ), status = 400 )
Original file line number Diff line number Diff line change @@ -701,10 +701,17 @@ def test_preview_device_jsonerror(self):
701
701
702
702
def test_preview_device_showerror (self ):
703
703
t1 = Template .objects .get (name = 'dhcp' )
704
- t2 = Template (name = 't' , config = t1 .config , backend = 'netjsonconfig.OpenWrt' )
705
- t2 .full_clean ()
706
- t2 .save ()
707
- templates = [t1 , t2 ]
704
+ t2 = Template (name = 't2' , config = t1 .config , backend = t1 .backend )
705
+ t3 = Template (name = 't3' , config = t1 .config , backend = t1 .backend )
706
+ t4 = Template (
707
+ name = 't4' ,
708
+ config = {"interfaces" : [{"name" : "eth0" , "type" : "bridge" , "stp" : "WRONG" }]},
709
+ backend = 'netjsonconfig.OpenWrt' ,
710
+ )
711
+ # skip validating config to raise error later
712
+ t4 .save ()
713
+ # adding multiple templates to ensure the order is retained correctly
714
+ templates = [t1 , t2 , t3 , t4 ]
708
715
path = reverse (f'admin:{ self .app_label } _device_preview' )
709
716
data = {
710
717
'name' : 'test-device' ,
You can’t perform that action at this time.
0 commit comments