Esempio n. 1
0
def userskill():
    users = get_data(Person)
    skills = get_data(Skill)
    req = req2(Person, UserSkill, Skill)
    userskills = [UserSkillDTO(i[0], i[1], i[3]) for i in req]
    form = UserSkillForm(request.form)
    form.skill_id.choices = [(skill.id, skill.name) for skill in skills]
    form.user_id.choices = [(user.id, user.first_name) for user in users]
    if request.method == 'POST':
        print(form.id.data)

        if form.id.data == '':
            userskill = UserSkill(int(random.getrandbits(31)),
                                  form.user_id.data, form.skill_id.data)
            insert_data(userskill)
        else:
            userskill = UserSkill(int(form.id.data), form.user_id.data,
                                  form.skill_id.data)
            update_data(userskill, UserSkill)
        save()
        return redirect('/usercode')

    return render_template('user_has_code.html',
                           userskills=userskills,
                           form=form)
Esempio n. 2
0
def userskill_edit(id):
    if request.method == 'GET':
        userskill = get_data_by_id(UserSkill, id)

        users = get_data(Person)
        skills = get_data(Skill)
        req = req2(Person, UserSkill, Skill)
        userskills = [UserSkillDTO(i[0], i[1], i[3]) for i in req]

        form = UserSkillForm(request.form)
        form.skill_id.choices = [(skill.id, skill.name) for skill in skills]
        form.user_id.choices = [(user.id, user.first_name) for user in users]
        form.id.data = userskill.id
        form.skill_id.data = userskill.skill_id
        form.user_id.data = userskill.user_id
        return render_template('user_has_code.html',
                               userskills=userskills,
                               form=form)