Mercurial > public > sg101
comparison donations/views.py @ 1031:e1c03da72818
Get rid of some warnings in Django 1.8.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 20 Dec 2015 22:18:59 -0600 |
parents | ee87ea74d46b |
children | 75189bd9c4ba |
comparison
equal
deleted
inserted
replaced
1030:d9610b1e2a3d | 1031:e1c03da72818 |
---|---|
4 import urllib2 | 4 import urllib2 |
5 import decimal | 5 import decimal |
6 import datetime | 6 import datetime |
7 import logging | 7 import logging |
8 | 8 |
9 from django.shortcuts import render_to_response | 9 from django.shortcuts import render |
10 from django.template import RequestContext | |
11 from django.conf import settings | 10 from django.conf import settings |
12 from django.contrib.sites.models import Site | 11 from django.contrib.sites.models import Site |
13 from django.http import HttpResponse | 12 from django.http import HttpResponse |
14 from django.http import HttpResponseServerError | |
15 from django.contrib.auth.models import User | 13 from django.contrib.auth.models import User |
16 from django.views.decorators.csrf import csrf_exempt | 14 from django.views.decorators.csrf import csrf_exempt |
17 | 15 |
18 | 16 |
19 from donations.models import Donation | 17 from donations.models import Donation |
47 | 45 |
48 req = urllib2.Request(paypal_params()[0], params) | 46 req = urllib2.Request(paypal_params()[0], params) |
49 req.add_header("Content-type", "application/x-www-form-urlencoded") | 47 req.add_header("Content-type", "application/x-www-form-urlencoded") |
50 try: | 48 try: |
51 response = urllib2.urlopen(req) | 49 response = urllib2.urlopen(req) |
52 except URLError, e: | 50 except urllib2.URLError as ex: |
53 logging.exception('IPN: exception verifying IPN: %s', e) | 51 logging.exception('IPN: exception verifying IPN: %s', ex) |
54 return None | 52 return None |
55 | 53 |
56 return response.read() | 54 return response.read() |
57 | 55 |
58 | 56 |
59 def index(request): | 57 def index(request): |
60 gross, net, donations = Donation.objects.monthly_stats() | 58 gross, net, donations = Donation.objects.monthly_stats() |
61 current_site = Site.objects.get_current() | 59 current_site = Site.objects.get_current() |
62 form_action, business = paypal_params() | 60 form_action, business = paypal_params() |
63 | 61 |
64 return render_to_response('donations/index.html', { | 62 return render(request, 'donations/index.html', { |
65 'goal': settings.DONATIONS_GOAL, | 63 'goal': settings.DONATIONS_GOAL, |
66 'gross': gross, | 64 'gross': gross, |
67 'net': net, | 65 'net': net, |
68 'left': settings.DONATIONS_GOAL - net, | 66 'left': settings.DONATIONS_GOAL - net, |
69 'donations': donations, | 67 'donations': donations, |
72 'anonymous': settings.DONATIONS_ANON_NAME, | 70 'anonymous': settings.DONATIONS_ANON_NAME, |
73 'item_name': settings.DONATIONS_ITEM_NAME, | 71 'item_name': settings.DONATIONS_ITEM_NAME, |
74 'item_number': settings.DONATIONS_ITEM_NUM, | 72 'item_number': settings.DONATIONS_ITEM_NUM, |
75 'item_anon_number': settings.DONATIONS_ITEM_ANON_NUM, | 73 'item_anon_number': settings.DONATIONS_ITEM_ANON_NUM, |
76 'domain': current_site.domain, | 74 'domain': current_site.domain, |
77 }, | 75 }) |
78 context_instance = RequestContext(request)) | |
79 | 76 |
80 | 77 |
81 @csrf_exempt | 78 @csrf_exempt |
82 def ipn(request): | 79 def ipn(request): |
83 """ | 80 """ |
216 except: | 213 except: |
217 logging.exception('IPN: exception during donation creation') | 214 logging.exception('IPN: exception during donation creation') |
218 else: | 215 else: |
219 donation.save() | 216 donation.save() |
220 logging.info('IPN: donation saved') | 217 logging.info('IPN: donation saved') |
221 |