本文整理汇总了Python中models.users.Users.add_private_user方法的典型用法代码示例。如果您正苦于以下问题:Python Users.add_private_user方法的具体用法?Python Users.add_private_user怎么用?Python Users.add_private_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.users.Users
的用法示例。
在下文中一共展示了Users.add_private_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_private
# 需要导入模块: from models.users import Users [as 别名]
# 或者: from models.users.Users import add_private_user [as 别名]
def add_private():
'''Add a private user connection for a user'''
error = None
if request.method == 'POST':
new_user_name, current_user_id = request.form['name'], session.get('logged_in_user')
# setup objects in a context
useri = Users(current_user_id)
# blank name?
if new_user_name:
# already exists?
if not useri.is_connection(name=new_user_name):
# create new private user
new_user_id = useri.add_private_user(new_user_name)
# give the user a default account so we can do loans
acc = Accounts(new_user_id)
acc.add_default_account()
# have we provided initial balance?
if 'balance' in request.form:
# get balance
balance = request.form['balance']
# balance could be "empty"
if balance != "":
# valid amount?
if is_float(balance):
balance = float(balance)
# do we have a pre-existing balance with the user?
if balance != 0:
if balance > 0: # they owe us
# models
loa, acc = Loans(current_user_id), Accounts(current_user_id)
# add loan entry
loa.add_loan(other_user_id=new_user_id, date=today_date(),
account_id=acc.get_default_account(),
description="Initial balance with the user", amount=balance)
# fudge loan monies balance
acc.modify_loan_balance(amount=balance, with_user_id=new_user_id)
else: # we owe them
# models
loa, acc = Loans(new_user_id), Accounts(current_user_id)
# add loan entry
loa.add_loan(other_user_id=current_user_id, date=today_date(),
account_id=acc.get_default_account(),
description="Initial balance with the user", amount=-balance)
# fudge loan monies balance
acc.modify_loan_balance(amount=balance, with_user_id=new_user_id)
else: error = 'Not a valid amount'
# create connections from us to them and back
useri.add_connection(new_user_id)
flash('Private user added')
else: error = 'You already have a user under that name'
else: error = 'You need to provide a name'
return render_template('admin_add_private_user.html', **locals())