Skip to content
Open
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
5 changes: 3 additions & 2 deletions openwisp_utils/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,22 @@ def uuid(self, obj):
uuid.short_description = _("UUID")


class ReceiveUrlAdmin(ModelAdmin):
class ReceiveUrlAdmin(CopyableFieldsAdmin):
"""Adds a receive_url field.

The receive_url method will build the URL using the parameters:

- receive_url_name
- receive_url_object_arg
- receive_url_object_arg
- receive_url_querystring_arg
"""

receive_url_querystring_arg = "key"
receive_url_object_arg = "pk"
receive_url_name = None
receive_url_urlconf = None
receive_url_baseurl = None
copyable_fields = ("receive_url",)

def add_view(self, request, *args, **kwargs):
self.request = request
Expand Down
9 changes: 7 additions & 2 deletions tests/test_project/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
ReadOnlyAdmin,
ReceiveUrlAdmin,
TimeReadonlyAdminMixin,
UUIDAdmin,
)
from openwisp_utils.admin_theme.filters import (
AutocompleteFilter,
Expand Down Expand Up @@ -80,12 +79,18 @@ class OperatorInline(HelpTextStackedInline):


@admin.register(Project)
class ProjectAdmin(UUIDAdmin, ReceiveUrlAdmin):
class ProjectAdmin(ReceiveUrlAdmin):
inlines = [OperatorInline]
list_display = ("name",)
fields = ("uuid", "name", "key", "receive_url")
readonly_fields = ("uuid", "receive_url")
receive_url_name = "receive_project"
copyable_fields = ("uuid", "receive_url")

def uuid(self, obj):
return obj.pk

uuid.short_description = _("UUID")


class ShelfFilter(SimpleInputFilter):
Expand Down
10 changes: 6 additions & 4 deletions tests/test_project/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_uuid_field_in_add(self):
response = self.client.get(path)
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, "field-uuid")
self.assertContains(response, "field-receive_url")
self.assertNotContains(response, "field-receive_url")

def test_copyablefields_admin(self):
class TestCopyableFieldAdmin(CopyableFieldsAdmin):
Expand Down Expand Up @@ -251,10 +251,12 @@ def test_copyablefields_admin_fields_order(self):
path = reverse("admin:test_project_project_add")
self.client.get(path)
ma = ProjectAdmin(Project, self.site)
# 'uuid' should be missing from ma.get_fields()
# 'uuid' and 'receive_url' should be missing from ma.get_fields()
# because we're testing the project admin add form,
# and now we're adding it here again only to assert the admin field order
self.assertEqual(ma.fields, ("uuid", *ma.get_fields(self.client.request)))
# and now we're adding them here again only to assert the admin field order
self.assertEqual(
ma.fields, ("uuid", *ma.get_fields(self.client.request), "receive_url")
)
self.assertEqual(
ma.readonly_fields, ma.get_readonly_fields(self.client.request)
)
Expand Down
Loading