def user(username): user = User.query.filter_by(username=username).first_or_404() comments = [{ 'author': user, 'comment_text': 'Test post #1' }, { 'author': user, 'comment_text': 'Test post #2' }] decks = user.decks deck_counter = 0 # правильно ли делать это тут? for deck in decks: deck_counter += 1 # пробуем вытащить скиллы пользователя try: skills = current_user.skills[0] except IndexError: # если скиллов нету, то пишем об этом sk = Skill() skills = { 'first_skill': sk.default_skills(), 'second_skill': '', 'third_skill': '', 'fourth_skill': '', 'fifth_skill': '' } return render_template('user.html', title=user.username, user=user, comments=comments, deck_counter=str(deck_counter), decks=decks, skills=skills)
def vacancy_request(id_list, profession): print("Собираю атрибуты вакансий") currences = get_currencies() p = Profession.query.filter_by(name=profession).first() if p is None: p = Profession(name=profession) db.session.add(p) for vacancy_id in id_list: response = requests.get("https://api.hh.ru/vacancies/" + vacancy_id) vacancy = response.json() if not vacancy["key_skills"]: continue for skills in vacancy["key_skills"]: if Skill.query.filter_by(name=skills["name"]).first(): continue s = Skill(name=skills["name"]) db.session.add(s) db.session.commit() v = Vacancy(vacancy_id=vacancy["id"], name=vacancy["name"], expirience=vacancy["experience"]["name"], area=vacancy["area"]["name"], salary=set_salary(vacancy, currences), profession_id=p.id) if vacancy["key_skills"] is not None: for skills in vacancy["key_skills"]: s = Skill.query.filter_by(name=skills["name"]).first() v.skills.append(s) db.session.add(v) db.session.commit()
def pump_skills_table(): print('skills') skills = [ 'Plumber', 'Carpenter', 'Mechanic', 'Interior Decorator', 'Caterer'] for skill in skills: try: Skill(name=skill).save() except: pass
def add_random_user(id): user = User(id=id, nickname=generate(), description="Team Devian", steam=generate(), discord=generate(), twitch=generate()) s1 = Skill(title="Координатор", count=3, user=user) s2 = Skill(title="Лидер", count=2, user=user) g1 = Game(game_id=randint(0, 9), user=user) a1 = Award(title="Ez Game", imgSrc="https://www.ezride.be/wp-content/uploads/2017/11/cropped-Logo_EZRide_yellow_circle.png", user=user) db.session.add(user) db.session.add(s1) db.session.add(s2) db.session.add(g1) db.session.add(a1) db.session.commit() return user
def seed_skills(): skill_list = [ 'Lyra', 'Fabric', 'Dance trapeze', 'Static trapeze', 'Flying trapeze', 'Corde lisse', 'Pole', 'Chinese pole', 'Hammock', 'Invented apparatus' ] for num in range(100): skill = Skill(user_id=num + 1, skill_name=skill_list[faker.pyint( min_value=0, max_value=len(skill_list) - 1)]) db.session.add(skill) db.session.commit()
def _save_to_db(name, email, skills): if name is not None: try: Person(name=name, email=email).save() except: pass for skill in skills: try: Skill(name=skill).save() except Exception as e: print(e) pass
def create_skill(current_user): data = request.get_json() if not 'name' in data or not 'resume id' in data or not 'level' in data: return { 'error': 'Invalid data', 'message': 'Name, level and resume id must be given' }, 400 try: print(id) r = Resume.query.get_or_404(int(data['resume id'])) except Exception as e: return { 'error': 'Your request can not be processed', 'message': str(e) }, 500 s = Skill(name=data['name'], level=data['level'], resume_id=data['resume id']) db.session.add(s) r.skills.append(s) db.session.commit() return s.to_dict(), 201
def test_skill_model(self): skill = Skill({ 'name': "name", 'icon': "fakeicon.png", 'description': "fake desc", 'members_only': False, 'max_level': 99, 'skill_type': 'test' }) db.session.add(skill) db.session.commit() skills = Skill.query.all() assert skill in skills assert str(skill) == "<Skill 'name'>" assert skill.toJSON(False) == { 'id': 1, 'name': 'name', 'icon': 'fakeicon.png', 'description': 'fake desc', 'members_only': False, 'max_level': 99 } assert len(skills) == 1
def add_skill(): content = request.json if not content or 'name' not in content: abort(400) if not Skill.query.filter_by(name=content['name']).first(): skill = Skill(**content) try: db.session.add(skill) db.session.commit() return "Skill added" except: abort(400) else: abort(400, "Skill already exists")
def search(): page = request.args.get('page', 1, type=int) query = request.args.get('q') items_query, total = Item.search(query, page, current_app.config['POSTS_PER_PAGE']) items = [item for item in items_query] videos_query, total = Video.search(query, page, current_app.config['POSTS_PER_PAGE']) videos = [video for video in videos_query] skills_query, total = Skill.search(query, page, current_app.config['POSTS_PER_PAGE']) skills = [skill for skill in skills_query] reddits_query, total = Reddit.search(query, page, current_app.config['POSTS_PER_PAGE']) reddits = [reddit for reddit in reddits_query] all_items = items + videos + skills + reddits result = { 'result': [i.toJSON() for i in all_items], 'has_more': total > page * current_app.config['POSTS_PER_PAGE'], } return jsonify(result)
def skills_updater(user_id, five_skills_lst=['', '', '', '', '']): """Вспомогательная функция для обновления скиллов""" skills = Skill.query.filter_by(user_id=current_user.id).first() # если нашли, то перезаполняем if skills: skills.first_skill = five_skills_lst[0] skills.second_skill = five_skills_lst[1] skills.third_skill = five_skills_lst[2] skills.fourth_skill = five_skills_lst[3] skills.fifth_skill = five_skills_lst[4] # если не нашли, то создаём else: skills = Skill(first_skill=five_skills_lst[0], second_skill=five_skills_lst[1], third_skill=five_skills_lst[2], fourth_skill=five_skills_lst[3], fifth_skill=five_skills_lst[4], user_id=current_user.id) db.session.add(skills)
def skills(): if current_user.is_authenticated: form = AddSkillForm() skills = Skill.query.all() if form.validate_on_submit(): try: skill = Skill( title = form.title.data, year_started = form.year_started.data, category = form.category.data ) db.session.add(skill) db.session.commit() return redirect(url_for('skills')) except: print("Didn't post skill") return redirect(url_for('skills')) return render_template('skills.html', skills=skills, form=form, title="Skills") else: return redirect(url_for('backLogin'))
def update_profile(): form = UpdateAccountForm() # generates list of all interests and skills of the user present_interest = Interest.query.filter( Interest.users.any(username=current_user.username)).all() present_skill = Skill.query.filter( Skill.users.any(username=current_user.username)).all() if form.validate_on_submit(): if form.resume.data: # If user uploads their resume pic_file = save_pic(form.resume.data, 'static/resume') current_user.resume = pic_file if form.profile_picture.data: # If user uploads their profile picture pic_file_ = save_pic(form.profile_picture.data, 'static/profileimages') current_user.profile_picture = pic_file_ current_user.username = form.username.data current_user.email = form.email.data current_user.fname = form.fname.data current_user.lname = form.lname.data current_user.phone_number = form.phone.data current_user.is_super_admin = form.is_admin.data current_user.is_actively_interviewing = form.is_actively_interviewing.data current_user.is_recruiter = form.is_recruiter.data current_user.facebook_link = form.facebook_link.data current_user.twitter_link = form.twitter_link.data current_user.linkedin_link = form.linkedin_link.data current_user.salary_expt = form.salary.data current_user.address = form.address.data skill = form.skills.data skills = { 1: 'C++', 2: 'Python', 3: 'JavaScript', 4: 'Java', 5: 'React', 6: 'Golang', 7: 'Rust' } interest = form.interests.data interests = { 1: 'Product Design', 2: 'UI/UX', 3: 'Software Development', 4: 'Artificial Intelligence', 5: 'Data Science', 6: 'Game Development', 7: 'Cyber Security' } if skill: for skl in present_skill: db.session.delete(skl) for choice in skill: current_user.skills.append(Skill(name=skills[choice])) if interest: for skl in present_interest: db.session.delete(skl) for choice in interest: current_user.interests.append(Interest(name=interests[choice])) db.session.commit() flash('Your account has been updated', 'success') return redirect(url_for('profile')) form.username.data = current_user.username form.email.data = current_user.email form.fname.data = current_user.fname form.lname.data = current_user.lname form.phone.data = current_user.phone_number if form.phone.data == None: form.phone.data = '+2340000000000' form.address.data = current_user.address form.is_admin.data = current_user.is_super_admin form.is_actively_interviewing.data = current_user.is_actively_interviewing form.is_recruiter.data = current_user.is_recruiter form.facebook_link.data = current_user.facebook_link form.twitter_link.data = current_user.twitter_link form.interests.data = present_interest form.skills.data = present_skill form.linkedin_link.data = current_user.linkedin_link form.salary.data = current_user.salary_expt return render_template('updateprofile.html', title='Update Account', form=form)
def edit_profile(): if request.method == 'POST': name = request.form.get("name") bio = request.form.get("bio") location = request.form.get("location") month = request.form.get("month") day = request.form.get("day") year = request.form.get("year") gender = request.form.get("gender") skills = eval(request.form.get("skills")) file = request.files.get("image") if not name: print("All fields required") return json.dumps({'status': 'Name must be filled in', 'box_id': 'name'}) if not location: print("All fields required") return json.dumps({'status': 'Location must be filled in', 'box_id': 'location'}) if not month or not day or not year: print("All fields required") return json.dumps({'status': 'Birthday must be filled in', 'box_id': 'birthdate'}) birthdate = date(month=int(month), day=int(day), year=int(year)) if not get_age(birthdate) >= 13: return json.dumps({'status': 'You must be over the age of 13', 'box_id': 'birthdate'}) location = geocode(location) if not location: print("Non-valid location") return json.dumps({'status': 'Non-valid location', 'box_id': 'location'}) if file: image = Image.open(file) new_image = image.resize((256, 256), Image.ANTIALIAS) new_image.format = image.format current_user.profile_pic.save(image=new_image) current_user.name = name.strip() current_user.bio = bio.strip() current_user.set_location(location=location, prelocated=True) current_user.set_birthdate(birthdate) current_user.gender = gender # Add skills that are not already there for skill in skills: if not current_user.skills.filter_by(title=skill).first(): skill = Skill(owner=current_user, title=skill) db.session.add(skill) # Delete skills that are meant to be deleted for skill in current_user.skills: if not skill.title in skills: db.session.delete(skill) db.session.commit() return json.dumps({'status': 'Successfully saved'}) return render_template('profile.html', edit_profile=True, profile=current_user, available_skills=available_skills, selected_month=current_user.birthdate.month, selected_day=current_user.birthdate.day, selected_year=current_user.birthdate.year)
def db_import(): """Initialize the database.""" click.echo('Database initialization') MOCK_DB = None with open('fixtures/mock.json', 'r') as mock: MOCK_DB = json.load(mock) click.echo('Resetting db...') db.reflect() db.drop_all() db.create_all() click.echo('Adding items...') local_items = [] for item in MOCK_DB['items']: item_row = Item(item) db.session.add(item_row) local_items += [item_row] local_skills = [] for skill in MOCK_DB['skills']: skill_row = Skill(skill) db.session.add(skill_row) local_skills += [skill_row] local_videos = [] for video in MOCK_DB['videos']: video_row = Video(video) db.session.add(video_row) local_videos += [video_row] local_reddits = [] for reddit in MOCK_DB['reddits']: reddit_row = Reddit(reddit) db.session.add(reddit_row) local_reddits += [reddit_row] for json_item in MOCK_DB['items']: db_item = local_items[json_item['id'] - 1] for skill_id in json_item['skills']: db_item.skills.append(local_skills[skill_id - 1]) for reddit_id in json_item['reddits']: db_item.reddits.append(local_reddits[reddit_id - 1]) for video_id in json_item['videos']: db_item.videos.append(local_videos[video_id - 1]) db.session.add(db_item) for json_skill in MOCK_DB['skills']: db_skill = local_skills[json_skill['id'] - 1] for item_id in json_skill['items']: db_skill.items.append(local_items[item_id - 1]) for reddit_id in json_skill['reddits']: db_skill.reddits.append(local_reddits[reddit_id - 1]) for video_id in json_skill['videos']: db_skill.videos.append(local_videos[video_id - 1]) db.session.add(db_skill) for json_video in MOCK_DB['videos']: db_video = local_videos[json_video['id'] - 1] for item_id in json_video['items']: db_video.items.append(local_items[item_id - 1]) for skill_id in json_video['skills']: db_video.skills.append(local_skills[skill_id - 1]) db.session.add(db_video) for json_reddit in MOCK_DB['reddits']: db_reddit = local_reddits[json_reddit['id'] - 1] for item_id in json_reddit['items']: db_reddit.items.append(local_items[item_id - 1]) for skill_id in json_reddit['skills']: db_reddit.skills.append(local_skills[skill_id - 1]) db.session.add(db_reddit) click.echo('Reindexing for elasticsearch...') db.session.commit() Item.reindex() Skill.reindex() Reddit.reindex() Video.reindex() click.echo('Done.')