@@ -135,30 +135,7 @@ def handle_github_hook(project):
135135def project_input_view (project , edit_operation , fields ):
136136 """ Generic view for project editing """
137137 if request .method == 'POST' :
138- fill_data = request .form .to_dict ()
139-
140- # Filter out github properties if not a github repo, so that they are
141- # unset on the project
142- if request .args .get ('repo_type' , None ) == 'github' :
143- fill_data ['github_auth_user' ] = current_user
144- fields .append ('github_auth_user' )
145- else :
146- fill_data ['github_repo_id' ] = None
147- fields .append ('github_repo_id' )
148-
149- saved = request_fill (
150- project , fields ,
151- data = fill_data ,
152- save = request .args .get ('repo_type' , None ) != 'github' ,
153- )
154-
155- if request .args .get ('repo_type' , None ) == 'github' :
156- saved = handle_github_hook (project )
157-
158- if saved :
159- return redirect (
160- '/projects/{project_slug}' .format (project_slug = project .slug )
161- )
138+ project_input_view_post (project , edit_operation , fields )
162139
163140 if 'repo_type' in request .args :
164141 default_repo_type = request .args ['repo_type' ]
@@ -179,3 +156,46 @@ def project_input_view(project, edit_operation, fields):
179156 edit_operation = edit_operation ,
180157 default_repo_type = default_repo_type ,
181158 )
159+
160+
161+ def project_input_view_post (project , edit_operation , fields ):
162+ """ Handle the form filling for ``project_input_view `` """
163+ fill_data = request .form .to_dict ()
164+
165+ # Filter out github properties if not a github repo, so that they are
166+ # unset on the project
167+ if request .args .get ('repo_type' , None ) == 'github' :
168+ fill_data ['github_auth_user' ] = current_user
169+ fields .append ('github_auth_user' )
170+ else :
171+ fill_data ['github_repo_id' ] = None
172+ fields .append ('github_repo_id' )
173+
174+ save = request .args .get ('repo_type' , None ) != 'github'
175+ save &= edit_operation != 'new'
176+
177+ saved = request_fill (
178+ project , fields ,
179+ data = fill_data ,
180+ save = save ,
181+ )
182+
183+ if edit_operation == 'new' :
184+ if project .exists ():
185+ flash ("Project with slug '%s' already exists" % project .slug ,
186+ 'danger' )
187+ saved = False
188+
189+ elif request .args .get ('repo_type' , None ) == 'github' :
190+ saved = handle_github_hook (project )
191+
192+ else :
193+ project .save ()
194+
195+ elif request .args .get ('repo_type' , None ) == 'github' :
196+ saved = handle_github_hook (project )
197+
198+ if saved :
199+ return redirect (
200+ '/projects/{project_slug}' .format (project_slug = project .slug )
201+ )
0 commit comments