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


Python User.supervisor方法代码示例

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


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

示例1: add_users

# 需要导入模块: from app.users.models import User [as 别名]
# 或者: from app.users.models.User import supervisor [as 别名]
def add_users():
    form = AddUserForms(request.form)
    all_users = User.query.all()
    form.select_role.choices = [(role.id, role.name)        ## Loads up choices
                                for role in Role.query.all()] 
    ## load roles that had supervisor roles in it:
 

    form.select_supervisor.choices = [(user.username, user.username)
                                     for user in User.query.all() if user.is_supervisor]

    print form.select_role.choices 
    if form.validate_on_submit():
        password = generate_password_hash('seer')       
        u = User (form.fname.data,form.midname.data,form.lname.data,    ## Load user
                  form.email.data,form.username.data,password)
        print form.select_role.data

        for i in form.select_role.data:  ## Loads up the selected choices of the user
            print i 
            u.role.append(Role.query.get(i))
        print u.role

        ##Checks if the user is a supervisor
        if form.check_if_supervisor.data:
            u.is_supervisor = True

        ## Loads up the supervisor of the user, and loads up the user to its supervisor
        u.supervisor = form.select_supervisor.data
        print form.select_supervisor.data

        supervisor = User.query.filter_by(username=form.select_supervisor.data).first()
        if supervisor.supervisee is None or '': 
            
            supervisor.supervisee = u.username
            print supervisor.supervisee
        else:
            supervisor.supervisee = supervisor.supervisee + ' ' + u.username
            print supervisor.supervisee

        db_session.add(u)
        db_session.add(supervisor)
        db_session.commit()

        us = UserStatistics(userId=u.id)
        us.sl = form.number_of_sick_leaves.data
        us.vl = form.number_of_vacation_leaves.data
        us.offset = 0
        db_session.add(us)
        db_session.commit()
        flash('User Created')
        return redirect(url_for('Users.add_users'))
    return render_template('admin/add_user.html', form = form)
开发者ID:blouiecubero,项目名称:projectIRIS,代码行数:55,代码来源:controllers.py


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