def profile_form_submit(user_id): form = ProfileForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): profile = Profile.query.filter_by(user_id=user_id).first() if profile: profile.about = form.data['about'], profile.first_name = form.data['first_name'], profile.last_name = form.data['last_name'], profile.phone_number = form.data['phone_number'], profile.location = form.data['location'], profile.work = form.data['work'], profile.language = form.data['language'], else: profile = Profile(about=form.data['about'], first_name=form.data['first_name'], last_name=form.data['last_name'], phone_number=form.data['phone_number'], location=form.data['location'], work=form.data['work'], language=form.data['language'], user_id=user_id) db.session.add(profile) db.session.commit() return profile.to_dict()
def profile_form_submit(user_id): form = ProfileForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): profile = Profile.query.filter(Profile.user_id == user_id).first() if profile: profile.about_me = form.data['about_me'] profile.location = form.data['location'] profile.nin_gt = form.data['nin_gt'] profile.ps_gt = form.data['ps_gt'] profile.xbox_gt = form.data['xbox_gt'] profile.steam_gt = form.data['steam_gt'] profile.discord_gt = form.data['discord_gt'] else: profile = Profile( user_id=user_id, about_me=form.data['about_me'], location=form.data['location'], nin_gt=form.data['nin_gt'], ps_gt=form.data['ps_gt'], xbox_gt=form.data['xbox_gt'], steam_gt=form.data['steam_gt'], discord_gt=form.data['discord_gt'], ) db.session.add(profile) db.session.commit() return profile.to_dict()
def create_profile(): form = ProfileForm() form['csrf_token'].data = request.cookies['csrf_token'] if current_user.is_authenticated and form.validate_on_submit() and ( current_user.id == form.data['userId']): profile = Profile(name=form.data['name'], iconId=form.data['iconId'], userId=form.data['userId']) db.session.add(profile) db.session.commit() return profile.to_dict() return {'errors': validation_errors_to_error_messages(form.errors)}, 401
def profile_form_submit(user_id): print('hey its the user_id', user_id) form = ProfileForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): profile = Profile.query.filter_by(user_id=user_id).first() if profile: profile.bio=form.data['bio'], profile.name=form.data['name'], profile.location=form.data['location'], profile.website = form.data['website'] else: profile = Profile( bio=form.data['bio'], name=form.data['name'], location=form.data['location'], website=form.data['website'], user_id=user_id ) db.session.add(profile) db.session.commit() return profile.to_dict()
def profile_update(id): profile = request.get_json() profiles = Profile.query.filter(Profile.userId == id).first() city = Location.query.filter(Location.city.ilike(profile["city"]))\ .filter(State.id == profile["state"]).first() location = None l_list = Languages.query.all() lang_match = [ la for la in l_list for lang in profile["languages"] if la.to_dict()["id"] == lang ] e_list = Expertise.query.all() exp_match = [ ex for ex in e_list for exp in profile["expertises"] if ex.to_dict()["id"] == exp ] if city is not None: location = city.to_dict()["id"] else: location = profile["city"] new_location = Location(city=location, stateId=profile["state"]) db.session.add(new_location) db.session.commit() city = Location.query.filter(Location.city.ilike(profile["city"]))\ .filter(State.id == profile["state"]).first() location = city.to_dict()["id"] if profiles is not None: profiles.userId = profile["user_id"] profiles.firstName = profile["first_name"] profiles.lastName = profile["last_name"] profiles.imageUrl = profile["image_url"] profiles.bio = profile["bio"] profiles.locationId = location profiles.level = profile["level"] profiles.inPerson = profile["in_person"] profiles.personality = profile["personality"] profiles.frequencyId = profile["frequency_id"] profiles.mentorship = profile["mentorship"] profiles.morning = profile["morning"] profiles.languages = lang_match profiles.expertises = exp_match db.session.commit() return profiles.to_dict() else: new_profile = Profile( userId=profile["user_id"], firstName=profile["first_name"], lastName=profile["last_name"], imageUrl=profile["image_url"], bio=profile["bio"], locationId=location, level=profile["level"], inPerson=profile["in_person"], personality=profile["personality"], frequencyId=profile["frequency_id"], mentorship=profile["mentorship"], morning=profile["morning"], ) db.session.add(new_profile) new_profile.languages = lang_match new_profile.expertises = exp_match db.session.commit() return new_profile.to_dict()