Skip to content
Snippets Groups Projects
Commit 977973ff authored by Ben Adida's avatar Ben Adida
Browse files

began update to django 1.6

parent d61f5dbd
Branches
Tags
No related merge requests found
Showing
with 52 additions and 63 deletions
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
Crypto Utils Crypto Utils
""" """
import hmac, base64 import hmac, base64, json
from django.utils import simplejson
from hashlib import sha256 from hashlib import sha256
...@@ -18,8 +16,8 @@ def hash_b64(s): ...@@ -18,8 +16,8 @@ def hash_b64(s):
return result return result
def to_json(d): def to_json(d):
return simplejson.dumps(d, sort_keys=True) return json.dumps(d, sort_keys=True)
def from_json(json_str): def from_json(json_str):
if not json_str: return None if not json_str: return None
return simplejson.loads(json_str) return json.loads(json_str)
...@@ -7,10 +7,10 @@ and adapted to LDObject ...@@ -7,10 +7,10 @@ and adapted to LDObject
""" """
import datetime import datetime
import json
from django.db import models from django.db import models
from django.db.models import signals from django.db.models import signals
from django.conf import settings from django.conf import settings
from django.utils import simplejson as json
from django.core.serializers.json import DjangoJSONEncoder from django.core.serializers.json import DjangoJSONEncoder
from . import LDObject from . import LDObject
......
...@@ -4,7 +4,7 @@ Helios URLs for Election related stuff ...@@ -4,7 +4,7 @@ Helios URLs for Election related stuff
Ben Adida (ben@adida.net) Ben Adida (ben@adida.net)
""" """
from django.conf.urls.defaults import * from django.conf.urls import *
from helios.views import * from helios.views import *
......
...@@ -7,7 +7,7 @@ Ben Adida ...@@ -7,7 +7,7 @@ Ben Adida
""" """
from django.db import models, transaction from django.db import models, transaction
from django.utils import simplejson import json
from django.conf import settings from django.conf import settings
from django.core.mail import send_mail from django.core.mail import send_mail
......
...@@ -4,7 +4,7 @@ Helios URLs for Election related stuff ...@@ -4,7 +4,7 @@ Helios URLs for Election related stuff
Ben Adida (ben@adida.net) Ben Adida (ben@adida.net)
""" """
from django.conf.urls.defaults import * from django.conf.urls import *
from helios.stats_views import * from helios.stats_views import *
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.conf.urls.defaults import * from django.conf.urls import *
from django.conf import settings from django.conf import settings
......
...@@ -77,7 +77,7 @@ def render_json(json_txt): ...@@ -77,7 +77,7 @@ def render_json(json_txt):
return HttpResponse(json_txt, "application/json") return HttpResponse(json_txt, "application/json")
# decorator # decorator
def json(func): def return_json(func):
""" """
A decorator that serializes the output to JSON before returning to the A decorator that serializes the output to JSON before returning to the
web client. web client.
......
...@@ -115,7 +115,7 @@ def admin_autologin(request): ...@@ -115,7 +115,7 @@ def admin_autologin(request):
## General election features ## General election features
## ##
@json @return_json
def election_params(request): def election_params(request):
return ELGAMAL_PARAMS_LD_OBJECT.toJSONDict() return ELGAMAL_PARAMS_LD_OBJECT.toJSONDict()
...@@ -265,14 +265,14 @@ def one_election_schedule(request, election): ...@@ -265,14 +265,14 @@ def one_election_schedule(request, election):
return HttpResponse("foo") return HttpResponse("foo")
@election_view() @election_view()
@json @return_json
def one_election(request, election): def one_election(request, election):
if not election: if not election:
raise Http404 raise Http404
return election.toJSONDict(complete=True) return election.toJSONDict(complete=True)
@election_view() @election_view()
@json @return_json
def one_election_meta(request, election): def one_election_meta(request, election):
if not election: if not election:
raise Http404 raise Http404
...@@ -381,7 +381,7 @@ def socialbuttons(request): ...@@ -381,7 +381,7 @@ def socialbuttons(request):
## As of July 2009, there are always trustees for a Helios election: one trustee is acceptable, for simple elections. ## As of July 2009, there are always trustees for a Helios election: one trustee is acceptable, for simple elections.
## ##
@election_view() @election_view()
@json @return_json
def list_trustees(request, election): def list_trustees(request, election):
trustees = Trustee.get_by_election(election) trustees = Trustee.get_by_election(election)
return [t.toJSONDict(complete=True) for t in trustees] return [t.toJSONDict(complete=True) for t in trustees]
...@@ -500,7 +500,7 @@ def trustee_upload_pk(request, election, trustee): ...@@ -500,7 +500,7 @@ def trustee_upload_pk(request, election, trustee):
## ##
@election_view() @election_view()
@json @return_json
def get_randomness(request, election): def get_randomness(request, election):
""" """
get some randomness to sprinkle into the sjcl entropy pool get some randomness to sprinkle into the sjcl entropy pool
...@@ -512,7 +512,7 @@ def get_randomness(request, election): ...@@ -512,7 +512,7 @@ def get_randomness(request, election):
} }
@election_view(frozen=True) @election_view(frozen=True)
@json @return_json
def encrypt_ballot(request, election): def encrypt_ballot(request, election):
""" """
perform the ballot encryption given answers_json, a JSON'ified list of list of answers perform the ballot encryption given answers_json, a JSON'ified list of list of answers
...@@ -780,14 +780,14 @@ def one_election_cast_done(request, election): ...@@ -780,14 +780,14 @@ def one_election_cast_done(request, election):
include_user=(not logout)) include_user=(not logout))
@election_view() @election_view()
@json @return_json
def one_election_result(request, election): def one_election_result(request, election):
if not election.result_released_at: if not election.result_released_at:
raise PermissionDenied raise PermissionDenied
return election.result return election.result
@election_view() @election_view()
@json @return_json
def one_election_result_proof(request, election): def one_election_result_proof(request, election):
if not election.result_released_at: if not election.result_released_at:
raise PermissionDenied raise PermissionDenied
...@@ -1355,7 +1355,7 @@ def voters_email(request, election): ...@@ -1355,7 +1355,7 @@ def voters_email(request, election):
# Individual Voters # Individual Voters
@election_view() @election_view()
@json @return_json
def voter_list(request, election): def voter_list(request, election):
# normalize limit # normalize limit
limit = int(request.GET.get('limit', 500)) limit = int(request.GET.get('limit', 500))
...@@ -1365,7 +1365,7 @@ def voter_list(request, election): ...@@ -1365,7 +1365,7 @@ def voter_list(request, election):
return [v.ld_object.toDict() for v in voters] return [v.ld_object.toDict() for v in voters]
@election_view() @election_view()
@json @return_json
def one_voter(request, election, voter_uuid): def one_voter(request, election, voter_uuid):
""" """
View a single voter's info as JSON. View a single voter's info as JSON.
...@@ -1376,7 +1376,7 @@ def one_voter(request, election, voter_uuid): ...@@ -1376,7 +1376,7 @@ def one_voter(request, election, voter_uuid):
return voter.toJSONDict() return voter.toJSONDict()
@election_view() @election_view()
@json @return_json
def voter_votes(request, election, voter_uuid): def voter_votes(request, election, voter_uuid):
""" """
all cast votes by a voter all cast votes by a voter
...@@ -1386,7 +1386,7 @@ def voter_votes(request, election, voter_uuid): ...@@ -1386,7 +1386,7 @@ def voter_votes(request, election, voter_uuid):
return [v.toJSONDict() for v in votes] return [v.toJSONDict() for v in votes]
@election_view() @election_view()
@json @return_json
def voter_last_vote(request, election, voter_uuid): def voter_last_vote(request, election, voter_uuid):
""" """
all cast votes by a voter all cast votes by a voter
...@@ -1399,7 +1399,7 @@ def voter_last_vote(request, election, voter_uuid): ...@@ -1399,7 +1399,7 @@ def voter_last_vote(request, election, voter_uuid):
## ##
@election_view() @election_view()
@json @return_json
def ballot_list(request, election): def ballot_list(request, election):
""" """
this will order the ballots from most recent to oldest. this will order the ballots from most recent to oldest.
......
...@@ -57,21 +57,24 @@ import mimetypes ...@@ -57,21 +57,24 @@ import mimetypes
# try to use simplejson first, otherwise fallback to XML # try to use simplejson first, otherwise fallback to XML
RESPONSE_FORMAT = 'JSON' RESPONSE_FORMAT = 'JSON'
try:
import json as simplejson import json
except ImportError:
try: # try:
import simplejson # import json as simplejson
except ImportError: # except ImportError:
try: # try:
from django.utils import simplejson # import simplejson
except ImportError: # except ImportError:
try: # try:
import jsonlib as simplejson # from django.utils import simplejson
simplejson.loads # except ImportError:
except (ImportError, AttributeError): # try:
from xml.dom import minidom # import jsonlib as simplejson
RESPONSE_FORMAT = 'XML' # simplejson.loads
# except (ImportError, AttributeError):
# from xml.dom import minidom
# RESPONSE_FORMAT = 'XML'
# support Google App Engine. GAE does not have a working urllib.urlopen. # support Google App Engine. GAE does not have a working urllib.urlopen.
try: try:
......
from django.http import HttpResponse from django.http import HttpResponse
from django.views.generic.simple import direct_to_template # from django.views.generic.simple import direct_to_template
#uncomment the following two lines and the one below #uncomment the following two lines and the one below
#if you dont want to use a decorator instead of the middleware #if you dont want to use a decorator instead of the middleware
#from django.utils.decorators import decorator_from_middleware #from django.utils.decorators import decorator_from_middleware
...@@ -30,7 +30,8 @@ def canvas(request): ...@@ -30,7 +30,8 @@ def canvas(request):
# User is guaranteed to be logged in, so pass canvas.fbml # User is guaranteed to be logged in, so pass canvas.fbml
# an extra 'fbuser' parameter that is the User object for # an extra 'fbuser' parameter that is the User object for
# the currently logged in user. # the currently logged in user.
return direct_to_template(request, 'canvas.fbml', extra_context={'fbuser': user}) #return direct_to_template(request, 'canvas.fbml', extra_context={'fbuser': user})
return None
@facebook.require_login() @facebook.require_login()
def ajax(request): def ajax(request):
......
...@@ -11,7 +11,6 @@ from django.template import loader ...@@ -11,7 +11,6 @@ from django.template import loader
from django import http from django import http
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse as reverseURL from django.core.urlresolvers import reverse as reverseURL
from django.views.generic.simple import direct_to_template
from django.conf import settings from django.conf import settings
...@@ -141,13 +140,3 @@ def normalDict(request_data): ...@@ -141,13 +140,3 @@ def normalDict(request_data):
""" """
return dict((k, v[0]) for k, v in request_data.iteritems()) return dict((k, v[0]) for k, v in request_data.iteritems())
def renderXRDS(request, type_uris, endpoint_urls):
"""Render an XRDS page with the specified type URIs and endpoint
URLs in one service block, and return a response with the
appropriate content-type.
"""
response = direct_to_template(
request, 'xrds.xml',
{'type_uris':type_uris, 'endpoint_urls':endpoint_urls,})
response['Content-Type'] = YADIS_CONTENT_TYPE
return response
from django import http from django import http
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.views.generic.simple import direct_to_template
from openid.consumer import consumer from openid.consumer import consumer
from openid.consumer.discover import DiscoveryFailure from openid.consumer.discover import DiscoveryFailure
......
...@@ -4,11 +4,10 @@ taken from ...@@ -4,11 +4,10 @@ taken from
http://www.djangosnippets.org/snippets/377/ http://www.djangosnippets.org/snippets/377/
""" """
import datetime import datetime, json
from django.db import models from django.db import models
from django.db.models import signals from django.db.models import signals
from django.conf import settings from django.conf import settings
from django.utils import simplejson as json
from django.core.serializers.json import DjangoJSONEncoder from django.core.serializers.json import DjangoJSONEncoder
class JSONField(models.TextField): class JSONField(models.TextField):
......
...@@ -4,7 +4,7 @@ Authentication URLs ...@@ -4,7 +4,7 @@ Authentication URLs
Ben Adida (ben@adida.net) Ben Adida (ben@adida.net)
""" """
from django.conf.urls.defaults import * from django.conf.urls import *
from views import * from views import *
from auth_systems.password import password_login_view, password_forgotten_view from auth_systems.password import password_login_view, password_forgotten_view
......
...@@ -5,18 +5,18 @@ Some basic utils ...@@ -5,18 +5,18 @@ Some basic utils
2010-08-17 2010-08-17
""" """
from django.utils import simplejson import json
## JSON ## JSON
def to_json(d): def to_json(d):
return simplejson.dumps(d, sort_keys=True) return json.dumps(d, sort_keys=True)
def from_json(json_str): def from_json(json_str):
if not json_str: return None if not json_str: return None
return simplejson.loads(json_str) return json.loads(json_str)
def JSONtoDict(json): def JSONtoDict(json):
x=simplejson.loads(json) x=json.loads(json)
return x return x
def JSONFiletoDict(filename): def JSONFiletoDict(filename):
......
Django==1.4.18 Django==1.6.10
South==0.8.2 South==0.8.2
anyjson==0.3.1 anyjson==0.3.1
celery==3.0.16 celery==3.0.16
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.conf.urls.defaults import * from django.conf.urls import *
from views import * from views import *
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.conf.urls.defaults import * from django.conf.urls import *
from django.contrib import admin from django.contrib import admin
from django.conf import settings from django.conf import settings
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment