Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
bug 1260197 - address feedback on backend code
Browse files Browse the repository at this point in the history
  • Loading branch information
dchukhin committed Aug 22, 2016
1 parent 89ccaae commit 6302314
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
61 changes: 26 additions & 35 deletions kuma/wiki/views/edit.py
Expand Up @@ -168,16 +168,6 @@ def edit(request, document_slug, document_locale, revision_id=None):
# Get the possibly new slug for the imminent redirection:
doc = doc_form.save(parent=None)

# save-and-edit button
if is_async_submit:
# This is the most recent revision id
new_rev_id = rev.document.revisions.order_by('-id').first().id
data = {
"error": False,
"new_revision_id": new_rev_id
}
return JsonResponse(data)

return redirect(urlparams(doc.get_edit_url(),
opendescription=1))
disclose_description = True
Expand Down Expand Up @@ -207,20 +197,22 @@ def edit(request, document_slug, document_locale, revision_id=None):
curr_rev = doc.current_revision

if not rev_form.is_valid():
# Was there a mid-air collision?
if 'current_rev' in rev_form._errors:
# Make the error message safe so the '<' and '>' don't
# get turned into '&lt;' and '&gt;', respectively
rev_form.errors['current_rev'][0] = mark_safe(rev_form.errors['current_rev'][0])

# If this was an Ajax POST, then return a JsonResponse
if is_async_submit:
data = {
"error": True,
"error_message": rev_form.errors['current_rev'],
"new_revision_id": curr_rev.id,
}
return JsonResponse(data=data, status=409)
# If this was an Ajax POST, then return a JsonResponse
if is_async_submit:
# Was there a mid-air collision?
if 'current_rev' in rev_form._errors:
# Make the error message safe so the '<' and '>' don't
# get turned into '&lt;' and '&gt;', respectively
rev_form.errors['current_rev'][0] = mark_safe(
rev_form.errors['current_rev'][0])
errors = [rev_form.errors[key][0] for key in rev_form.errors.keys()]

data = {
"error": True,
"error_message": errors,
"new_revision_id": curr_rev.id,
}
return JsonResponse(data=data)
# Jump out to a function to escape indentation hell
return _edit_document_collision(
request, orig_rev, curr_rev, is_async_submit,
Expand All @@ -237,19 +229,18 @@ def edit(request, document_slug, document_locale, revision_id=None):
return JsonResponse(data=data)
if rev_form.is_valid():
rev_form.save(doc)
if (is_raw and orig_rev is not None and
curr_rev.id != orig_rev.id):
# If this is the raw view, and there was an original
# revision, but the original revision differed from the
# current revision at start of editing, we should tell
# the client to refresh the page.
response = HttpResponse('RESET')
response['X-Frame-Options'] = 'SAMEORIGIN'
response.status_code = 205
return response
# Is this an Ajax POST?
if is_async_submit:
if (is_raw and orig_rev is not None and
curr_rev.id != orig_rev.id):
# If this is the raw view, and there was an original
# revision, but the original revision differed from the
# current revision at start of editing, we should tell
# the client to refresh the page.
response = HttpResponse('RESET')
response['X-Frame-Options'] = 'SAMEORIGIN'
response.status_code = 205
return response
# This must be an Ajax POST, but no need to refresh
# This is the most recent revision id
new_rev_id = rev.document.revisions.order_by('-id').first().id
data = {
Expand Down
9 changes: 8 additions & 1 deletion kuma/wiki/views/translate.py
Expand Up @@ -129,6 +129,7 @@ def translate(request, document_slug, document_locale, revision_id=None):
if user_has_rev_perm:
initial = {
'based_on': based_on_rev.id,
'current_rev': doc.current_or_latest_revision().id if doc else None,
'comment': '',
'toc_depth': based_on_rev.toc_depth,
'localization_tags': ['inprogress'],
Expand Down Expand Up @@ -228,9 +229,15 @@ def translate(request, document_slug, document_locale, revision_id=None):
else:
# If this is an Ajax POST, then return a JsonResponse with error
if request.is_ajax():
if 'current_rev' in rev_form._errors:
# Make the error message safe so the '<' and '>' don't
# get turned into '&lt;' and '&gt;', respectively
rev_form.errors['current_rev'][0] = mark_safe(
rev_form.errors['current_rev'][0])
errors = [rev_form.errors[key][0] for key in rev_form.errors.keys()]
data = {
"error": True,
"error_message": mark_safe(rev_form.errors['current_rev'][0]),
"error_message": errors,
"new_revision_id": rev_form.instance.id,
}
return JsonResponse(data=data)
Expand Down

0 comments on commit 6302314

Please sign in to comment.