def index(): form = SkillForm(request.form) form.update_category_choices() # adding a new skill if request.method == 'POST' and 'skill' in request.form.keys( ) and 'new_category' not in request.form.keys(): if form.validate() and form.no_special_characters(): if Skill.insert_new_skill( form.skill.data, dict(form.category.choices).get(form.category.data)): return redirect(url_for('main.index')) else: form.add_error(ErrorMessages.SKILL_NOT_UNIQUE) # going to category form elif request.method == 'POST' and 'skill' in request.form.keys( ) and 'new_category' in request.form.keys(): return redirect(url_for('content.category')) return render_template('content/index.html', result_set=Skill.get_all_visible_skills(), form=form, admin_email=Config.ADMIN_EMAIL)
def create_skill(): response = User.check_token(request) if response == 200 \ and User.query.filter_by(token=request.headers.get('Authorization')).first().email == Config.ADMIN_EMAIL: data = request.get_json() or {} if not validate_skill_json(data): return bad_request(ErrorMessages.API_FORMAT_NOT_ALLOWED) if not validate_new_skill_name(data['skill_name']): return bad_request(ErrorMessages.API_SKILL_NAME_ERROR) if not validate_new_category_name(data['category_name']): return bad_request(ErrorMessages.API_CATEGORY_NAME_ERROR) if Skill.insert_new_skill(data['skill_name'], data['category_name'], data.get('is_shown', 1)): response = jsonify( Skill.query.filter_by( skill_name=data['skill_name']).first().to_dict('name')) response.status_code = 201 response.headers['Location'] = url_for( 'api.get_skill_by_name', skill_name=data['skill_name']) return response else: return bad_request(ErrorMessages.API_SKILL_INSERT_ERROR) return error_response(response if response != 200 else 401)