Example #1
0
def show_team():
    # 判断用户权限
    judge(g.user['level'])
    if request.method == 'POST':
        team_name = request.form['team_name']
        db = get_db()
        posts = db.execute(
            '''
            SELECT t.id,t.team_name,t.team_describe,
            (SELECT COUNT(*) FROM user u WHERE u.team_id=t.id) AS team_count
            FROM team t WHERE team_name=?
            ''', (team_name, )).fetchall()
    else:
        db = get_db()
        posts = db.execute('''
            SELECT t.id,t.team_name,t.team_describe,
            (SELECT COUNT(*) FROM user u WHERE u.team_id=t.id) AS team_count
            FROM team t
            ''').fetchall()
    pager_obj = Pagination(request.args.get("page", 1),
                           len(posts),
                           request.path,
                           request.args,
                           per_page_count=10)
    list = posts[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    return render_template('admin/team/show.html', list=list, html=html)
Example #2
0
def notice_user():
    db = get_db()
    if request.method == 'POST':
        search_name = request.form['search_name']
        name = '%' + request.form['name'] + '%'
        if search_name == '按标题搜索':
            posts = db.execute(
                nt_sql + '''
                AND cp_title LIKE ?
                ORDER BY cp_created DESC
                ''', (name, )).fetchall()
        else:
            posts = db.execute(
                nt_sql + '''
                AND username LIKE ?
                ORDER BY cp_created DESC
                ''', (name, )).fetchall()
    else:
        posts = db.execute(nt_sql + '''
            ORDER BY cp_created DESC
            ''').fetchall()
    pager_obj = Pagination(request.args.get("page", 1),
                           len(posts),
                           request.path,
                           request.args,
                           per_page_count=10)
    posts = posts[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    return render_template('user/notice/show.html', posts=posts, html=html)
Example #3
0
def not_allow():
    # 判断用户权限
    judge(g.user['level'])
    if request.method == 'POST':
        search_name = request.form['search_name']
        name = '%' + request.form['name'] + '%'
        db = get_db()
        # 按员工姓名搜索
        if search_name == '按员工姓名搜索':
            posts = db.execute(
                not_allow_sql + 'AND username LIKE ?' + order_by,
                (g.user['username'], name)).fetchall()
        # 按请假类型搜索
        elif search_name == '按请假类型搜索':
            posts = db.execute(
                not_allow_sql + 'AND leave_name LIKE ?' + order_by,
                (g.user['username'], name)).fetchall()
    else:
        db = get_db()
        posts = db.execute(not_allow_sql + order_by,
                           (g.user['username'], )).fetchall()
    # 分页
    pager_obj = Pagination(request.args.get("page", 1),
                           len(posts),
                           request.path,
                           request.args,
                           per_page_count=10)
    posts = posts[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    return render_template('admin/leave/not_allow.html',
                           posts=posts,
                           html=html)
Example #4
0
def show():
    # 判断用户权限
    judge(g.user['level'])
    db = get_db()
    if request.method == 'POST':
        search_name = request.form['search_name']
        # 变成模糊搜索格式
        name = '%' + request.form['name'] + '%'
        # 按姓名搜索
        if search_name == '按姓名搜索':
            posts = db.execute(sql + '''WHERE u.username LIKE ?''',
                               (name, )).fetchall()
        # 按性别搜索
        elif search_name == '按性别搜索':
            posts = db.execute(sql + '''WHERE u.sex LIKE ?''',
                               (name, )).fetchall()
        # 按权限搜索
        elif search_name == '按权限搜索':
            posts = db.execute(sql + '''WHERE u.level LIKE ?''',
                               (name, )).fetchall()
        # 按职位搜索
        elif search_name == '按职位搜索':
            posts = db.execute(sql + '''WHERE p_name LIKE ?''',
                               (name, )).fetchall()
        # 按所属团队搜索
        elif search_name == '按所属团队搜索':
            posts = db.execute(sql + '''WHERE t_name LIKE ?''',
                               (name, )).fetchall()
        # 按所属部门搜索
        elif search_name == '按所属部门搜索':
            posts = db.execute(sql + '''WHERE d_name LIKE ?''',
                               (name, )).fetchall()
    # 默认条件下展示所有员工
    else:
        posts = db.execute(sql).fetchall()
    '''
    current_page——表示当前页。
    total_count——表示数据总条数。
    base_url——表示分页URL前缀,请求的前缀获取可以通过Flask的request.path方法,无需自己指定。
    例如:我们的路由方法为@app.route('/test'),request.path方法即可获取/test。
    params——表示请求传入的数据,params可以通过request.args动态获取。
    例如:我们链接点击为:http://localhost:5000/test?page=10,此时request.args获取数据为ImmutableMultiDict([('page', u'10')])
    per_page_count——指定每页显示数。
    max_pager_count——指定页面最大显示页码
    '''
    # 分页
    pager_obj = Pagination(request.args.get("page", 1),
                           len(posts),
                           request.path,
                           request.args,
                           per_page_count=10)
    list = posts[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    return render_template('admin/personnel/show.html', list=list, html=html)
Example #5
0
def show_all():
    if request.method == 'POST':
        search_name = request.form['search_name']
        name = '%' + request.form['name'] + '%'
        db = get_db()
        if search_name == '按姓名搜索':
            posts = db.execute(
                sql + '''
                WHERE u.username LIKE ?
                ''', (name, )).fetchall()
        elif search_name == '按性别搜索':
            posts = db.execute(
                sql + '''
                WHERE u.sex LIKE ?
                ''', (name, )).fetchall()
        elif search_name == '按职位搜索':
            posts = db.execute(
                sql + '''
                WHERE p_name LIKE ?
                ''', (name, )).fetchall()
        elif search_name == '按所属团队搜索':
            posts = db.execute(
                sql + '''
                WHERE t_name LIKE ?
                ''', (name, )).fetchall()
        elif search_name == '按所属部门搜索':
            posts = db.execute(
                sql + '''
                WHERE d_name LIKE ?
                ''', (name, )).fetchall()
    else:
        db = get_db()
        posts = db.execute(sql).fetchall()
    pager_obj = Pagination(request.args.get("page", 1),
                           len(posts),
                           request.path,
                           request.args,
                           per_page_count=10)
    list = posts[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    return render_template('user/personnel/show_all.html',
                           list=list,
                           html=html)
Example #6
0
def level_leave():
    db = get_db()
    if request.method == 'POST':
        search_name = request.form['search_name']
        name = '%' + request.form['name'] + '%'
        if search_name == '按请假类型搜索':
            posts = db.execute(
                'SELECT * FROM leave WHERE leave_name LIKE ? AND username=? ORDER BY id DESC',
                (
                    name,
                    g.user['username'],
                )).fetchall()
        elif search_name == '按批复人搜索':
            posts = db.execute(
                'SELECT * FROM leave WHERE allow_name LIKE ? AND username=? ORDER BY id DESC',
                (
                    name,
                    g.user['username'],
                )).fetchall()
        elif search_name == '按批复状态搜索':
            posts = db.execute(
                'SELECT * FROM leave WHERE allow_level LIKE ? AND username=? ORDER BY id DESC',
                (
                    name,
                    g.user['username'],
                )).fetchall()
    else:
        posts = db.execute(
            'SELECT * FROM leave WHERE username=? ORDER BY id DESC',
            (g.user['username'], )).fetchall()
    pager_obj = Pagination(request.args.get("page", 1),
                           len(posts),
                           request.path,
                           request.args,
                           per_page_count=10)
    posts = posts[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    return render_template('user/leave/level.html', posts=posts, html=html)
Example #7
0
def show_user_dp():
    db = get_db()
    if request.method == 'POST':
        dp_name = request.form['dp_name']
        posts = db.execute(
            '''
            SELECT d.id,d.dp_name,d.dp_describe,
            (SELECT COUNT(*) FROM user u WHERE u.dp_id=d.id) AS dp_count
            FROM department d WHERE d.dp_name=?
            ''', (dp_name, )).fetchall()
    else:
        posts = db.execute('''
            SELECT d.id,d.dp_name,d.dp_describe,
            (SELECT COUNT(*) FROM user u WHERE u.dp_id=d.id) AS dp_count
            FROM department d
            ''').fetchall()
    pager_obj = Pagination(request.args.get("page", 1),
                           len(posts),
                           request.path,
                           request.args,
                           per_page_count=10)
    list = posts[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    return render_template('user/department.html', list=list, html=html)
Example #8
0
def show_user_pt():
    if request.method == 'POST':
        pt_name = request.form['pt_name']
        db = get_db()
        posts = db.execute(
            '''
            SELECT p.id,p.pt_name,p.pt_describe,
            (SELECT COUNT(*) FROM user u WHERE u.pt_id=p.id) AS pt_count
            FROM position p WHERE p.pt_name=?
        ''', (pt_name, ))
        li = []
        for post in posts:
            li.append(post)
        pager_obj = Pagination(request.args.get("page", 1),
                               len(li),
                               request.path,
                               request.args,
                               per_page_count=10)
        list = li[pager_obj.start:pager_obj.end]
        html = pager_obj.page_html()
        return render_template('user/position.html', list=list, html=html)
    else:
        db = get_db()
        posts = db.execute('''
            SELECT p.id,p.pt_name,p.pt_describe,
            (SELECT COUNT(*) FROM user u WHERE u.pt_id=p.id) AS pt_count
            FROM position p
            ''')
        li = []
        for post in posts:
            li.append(post)
        pager_obj = Pagination(request.args.get("page", 1),
                               len(li),
                               request.path,
                               request.args,
                               per_page_count=10)
        list = li[pager_obj.start:pager_obj.end]
        html = pager_obj.page_html()
        return render_template('user/position.html', list=list, html=html)
Example #9
0
def show_user_dp_same():
    db = get_db()
    # 拿到部门的名称
    d_posts = db.execute(
        '''
        SELECT dp_name FROM department WHERE id=?
        ''', (g.user['dp_id'], ))
    # 按条件搜索时
    if request.method == 'POST':
        search_name = request.form['search_name']
        name = '%' + request.form['name'] + '%'
        # 按姓名搜索
        if search_name == '按姓名搜索':
            posts = db.execute(
                '''
                SELECT u.id,u.username,u.sex,u.email,u.tel,
                (SELECT t.team_name FROM team t WHERE u.team_id = t.id) AS t_name,
                (SELECT p.pt_name FROM position p WHERE u.pt_id = p.id) AS p_name
                FROM user u WHERE u.dp_id=? AND u.username LIKE ?
                ''', (
                    g.user['dp_id'],
                    name,
                )).fetchall()
        # 按性别搜索
        elif search_name == '按性别搜索':
            posts = db.execute(
                '''
                SELECT u.id,u.username,u.sex,u.email,u.tel,
                (SELECT t.team_name FROM team t WHERE u.team_id = t.id) AS t_name,
                (SELECT p.pt_name FROM position p WHERE u.pt_id = p.id) AS p_name
                FROM user u WHERE u.dp_id=? AND u.sex LIKE ?
                ''', (
                    g.user['dp_id'],
                    name,
                )).fetchall()
        # 按职位搜索
        elif search_name == '按职位搜索':
            posts = db.execute(
                '''
                SELECT u.id,u.username,u.sex,u.email,u.tel,
                (SELECT t.team_name FROM team t WHERE u.team_id = t.id) AS t_name,
                (SELECT p.pt_name FROM position p WHERE u.pt_id = p.id) AS p_name
                FROM user u WHERE u.dp_id=? AND p_name LIKE ?
                ''', (
                    g.user['dp_id'],
                    name,
                )).fetchall()
        # 按所属团队搜索
        elif search_name == '按所属团队搜索':
            posts = db.execute(
                '''
                SELECT u.id,u.username,u.sex,u.email,u.tel,
                (SELECT t.team_name FROM team t WHERE u.team_id = t.id) AS t_name,
                (SELECT p.pt_name FROM position p WHERE u.pt_id = p.id) AS p_name
                FROM user u WHERE u.dp_id=? AND t_name LIKE ?
                ''', (
                    g.user['dp_id'],
                    name,
                )).fetchall()
    else:
        # 拿到同部门同事的参数
        posts = db.execute(
            '''
            SELECT u.id,u.username,u.sex,u.email,u.tel,
            (SELECT t.team_name FROM team t WHERE u.team_id = t.id) AS t_name,
            (SELECT p.pt_name FROM position p WHERE u.pt_id = p.id) AS p_name
            FROM user u WHERE u.dp_id=?
            ''', (g.user['dp_id'], )).fetchall()
    pager_obj = Pagination(request.args.get("page", 1),
                           len(posts),
                           request.path,
                           request.args,
                           per_page_count=10)
    list = posts[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    return render_template('user/department/show_same.html',
                           list=list,
                           html=html,
                           d_posts=d_posts)