Пример #1
0
def get_local_results(offset, size, category, user):
    localresult = TallstreetUniverse.get_results(offset, size, category)
    results = []
    for result in localresult:
        result.urlkey = result._url.id_or_name()
        try:
            if not cache.get("url:" + urlquote(result._url.id_or_name())):
                url = result.url
        except:
            logging.error("No url")
            continue
        i = 0
        related_keywords_display = []
        for related_keywords in result.url.related_keywords:
            if i > 5:
                break
            i += 1
            related_keywords_display.append(related_keywords)

        result.url.related_keywords_display = related_keywords_display
        if user and user.is_authenticated():
            portfolio = TallstreetPortfolio.get_invested(user, result._url, category)
            if portfolio:
                result.money_invested = portfolio.money
        results.append(result)

    return results
Пример #2
0
def update_portfolio(user, keyword, url, investment, ip):
	portfolio = TallstreetPortfolio.get_invested(user, url, keyword)
	if not(portfolio):
		portfolio = TallstreetPortfolio(parent=user, key_name='url%skeyword%s' % (url.key(), keyword.key()))
		portfolio.url = url
		portfolio.keyword = keyword
		portfolio.user = user
		portfolio.money = investment
		if investment == 0:
			return 0
		change = investment
	else:
		change = investment - portfolio.money
		if change == 0:
			return 0
		portfolio.money = investment
	if user.money_outstanding - change < 0:
		raise forms.ValidationError("No Money left in account.")
	
	user.money_outstanding -= change
	if investment == 0:
		portfolio.delete()
		portfolio = None
	else:
		portfolio.put()
	transaction = TallstreetTransaction(parent=user, change=change, new_amount=investment, account_balance=user.money, account_balance_outstanding=user.money_outstanding, portfolio=portfolio, user=user, ip=ip)
	if change > 0:
		transaction.description = "Bought in [%s] under %s" % (url.key().id_or_name(), keyword.tag)
	else:
		transaction.description = "Sold in [%s] under %s" % (url.key().id_or_name(), keyword.tag)
	transaction.put()
	
	user.put()
	return change
Пример #3
0
def update_portfolio_gain(user, url, keyword, gain):
	portfolio = TallstreetPortfolio.get_invested(user, url, keyword)
	change = long(round(portfolio.money * (1.0 * gain / 100)))

	if change == 0:
		return 0	
	portfolio.money = portfolio.money + change
		
	user.money += change
	if portfolio.money <= 0:
		portfolio.delete()
		portfolio = None
	else:
		portfolio.put()
	transaction = TallstreetTransaction(parent=user, change=change, new_amount=portfolio.money, account_balance=user.money, account_balance_outstanding=user.money_outstanding, portfolio=portfolio, user=user)
	if change > 0:
		transaction.description = "Gained in [%s] under %s" % (url.key().id_or_name(), keyword.tag)
	else:
		transaction.description = "Lost in [%s] under %s" % (url.key().id_or_name(), keyword.tag)
	transaction.put()
	
	user.put()
	return change