Ejemplo n.º 1
0
def ticket():
    ticket_form = TicketForm()
    sidebar = copy.deepcopy(start_sidebar)
    sidebar = init_sidebar(sidebar, now, 'put_task')
    if request.method == "GET":
        search_value = request.args.get('search', '')
        if search_value:
            sidebar = init_sidebar(sidebar, now, "my_task")
            page = int(request.args.get('page', 1))
            result = search(Task, 'title', search_value)
            result = result.search_return()
            if result:
                pagination = result.paginate(page, 100, False)
                items = pagination.items
                return render_template('task/ticket.html',
                                       sidebar=sidebar,
                                       ticket_form=ticket_form,
                                       search_value=search_value,
                                       thead=thead,
                                       pagination=pagination,
                                       endpoint=endpoint,
                                       items=items)

    if request.method == "POST":
        if request.form['action'] == 'put_task':
            idebar = init_sidebar(sidebar, now, 'put_task')
            if ticket_form.validate_on_submit():
                task = Task(author=current_user.username,
                            title=ticket_form.title.data,
                            task=ticket_form.task.data,
                            site=ticket_form.site.data,
                            body=ticket_form.body.data,
                            status=u"审核")
                add_sql = edit(current_user.username,
                               task,
                               "title",
                               record=False)
                add_sql.run('add')
                flash(u'任务添加成功 可以继续添加新的任务')
            else:
                for key in check_field:
                    if ticket_form.errors.get(key, None):
                        flash(ticket_form.errors[key][0])
                        break

    return render_template('task/ticket.html',
                           sidebar=sidebar,
                           thead=thead,
                           ticket_form=ticket_form)
Ejemplo n.º 2
0
def ticket():
    ticket_form = TicketForm()
    sidebar = copy.deepcopy(start_sidebar)
    sidebar = init_sidebar(sidebar, now, 'put_task')
    if request.method == "GET":
        search_value = request.args.get('search', '')
        if search_value:
            sidebar = init_sidebar(sidebar, now, "my_task")
            page = int(request.args.get('page', 1))
            result = search(Task, 'title' , search_value)
            result = result.search_return()
            if result:
                pagination = result.paginate(page, 100, False)
                items = pagination.items
                return render_template(
                    'task/ticket.html', sidebar=sidebar, ticket_form=ticket_form, 
                    search_value=search_value, thead=thead, pagination=pagination,
                    endpoint=endpoint, items=items
                )

    if request.method == "POST":
        if request.form['action'] == 'put_task':
            idebar = init_sidebar(sidebar, now,'put_task')
            if ticket_form.validate_on_submit():
                task = Task(
                    author=current_user.username,
                    title=ticket_form.title.data,
                    task=ticket_form.task.data,
                    site=ticket_form.site.data,
                    body=ticket_form.body.data,
                    status=u"审核"
                )
                add_sql = edit(current_user.username, task, "title", record=False )
                add_sql.run('add')
                flash(u'任务添加成功 可以继续添加新的任务')
            else:
                for key in check_field :
                    if ticket_form.errors.get(key, None):
                        flash(ticket_form.errors[key][0])
                        break

    return render_template(
        'task/ticket.html', sidebar=sidebar, thead=thead, ticket_form=ticket_form
    )
Ejemplo n.º 3
0
def users_setting():
    '''用户设置'''
    role_permission = getattr(Permission, current_user.role)
    passwd_form = ChangePasswordForm()
    register_form = RegistrationForm()
    sidebar = copy.deepcopy(start_sidebar)
    thead = copy.deepcopy(start_thead)
    sidebar = init_sidebar(sidebar, now, 'passwd')
    search_value = ''
    if request.method == "POST":
        # 更改密码
        if request.form['action'] == 'passwd':
            sidebar = init_sidebar(sidebar, now, 'passwd')
            if passwd_form.validate_on_submit():
                if current_user.verify_password(passwd_form.old_password.data):
                    value = passwd_form.password.data
                    change_sql = edit(current_user.username, current_user,
                                      "password", value)
                    change_sql.run('change')
                    flash(u'密码更改成功')
                else:
                    flash(u'旧密码错误')
            else:
                for key in passwd_form.errors.keys():
                    flash(passwd_form.errors[key][0])
        # 用户注册
        if request.form[
                'action'] == 'register' and role_permission >= Permission.ADMIN:
            sidebar = init_sidebar(sidebar, now, 'register')
            if register_form.validate_on_submit():
                user = User(username=register_form.username.data,
                            password=register_form.password.data,
                            alias=register_form.alias.data,
                            role=register_form.role.data)
                add_sql = edit(current_user.username, user, "username")
                add_sql.run('add')
                flash(u'用户添加成功')
            else:
                for thead in start_thead:
                    key = thead[2]
                    if register_form.errors.get(key, None):
                        flash(register_form.errors[key][0])
                        break
    if request.method == "GET":
        search_value = request.args.get('search', '')
        checkbox = request.args.getlist('hidden') or request.args.get(
            'hiddens', '')
        if search_value:
            # 搜索
            thead = init_checkbox(thead, checkbox)
            sidebar = init_sidebar(sidebar, now, 'edituser')
            page = int(request.args.get('page', 1))
            result = search(User, 'username', search_value)
            result = result.search_return()
            if result:
                pagination = result.paginate(page, 100, False)
                items = pagination.items
                return render_template('auth/setting.html',
                                       sidebar=sidebar,
                                       passwd_form=passwd_form,
                                       register_form=register_form,
                                       search_value=search_value,
                                       checkbox=str(checkbox),
                                       thead=thead,
                                       endpoint=endpoint,
                                       pagination=pagination,
                                       items=items)
    return render_template('auth/setting.html',
                           sidebar=sidebar,
                           search_value=search_value,
                           passwd_form=passwd_form,
                           register_form=register_form,
                           thead=thead)
Ejemplo n.º 4
0
def users_setting():
    '''用户设置'''
    role_permission = getattr(Permission, current_user.role)
    passwd_form = ChangePasswordForm()
    register_form = RegistrationForm()
    sidebar = copy.deepcopy(start_sidebar)
    thead = copy.deepcopy(start_thead)
    sidebar = init_sidebar(sidebar, now,'passwd')
    search_value = ''
    if request.method == "POST":
        # 更改密码
        if request.form['action'] == 'passwd':
            sidebar = init_sidebar(sidebar, now,'passwd')
            if passwd_form.validate_on_submit():
                if current_user.verify_password(passwd_form.old_password.data):
                    value = passwd_form.password.data
                    change_sql = edit(current_user.username, current_user, "password", value)
                    change_sql.run('change')
                    flash(u'密码更改成功')
                else:
                    flash(u'旧密码错误')
            else:
                for key in passwd_form.errors.keys():
                    flash(passwd_form.errors[key][0])
        # 用户注册
        if request.form['action'] == 'register' and role_permission >= Permission.ADMIN:
            sidebar = init_sidebar(sidebar, now,'register')
            if register_form.validate_on_submit():
                user = User(
                    username=register_form.username.data,
                    password=register_form.password.data,
                    alias=register_form.alias.data,
                    role=register_form.role.data
                )
                add_sql = edit(current_user.username, user, "username")
                add_sql.run('add')
                flash(u'用户添加成功')
            else:
                for thead in start_thead:
                    key = thead[2]
                    if register_form.errors.get(key, None):
                        flash(register_form.errors[key][0])
                        break    
    if request.method == "GET":
        search_value = request.args.get('search', '')
        checkbox = request.args.getlist('hidden') or request.args.get('hiddens', '')
        if search_value:
            # 搜索
            thead = init_checkbox(thead, checkbox)
            sidebar = init_sidebar(sidebar, now,'edituser')
            page = int(request.args.get('page', 1))
            result = search(User, 'username' , search_value)
            result = result.search_return()
            if result:
                pagination = result.paginate(page, 100, False)
                items = pagination.items
                return render_template(
                    'auth/setting.html', sidebar=sidebar, passwd_form=passwd_form, 
                    register_form=register_form, search_value=search_value, 
                    checkbox=str(checkbox), thead=thead, endpoint=endpoint,
                    pagination=pagination, items=items
                )
    return render_template(
        'auth/setting.html',sidebar=sidebar, search_value=search_value,
        passwd_form=passwd_form, register_form=register_form,
        thead=thead
    )