Files
@ 6fe13959a3b3
Branch filter:
Location: website/www/conservancy/__init__.py - annotation
6fe13959a3b3
928 B
text/x-python
supporter: Support donors upgrading to supporters.
With a valid URL, a past donor can upgrade to a supporter by donating
the rest of the amount. Django validates the data and, if it passes,
puts it in the form. The JavaScript does most of the work from there.
With a valid URL, a past donor can upgrade to a supporter by donating
the rest of the amount. Django validates the data and, if it passes,
puts it in the form. The JavaScript does most of the work from there.
6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 8fec6023e964 8fec6023e964 8fec6023e964 6fe13959a3b3 6fe13959a3b3 8fec6023e964 8fec6023e964 8fec6023e964 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 6fe13959a3b3 | import hashlib
from django.conf import settings
from django.shortcuts import render_to_response
from django.template import RequestContext
HASH_ENCODING = 'utf-8'
def render_template_with_context(request, template_path, context_dict):
return render_to_response(template_path, context_dict,
context_instance=RequestContext(request))
def param_if_valid(params, param_name, hash_param_name, default=None):
try:
seed = settings.CONSERVANCY_SECRET_KEY
param_value = params[param_name]
param_bytes = param_value.encode(HASH_ENCODING)
given_hash = params[hash_param_name]
except (AttributeError, KeyError, UnicodeEncodeError):
return default
good_hash = hashlib.sha256()
good_hash.update(seed)
good_hash.update(param_bytes)
if given_hash == unicode(good_hash.hexdigest()):
return param_value
else:
return default
|