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):
92
92
93
93
class Meta :
94
94
model = Organization
95
- fields = ["name" , "email" ]
95
+ fields = ["name" , "slug" , " email" ]
96
96
labels = {
97
97
"name" : _ ("Organization Name" ),
98
98
"email" : _ ("Billing Email" ),
99
99
}
100
+ help_texts = {
101
+ "slug" : "Used in URLs for your projects when not using a custom domain. It cannot be changed later." ,
102
+ }
100
103
101
104
url = None
102
105
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
+
103
112
@staticmethod
104
113
def _create_default_teams (organization ):
105
114
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):
179
179
}
180
180
form = forms .OrganizationSignupForm (data , user = self .user )
181
181
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
+
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