def _get_demo_portfolio(portfolio_id): if portfolio_id != None: candidate = Portfolio.objects.filter(id = portfolio_id) if candidate.count() == 1: return candidate[0] else: portfolio = create_portfolio(get_demo_user(), ('SAMPLE #%d' % random.randint(100000000, 999999999))) for sample_transaction in get_demo_transactions(): transaction = clone_transaction(sample_transaction, portfolio); transaction.save() return portfolio
def login(request): token = None if request.method == 'POST': token = request.POST.get('token') else: token = request.GET.get('token') if token == None: return redirect("/demo.html?loginFailed=true") u = None try: u = urlopen('https://rpxnow.com/api/v2/auth_info?apiKey=%s&token=%s' % (JANRAIN_API_KEY, token)) auth_info = json.loads(u.read()) status = auth_info['stat'] if status != 'ok': return redirect("/demo.html?loginFailed=true") profile = auth_info['profile'] identifier = profile['identifier'] email = profile['email'] if profile.has_key('email') else None candidate = User.objects.filter(open_id = identifier) user = None portfolio = None target = 'transactions' if candidate.count() == 0: user = create_user(identifier, email) portfolio = create_portfolio(user, 'Default') else: user = candidate[0] portfolio = Portfolio.objects.filter(user__id__exact = user.id)[0] target = 'positions' request.session['user_id'] = user.id return redirect_to_portfolio_action(target, portfolio) finally: if u != None: u.close()