def billing_view(request):
"""Shows CC info and transaction history."""
user_profile = UserProfile.objects.get(user=request.user)
network = user_profile.network
transactions = (network.ledger.transaction_set.filter(
kind__in=["credit", "adjustment"]).order_by('-created'))
transaction_paginator = Paginator(transactions, 10)
page = request.GET.get('page', 1)
try:
transactions = transaction_paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
transactions = transaction_paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
num_pages = transaction_paginator.num_pages
transactions = transaction_paginator.page(num_pages)
context = {
'networks': get_objects_for_user(request.user, 'view_network', klass=Network),
'user_profile': user_profile,
'transactions': transactions
}
# deal with messages; template needs to explicitly handle messages
msgs = messages.get_messages(request)
for m in msgs:
if "billing_resp_code" in m.tags:
context[m.message] = True # pass the message on to the template as-is
if network.stripe_card_type == "American Express":
context['card_type'] = 'AmEx'
else:
context['card_type'] = network.stripe_card_type
# Pass in card types that have icons.
context['cards_with_icons'] = ['Visa', 'AmEx', 'MasterCard', 'Discover']
t = get_template("dashboard/billing.html")
html = t.render(context, request)
return HttpResponse(html)
dashboard.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录