Skip to content

Commit

Permalink
Merge pull request nanvel#3 from alekzvik/patch-1
Browse files Browse the repository at this point in the history
Made simplejson optional
  • Loading branch information
nanvel committed Feb 7, 2015
2 parents 2a13d50 + fc51733 commit a26cfc0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions nicedit/views.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from django.utils import simplejson
try:
from django.utils import simplejson as json
except ImportError:
import json
from django.http import HttpResponse

from .forms import NicEditImageForm


def upload(request):
if not request.user.is_authenticated():
json = simplejson.dumps({
json_data = json.dumps({
'success': False,
'errors': {'__all__': 'Authentication required'}})
return HttpResponse(json, mimetype='application/json')
return HttpResponse(json_data, mimetype='application/json')
form = NicEditImageForm(request.POST or None, request.FILES or None)
if form.is_valid():
image = form.save()
json = simplejson.dumps({
json_data = json.dumps({
'success': True,
'upload': {
'links': {
Expand All @@ -24,6 +27,6 @@ def upload(request):
}
})
else:
json = simplejson.dumps({
json_data = json.dumps({
'success': False, 'errors': form.errors})
return HttpResponse(json, mimetype='application/json')
return HttpResponse(json_data, mimetype='application/json')

0 comments on commit a26cfc0

Please sign in to comment.