当前位置: 首页>>代码示例>>Python>>正文


Python Users.add_connection方法代码示例

本文整理汇总了Python中models.users.Users.add_connection方法的典型用法代码示例。如果您正苦于以下问题:Python Users.add_connection方法的具体用法?Python Users.add_connection怎么用?Python Users.add_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.users.Users的用法示例。


在下文中一共展示了Users.add_connection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: connect_with_user

# 需要导入模块: from models.users import Users [as 别名]
# 或者: from models.users.Users import add_connection [as 别名]
def connect_with_user():
    '''Make a connection with a 'normal' user'''

    error = None
    current_user_id = session.get('logged_in_user')

    if request.method == 'POST':
        # fetch values and check they are actually provided
        if 'key' in request.form:
            key_value = request.form['key']

            useri = Users(current_user_id)

            key_user_id = useri.validate_key(key_value)

            # valid key
            if key_user_id:
                # cannot connect to ourselves and make a connection that has already been made ;)
                if not key_user_id == current_user_id and not useri.is_connection(user_id=key_user_id):

                    # create connections from us to them and back
                    useri.add_connection(key_user_id)

                    flash('Connection made')

                else: error = 'I can haz myself impossible'
            else: error = 'Invalid key'
        else: error = 'You need to provide a key'

    return render_template('admin_connect_with_user.html', **locals())
开发者ID:egeriicw,项目名称:FlaskBudget,代码行数:32,代码来源:users.py

示例2: add_private

# 需要导入模块: from models.users import Users [as 别名]
# 或者: from models.users.Users import add_connection [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())
开发者ID:egeriicw,项目名称:FlaskBudget,代码行数:64,代码来源:users.py


注:本文中的models.users.Users.add_connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。