Skip to content

Commit eee3350

Browse files
authored
Organizations: show the slug field on creation (#12297)
Required by readthedocs/ext-theme#25
1 parent 4617dfa commit eee3350

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

readthedocs/organizations/forms.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,23 @@ class OrganizationSignupFormBase(OrganizationForm):
9292

9393
class Meta:
9494
model = Organization
95-
fields = ["name", "email"]
95+
fields = ["name", "slug", "email"]
9696
labels = {
9797
"name": _("Organization Name"),
9898
"email": _("Billing Email"),
9999
}
100+
help_texts = {
101+
"slug": "Used in URLs for your projects when not using a custom domain. It cannot be changed later.",
102+
}
100103

101104
url = None
102105

106+
def __init__(self, *args, **kwargs):
107+
super().__init__(*args, **kwargs)
108+
109+
# `slug` is not required since its value is auto-generated from `name` if not provided
110+
self.fields["slug"].required = False
111+
103112
@staticmethod
104113
def _create_default_teams(organization):
105114
organization.teams.create(name="Admins", access=ADMIN_ACCESS)

readthedocs/organizations/tests/test_forms.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,15 @@ def test_create_organization_with_nonexistent_slug(self):
179179
}
180180
form = forms.OrganizationSignupForm(data, user=self.user)
181181
self.assertTrue(form.is_valid())
182+
organization = form.save()
183+
self.assertEqual(Organization.objects.filter(slug="my-new-organization").count(), 1)
184+
185+
def test_create_organization_with_invalid_slug(self):
186+
data = {
187+
"name": "My Org",
188+
"email": "[email protected]",
189+
"slug": "invalid-<slug>",
190+
}
191+
form = forms.OrganizationSignupForm(data, user=self.user)
192+
self.assertFalse(form.is_valid())
193+
self.assertIn("consisting of letters, numbers", form.errors["slug"][0])

0 commit comments

Comments
 (0)