File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
readthedocs/organizations Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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" : "test@example.org" ,
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 ])
You can’t perform that action at this time.
0 commit comments