Skip to content

Commit

Permalink
[fix] Fixed "receive_url" field in TopologyAdmin
Browse files Browse the repository at this point in the history
Bug:
When WiFi Mesh integration is enabled, opening the topology add
view was generating Server 500 Error. The issue was caused because
the topology instance for the ModelForm didn't have primary key set.

Fix:
Do not show "receive_url" field on add view.
  • Loading branch information
pandafy committed Jun 16, 2023
1 parent e363f0b commit 5ed611a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions openwisp_network_topology/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ class TopologyAdmin(
receive_url_baseurl = app_settings.TOPOLOGY_API_BASEURL
change_form_template = 'admin/topology/topology/change_form.html'

def get_fields(self, request, obj=None):
fields = list(super().get_fields(request, obj))
if not obj:
# Receive URL cannot be created without an object.
# Hence, remove the "receive_url" field.
fields.remove('receive_url')
return fields

def get_actions(self, request):
"""
move delete action to last position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,14 @@ def test_topology_admin(self):
"""
admin = self._create_admin()
self.client.force_login(admin)
topology = self._create_topology()
response = self.client.get(
reverse(f'{self.prefix}_topology_change', args=[topology.id])
)
self.assertContains(response, 'Wifi mesh')

with self.subTest('Test add form'):
response = self.client.get(reverse(f'{self.prefix}_topology_add'))
self.assertContains(response, 'Wifi mesh')

with self.subTest('Test change form'):
topology = self._create_topology()
response = self.client.get(
reverse(f'{self.prefix}_topology_change', args=[topology.id])
)
self.assertContains(response, 'Wifi mesh')

0 comments on commit 5ed611a

Please sign in to comment.