Пример #1
0
def add_skill(engineer):
    engineer = User.query.filter_by(engineer=engineer).first_or_404()

    form = SkillForm()

    if form.validate_on_submit():
        skill = Skills(skill_name=form.skill_name.data,
                       skill_strength=form.skill_strength.data,
                       engineer=engineer,
                       skill_engineer=engineer.engineer)

        print "skill is:" + repr(skill)

        db.session.add(skill)
        db.session.commit()
        skill_list = engineer.skills.all()
        return render_template('skills.html',
                               title='Engineer Skills',
                               engineer=engineer.engineer,
                               skills=skill_list)

    return render_template('add_skill.html',
                           title='Add a Skill',
                           engineer=engineer.engineer,
                           form=form)
Пример #2
0
def add_skill():
    """Route to add skill to database and redirect to index page"""
    skills = mongo.db.Skills
    form = SkillForm()

    if request.method == 'POST' and form.validate_on_submit():
        skills.insert(
            {
                'skill_name': request.form.get('skill_name'),
                'percent': int(request.form.get('percent')),
                'skill_icon': request.form.get('skill_icon')
            })
        return redirect(url_for('index'))
    return render_template('pages/add/skill.html', form=form)
Пример #3
0
def edit_skill(skill_id):
    """Route to edit skill in database and redirect to index page"""
    skills = mongo.db.Skills
    the_skill = mongo.db.Skills.find_one({'_id': ObjectId(skill_id)})
    form = SkillForm()
    form.skill_name.data = the_skill['skill_name']
    form.percent.data = the_skill['percent']
    form.skill_icon.data = the_skill['skill_icon']

    if request.method == 'POST' and form.validate_on_submit():
        skills.update({'_id': ObjectId(skill_id)},
                      {
            'skill_name': request.form.get('skill_name'),
            'percent': int(request.form.get('percent')),
            'skill_icon': request.form.get('skill_icon')
        })
        return redirect(url_for('index'))
    return render_template('pages/edit/skill.html', skill=the_skill, form=form)
Пример #4
0
def addskill():
    form = SkillForm()
    if form.validate_on_submit():
        if request.method == 'POST':
            result = request.form
            cursor = connection1.cursor()
            values = list(result.values())
            cursor.execute("select * from skill_list")
            l = cursor.fetchall()
            lit = [i[0] for i in l]

            if values[1] in lit:
                flash("Already skill exists", 'danger')
                return redirect(url_for('addskill'))
            else:
                cursor.execute("insert into skill_list(skill) values('" +
                               values[1] + "')")
                connection1.commit()
                flash('Skill added successfully', 'success')
    return render_template('addskill.html', form=form)
Пример #5
0
def addSkill():
# define an error variable to be passed through if any errors that need to be prompted to the user occur
    error = None
    skill_form = SkillForm()
    # checks for a post request from the form submit button
    if request.method == 'POST':
        # if the validation from the wtform class passes continue
        if skill_form.validate_on_submit():
            skills = []
            for skill in current_user.get_skills():
                skills.append(skill.skillType)
            if skill_form.skill.data not in skills:
                new_skill = Skill(skill_form.skill.data, current_user.id)
                # add and commit to the database
                db.session.add(new_skill)
                db.session.commit()
                return redirect(url_for('dashboard.userDashboard'))
            else:
                error = "You have all ready added that skill."
        else:
            error = "Invalid Skill Selected."
    return render_template('accounts/add_skill.html', skill_form=skill_form, error=error)