From fc51733831232295b744b5aaf8f1e6899ac0fd20 Mon Sep 17 00:00:00 2001 From: Alex Vykalyuk Date: Fri, 6 Feb 2015 19:42:50 +0200 Subject: [PATCH] Made simplejson optional Now your lib can work with Django 1.7, where simplejson is deprecated. Can you also make an update on PyPI? --- nicedit/views.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/nicedit/views.py b/nicedit/views.py index b9abaf2..85e2f2e 100644 --- a/nicedit/views.py +++ b/nicedit/views.py @@ -1,4 +1,7 @@ -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 @@ -6,14 +9,14 @@ 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': { @@ -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')