Skip to content

Commit 28b7fb8

Browse files
committed
Merge pull request #184 from RickyCook/fix-new-project-exist
Error when adding a project that already exists
2 parents a8b4b0e + 15b5a8e commit 28b7fb8

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Sessions secret hidden on config edit form #178
2222
- Don't roll up log when body element is clicked #179
2323
- Better security for dowload of job output files #180
24+
- Can't add a project that already exists #184
2425

2526
## v0.0.3
2627
- Log level to debug #20

dockci/views/project.py

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -135,30 +135,7 @@ def handle_github_hook(project):
135135
def 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

Comments
 (0)