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 "receive_url" field in TopologyAdmin #201

Merged
merged 3 commits into from
Jun 22, 2023
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: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ Sending data for topology with RECEIVE strategy

E.g., in our case the URL is ``http://127.0.0.1:8000/api/v1/network-topology/topology/d17e539a-1793-4be2-80a4-c305eca64fd8/receive/?key=cMGsvio8q0L0BGLd5twiFHQOqIEKI423``.

**Note:** The topology receive URL is shown only after the topology object is created.

2. Create a script (eg: ``/opt/send-topology.sh``) which sends the topology
data using ``POST``, in the example script below we are sending the
status log data of OpenVPN but the same code can be applied to other
Expand Down
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')