[go: up one dir, main page]

Menu

[r728]: / trunk / demo / journal / views.py  Maximize  Restore  History

Download this file

142 lines (100 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Create your views here.
import decimal, re
from django.conf import settings
from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse
from django.core.context_processors import csrf
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotAllowed, Http404
from signup.decorators import has_profile
from modules import curiousorm, utils
db = curiousorm.Database(settings.DEMO_DSN)
_HANDOFF_FIELD = re.compile('^handoff-(\d{1,13})-(\d{1,13})-(\d{1,13})$')
@has_profile(db)
def show_unconfirmed_transactions(request, user, tmpl):
if request.method == 'POST':
# TODO: Do not rely on the garbage collector for connection closing.
confirmed = 0
trx = db.transaction()
for field_name in request.POST:
hof = _HANDOFF_FIELD.match(field_name)
if hof:
turn_id, issuer_id, deal_id = (int(i) for i in hof.group(1, 2, 3))
trx.confirm_transaction(turn_id, user['trader_id'], issuer_id, deal_id)
confirmed += 1
trx.commit()
return HttpResponseRedirect(reverse(
report_transactions_confirmation,
args=[user['trader_id'], confirmed]))
transactions = db.select_unconfirmed_transaction_list(
recipient_id=user['trader_id'],
__order_by='ts DESC')
# Render everything adding CSRF protection.
c = {'user': user, 'transactions' : transactions }
c.update(csrf(request))
return render_to_response(tmpl, c)
@has_profile(db)
def report_transactions_confirmation(request, user, count, tmpl):
# Render everything adding CSRF protection.
c = {'user': user, 'count': int(count) }
c.update(csrf(request))
return render_to_response(tmpl, c)
@has_profile(db)
def show_unconfirmed_deals(request, user, tmpl):
if request.method == 'POST':
# TODO: Do not rely on the garbage collector for connection closing.
confirmed = 0
trx = db.transaction()
for field_name in request.POST:
if field_name.startswith('turn-'):
confirmed += trx.delete_finalized_session(user['trader_id'], int(field_name[5:]))
#trx.commit()
trx.rollback()
return HttpResponseRedirect(reverse(
report_deals_confirmation,
args=[user['trader_id'], confirmed]))
new_deals = db.select_new_deal_list(
recipient_id=user['trader_id'],
__order_by='ts DESC')
turns = set([d['turn_id'] for d in new_deals])
c = {'user': user, 'new_deals' : new_deals, 'turns': turns }
c.update(csrf(request))
return render_to_response(tmpl, c)
@has_profile(db)
def report_deals_confirmation(request, user, count, tmpl):
# Render everything adding CSRF protection.
c = {'user': user, 'count': int(count) }
c.update(csrf(request))
return render_to_response(tmpl, c)
@has_profile(db)
def show_customer_transactions(request, user, year, mounth, day, tmpl):
# Render everything adding CSRF protection.
c = {'user': user, 'count': int(count) }
c.update(csrf(request))
return render_to_response(tmpl, c)
def show_todays_customer_transactions(request, user):
# Render everything adding CSRF protection.
c = {'user': user, 'count': int(count) }
c.update(csrf(request))
return render_to_response(tmpl, c)
@has_profile(db)
def show_customer_deals(request, user, year, mounth, day, tmpl):
# Render everything adding CSRF protection.
c = {'user': user, 'count': int(count) }
c.update(csrf(request))
return render_to_response(tmpl, c)
def show_todays_customer_deals(request, user):
# Render everything adding CSRF protection.
c = {'user': user, 'count': int(count) }
c.update(csrf(request))
return render_to_response(tmpl, c)
@has_profile(db)
def show_my_deals(request, user, year, mounth, day, tmpl):
# Render everything adding CSRF protection.
c = {'user': user, 'count': int(count) }
c.update(csrf(request))
return render_to_response(tmpl, c)
def show_my_todays_deals(request, user):
# Render everything adding CSRF protection.
c = {'user': user, 'count': int(count) }
c.update(csrf(request))
return render_to_response(tmpl, c)