# HG changeset patch # User Brian Neal # Date 1376615673 18000 # Node ID 89b240fe9297f2f45f99a1a5c67c34825cf0f776 # Parent 38a198ea8c613b5d96f70d42e37832fac39f398d For Django 1.5.2: import json; django.utils.simplejson is deprecated. diff -r 38a198ea8c61 -r 89b240fe9297 accounts/views.py --- a/accounts/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/accounts/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -3,6 +3,7 @@ """ import datetime +import json import logging from django.shortcuts import render @@ -13,7 +14,6 @@ from django.conf import settings from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth import login -from django.utils import simplejson from accounts.models import PendingUser from accounts.forms import RegisterForm, ForgotUsernameForm @@ -105,8 +105,7 @@ else: response['error'] = 'Invalid username or password' - return HttpResponse(simplejson.dumps(response), - content_type='application/json') + return HttpResponse(json.dumps(response), content_type='application/json') ####################################################################### diff -r 38a198ea8c61 -r 89b240fe9297 antispam/decorators.py --- a/antispam/decorators.py Wed Aug 14 14:53:21 2013 -0500 +++ b/antispam/decorators.py Thu Aug 15 20:14:33 2013 -0500 @@ -3,10 +3,10 @@ """ from datetime import timedelta +import json from functools import wraps from django.shortcuts import render -from django.utils import simplejson from antispam.rate_limit import RateLimiter, RateLimiterUnavailable @@ -41,7 +41,7 @@ success = (response and response.has_header('location') and response.status_code == 302) elif response: - json_resp = simplejson.loads(response.content) + json_resp = json.loads(response.content) success = json_resp['success'] if not success: diff -r 38a198ea8c61 -r 89b240fe9297 bio/flags.py --- a/bio/flags.py Wed Aug 14 14:53:21 2013 -0500 +++ b/bio/flags.py Thu Aug 15 20:14:33 2013 -0500 @@ -2,13 +2,11 @@ This module contains country flag data & functions. """ -from __future__ import with_statement +import json import os.path import locale import logging -import django.utils.simplejson as json - # Read flag data from external JSON file: diff -r 38a198ea8c61 -r 89b240fe9297 contests/tests/view_tests.py --- a/contests/tests/view_tests.py Wed Aug 14 14:53:21 2013 -0500 +++ b/contests/tests/view_tests.py Thu Aug 15 20:14:33 2013 -0500 @@ -3,10 +3,11 @@ """ import datetime +import json + from django.test import TestCase from django.contrib.auth.models import User from django.core.urlresolvers import reverse -from django.utils import simplejson from contests.models import Contest @@ -81,8 +82,8 @@ HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, 200) - json = simplejson.loads(response.content) - self.assertTrue(json['entered']) + c = json.loads(response.content) + self.assertTrue(c['entered']) contest = Contest.objects.get(pk=self.contest_id) self.assertTrue(self.user in contest.contestants.all()) @@ -92,8 +93,8 @@ HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, 200) - json = simplejson.loads(response.content) - self.failIf(json['entered']) + c = json.loads(response.content) + self.failIf(c['entered']) contest = Contest.objects.get(pk=self.contest_id) self.failIf(self.user in contest.contestants.all()) diff -r 38a198ea8c61 -r 89b240fe9297 contests/views.py --- a/contests/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/contests/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -2,10 +2,11 @@ Views for the contests application. """ +import json + from django.http import (HttpResponse, HttpResponseForbidden, HttpResponseBadRequest) from django.shortcuts import get_object_or_404 -from django.utils import simplejson from django.views.decorators.http import require_POST from contests.models import Contest @@ -42,5 +43,5 @@ result['entered'] = True result['msg'] = 'You have been entered into this contest!' - json = simplejson.dumps(result) - return HttpResponse(json, content_type='application/json') + json_result = json.dumps(result) + return HttpResponse(json_result, content_type='application/json') diff -r 38a198ea8c61 -r 89b240fe9297 core/views.py --- a/core/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/core/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -1,14 +1,16 @@ """ Views for the core application. These are mainly shared, common views used by multiple applications. + """ +import json + from django.contrib.auth.models import User from django.http import HttpResponse from django.shortcuts import render_to_response from django.contrib.auth.decorators import login_required from django.views.decorators.http import require_GET from django.views.generic import TemplateView -import django.utils.simplejson as json @login_required @@ -17,23 +19,25 @@ """ This view provides the Markdown help cheat sheet. It is expected to be called via AJAX. + """ return render_to_response('core/markdown_help.html') def ajax_users(request): """ - If the user is authenticated, return a JSON array of strings of usernames - whose names start with the 'q' GET parameter, limited by the 'limit' GET + If the user is authenticated, return a JSON array of strings of usernames + whose names start with the 'q' GET parameter, limited by the 'limit' GET parameter. Only active usernames are returned. If the user is not authenticated, return an empty array. + """ q = request.GET.get('q', None) if q is None or not request.user.is_authenticated(): return HttpResponse(json.dumps([]), content_type='application/json') limit = int(request.GET.get('limit', 10)) - users = User.objects.filter(is_active=True, + users = User.objects.filter(is_active=True, username__istartswith=q).values_list('username', flat=True)[:limit] return HttpResponse(json.dumps(list(users)), content_type='application/json') diff -r 38a198ea8c61 -r 89b240fe9297 downloads/views.py --- a/downloads/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/downloads/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -1,7 +1,7 @@ """ Views for the downloads application. """ -import random +import json from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext @@ -14,9 +14,7 @@ from django.http import HttpResponseNotFound from django.core.paginator import InvalidPage from django.core.urlresolvers import reverse -from django.db.models import Q from django.views.decorators.http import require_POST -import django.utils.simplejson as json from core.paginator import DiggPaginator from core.functions import email_admins diff -r 38a198ea8c61 -r 89b240fe9297 forums/latest.py --- a/forums/latest.py Wed Aug 14 14:53:21 2013 -0500 +++ b/forums/latest.py Thu Aug 15 20:14:33 2013 -0500 @@ -51,11 +51,11 @@ # while with MySQL InnoDb. # import datetime +import json import logging import time from django.dispatch import receiver -from django.utils import simplejson from django.template.loader import render_to_string import redis @@ -237,11 +237,11 @@ 'date': topic_score, 'url': post.topic.get_latest_post_url() } - json = simplejson.dumps(topic_content) + topic_json = json.dumps(topic_content) key = UPDATED_TOPIC_KEY % topic_id pipeline = conn.pipeline() - pipeline.set(key, json) + pipeline.set(key, topic_json) pipeline.zadd(UPDATED_TOPICS_SET_KEY, topic_score, topic_id) pipeline.zcard(UPDATED_TOPICS_SET_KEY) results = pipeline.execute() @@ -288,7 +288,7 @@ posts = [] for raw_post in raw_posts: - post = simplejson.loads(raw_post) + post = json.loads(raw_post) # fix up the pubdate; turn it back into a datetime object post['pubdate'] = datetime.datetime.fromtimestamp(post['pubdate']) @@ -350,20 +350,20 @@ """ conn = get_redis_connection() key = UPDATED_TOPIC_KEY % topic_id - json = conn.get(key) - if json is not None: + topic_json = conn.get(key) + if topic_json is not None: try: topic = Topic.objects.get(pk=topic_id) except Topic.DoesNotExist: logger.warning("topic %d does not exist", topic_id) return - topic_dict = simplejson.loads(json) + topic_dict = json.loads(topic_json) if topic.name != topic_dict['title']: topic_dict['title'] = topic.name - json = simplejson.dumps(topic_dict) - conn.set(key, json) + topic_json = json.dumps(topic_dict) + conn.set(key, topic_json) def get_stats(): @@ -421,7 +421,7 @@ topics = [] for s in json_list: - item = simplejson.loads(s) + item = json.loads(s) item['date'] = datetime.datetime.fromtimestamp(item['date']) topics.append(item) @@ -477,7 +477,7 @@ 'url': post.get_absolute_url() } - return simplejson.dumps(post_content) + return json.dumps(post_content) # Down here to avoid a circular import diff -r 38a198ea8c61 -r 89b240fe9297 forums/views/attachments.py --- a/forums/views/attachments.py Wed Aug 14 14:53:21 2013 -0500 +++ b/forums/views/attachments.py Thu Aug 15 20:14:33 2013 -0500 @@ -1,11 +1,13 @@ """ This module contains views for working with post attachments. + """ +import json + from django.http import HttpResponse from django.http import HttpResponseForbidden from django.http import HttpResponseBadRequest from django.http import HttpResponseNotFound -import django.utils.simplejson as json from forums.models import Post diff -r 38a198ea8c61 -r 89b240fe9297 membermap/views.py --- a/membermap/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/membermap/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -1,6 +1,9 @@ """ Views for the membermap application. + """ +import json + from django.shortcuts import render_to_response from django.template.loader import render_to_string from django.template import RequestContext @@ -8,7 +11,6 @@ from django.http import HttpResponseBadRequest from django.http import HttpResponseForbidden from django.views.decorators.http import require_POST -import django.utils.simplejson as json from django.core.cache import cache from membermap.models import MapEntry diff -r 38a198ea8c61 -r 89b240fe9297 messages/views.py --- a/messages/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/messages/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -3,6 +3,7 @@ """ import datetime +import json from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User @@ -14,7 +15,6 @@ from django.http import HttpResponseNotAllowed from django.shortcuts import get_object_or_404 from django.shortcuts import render -import django.utils.simplejson as json from messages.models import Message, Options from messages.forms import OptionsForm, ComposeForm diff -r 38a198ea8c61 -r 89b240fe9297 oembed/core.py --- a/oembed/core.py Wed Aug 14 14:53:21 2013 -0500 +++ b/oembed/core.py Thu Aug 15 20:14:33 2013 -0500 @@ -1,7 +1,8 @@ """ This module contains core functionality for the oembed application. + """ -from __future__ import with_statement +import json import urllib import urllib2 import gzip @@ -10,7 +11,6 @@ except ImportError: from StringIO import StringIO -import django.utils.simplejson as json USER_AGENT = 'gremmies python oembed' diff -r 38a198ea8c61 -r 89b240fe9297 oembed/views.py --- a/oembed/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/oembed/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -1,13 +1,13 @@ """ Views for the oembed application. + """ +import json import re -import urllib2 from django.http import HttpResponse from django.http import HttpResponseBadRequest from django.http import HttpResponseForbidden -import django.utils.simplejson as json from django.conf import settings from oembed.models import Provider diff -r 38a198ea8c61 -r 89b240fe9297 phantombrigade/views.py --- a/phantombrigade/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/phantombrigade/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -9,10 +9,11 @@ Current we provide a TeamSpeak 3 status view for the PhantomBrigade.us website. """ +import json + from django.conf import settings from django.core.cache import cache from django.http import HttpResponse, HttpResponseServerError -from django.utils import simplejson import ts3 @@ -94,8 +95,8 @@ channel['children'].append(node) tree = [channels[0]] - json = simplejson.dumps(tree) + status = json.dumps(tree) - cache.set(CACHE_KEY, json, CACHE_TIMEOUT) + cache.set(CACHE_KEY, status, CACHE_TIMEOUT) - return HttpResponse(json, content_type='application/json') + return HttpResponse(status, content_type='application/json') diff -r 38a198ea8c61 -r 89b240fe9297 podcast/views.py --- a/podcast/views.py Wed Aug 14 14:53:21 2013 -0500 +++ b/podcast/views.py Thu Aug 15 20:14:33 2013 -0500 @@ -2,13 +2,13 @@ Views for the podcast application. """ +import json import os.path from urlparse import urlparse from django.shortcuts import render_to_response from django.template import RequestContext from django.shortcuts import get_object_or_404 -import django.utils.simplejson as json from podcast.models import Channel from podcast.models import Item diff -r 38a198ea8c61 -r 89b240fe9297 sg101/settings/base.py --- a/sg101/settings/base.py Wed Aug 14 14:53:21 2013 -0500 +++ b/sg101/settings/base.py Thu Aug 15 20:14:33 2013 -0500 @@ -1,9 +1,9 @@ # Base Django settings for the SG101 website. +import json import os from decimal import Decimal -import django.utils.simplejson as json from django.contrib.messages import constants as message_constants import djcelery from celery.schedules import crontab