Ejemplo n.º 1
0
def add_labeller():
    '''Agregar usuario'''
    form = NewUser()
    tasks = Task.query.all()
    roles = Role.query.all()
    form.taskid.choices=[(task.id,task.name) for task in tasks]
    form.roleids.choices=[(role.id,role.name) for role in roles]
    if form.cancel.data:
        return redirect(url_for('.index'))
    elif form.validate_on_submit():
        nuser = User(
            username=form.username.data, active=True,
            name=form.name.data,
            taskid=form.taskid.data,
            password=user_manager.hash_password(form.password.data))
        for role_id in form.roleids.data:
            role = Role.query.filter(Role.id==role_id).first()
            if role:
                nuser.roles.append(role)
        db.session.add(nuser)
        db.session.commit()
        return redirect(url_for('.index'))
    return render_template("newlabeller.html", form=form)
Ejemplo n.º 2
0
    except NoResultFound, e:
        return render_template('error.html',message="Usuario no encontrado")
    form=EditLabeller()
    tasks = Task.query.all()
    roles = Role.query.all()
    form.taskid.choices=[(task.id,task.name) for task in tasks]
    form.roleids.choices=[(role.id,role.name) for role in roles]
 
    if form.cancel.data:
        return redirect(url_for('.index'))
    if form.validate_on_submit():
        l.username=form.username.data
        l.name=form.name.data
        l.taskid=int(form.taskid.data)
        if len(form.password.data)>0:
            l.password=user_manager.hash_password(form.password.data)
        l.roles[:]=[]
        for role_id in form.roleids.data:
            role = Role.query.filter(Role.id==role_id).first()
            if role:
                l.roles.append(role)
        db.session.add(l)
        db.session.commit()
        return redirect(url_for('.index'))
    form.taskid.data=l.taskid
    form.username.data=l.username
    form.name.data=l.name
    form.roleids.data=[role.id for role in l.roles]
    return render_template("editlabeller.html", form=form,username=username)

@dashboard.route("/list/labellers")