diff --git a/openwisp_utils/admin.py b/openwisp_utils/admin.py index bfaba7e2..b63c1240 100644 --- a/openwisp_utils/admin.py +++ b/openwisp_utils/admin.py @@ -150,14 +150,14 @@ 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" @@ -165,6 +165,7 @@ class ReceiveUrlAdmin(ModelAdmin): 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 diff --git a/tests/test_project/admin.py b/tests/test_project/admin.py index 3ea8fd49..210ce6aa 100644 --- a/tests/test_project/admin.py +++ b/tests/test_project/admin.py @@ -8,7 +8,6 @@ ReadOnlyAdmin, ReceiveUrlAdmin, TimeReadonlyAdminMixin, - UUIDAdmin, ) from openwisp_utils.admin_theme.filters import ( AutocompleteFilter, @@ -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): diff --git a/tests/test_project/tests/test_admin.py b/tests/test_project/tests/test_admin.py index 73ccf22f..018eaf8d 100644 --- a/tests/test_project/tests/test_admin.py +++ b/tests/test_project/tests/test_admin.py @@ -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): @@ -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) )