Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fixed re-ordering applied templates in device config #830

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openwisp_controller/config/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def clean_templates(self):
return templates

def save(self, *args, **kwargs):
templates = self.cleaned_data.pop('templates', [])
templates = self.cleaned_data.get('templates', [])
instance = super().save(*args, **kwargs)
# as group templates are not forced so if user remove any selected
# group template, we need to remove it from the config instance
Expand Down
32 changes: 32 additions & 0 deletions openwisp_controller/config/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,38 @@ def test_change_device_org_required_templates(self):
config.refresh_from_db()
self.assertEqual(config.templates.count(), 0)

def test_change_device_reorder_templates(self):
org = self._get_org()
template1 = self._create_template(name='template1')
template2 = self._create_template(name='template2')
config = self._create_config(organization=org)
device = config.device
config.templates.add(template1, template2)
self.assertEqual(config.templates.count(), 2)
self.assertEqual(
list(config.templates.values_list('id', flat=True)),
[template1.id, template2.id],
)

path = reverse(f'admin:{self.app_label}_device_change', args=[device.pk])
params = self._get_device_params(org=org)
params.update(
{
'config-0-id': str(config.pk),
'config-0-device': str(device.pk),
'config-0-templates': f'{template2.id},{template1.id}',
'config-INITIAL_FORMS': 1,
}
)
response = self.client.post(path, params, follow=True)
self.assertEqual(response.status_code, 200)
config.refresh_from_db()
self.assertEqual(config.templates.count(), 2)
self.assertEqual(
list(config.templates.values_list('id', flat=True)),
[template2.id, template1.id],
)

def test_download_device_config(self):
d = self._create_device(name='download')
self._create_config(device=d)
Expand Down
Loading