def settings(): users.require_role(2) user_id = session["user_id"] events_with_own_level = events.get_all_events_for_user(user_id) own_weekly_entries = entries.get_weekly_entries_for_user(user_id) friends_list = friends.get_friends(user_id) friend_requests = friends.get_friends_open_requests(user_id) friend_requests_own = friends.get_own_requests(user_id) weekdays = {0: "SU", 1: "MA", 2: "TI", 3: "KE", 4: "TO", 5: "PE", 6: "LA"} user_info = users.get_user_info(user_id) if session["user_role"] == 1 or session["user_role"] == 0: all_events = events.get_all_events() return render_template("settings.html", all_events=all_events, friend_requests_own=friend_requests_own, user_info=user_info, days=weekdays, events_with_own_level=events_with_own_level, own_weekly_entries=own_weekly_entries, friends=friends_list, friend_requests=friend_requests) return render_template("settings.html", friend_requests_own=friend_requests_own, user_info=user_info, days=weekdays, events_with_own_level=events_with_own_level, own_weekly_entries=own_weekly_entries, friends=friends_list, friend_requests=friend_requests)
def show_single_user(name): try: user_info = users.get_user_info(name=name) except errors.UserNotFoundError: return errors.not_found_response("No user associated with that name.") response_data = { "status": "ok", "user": user_info } return jsonify(response_data)
def info(): if users.user_role() == 0: return render_template("error.html", message="Ei oikeutta nähdä sivua.") user = users.user_id() info = users.get_user_info(user, db) card = cards.get_cards(user, db) bought = cards.bought_cards(user, db) return render_template("info.html", info=info, cards=card, bought=bought)
def show_update_user_response(name): try: clean_info = parse_info_as_json(request.data) old_user_info = users.get_user_info(name) updated_user_info = users.update_user_from_info( name=name, info=clean_info) except errors.UserNotFoundError: return errors.not_found_response("No user associated with that name.") except errors.JSONNotFoundError: return errors.bad_request_response("Updated user details are required in a proper JSON request body.") except errors.UserInfoError as user_info_error: return errors.bad_request_response(message=str(user_info_error)) except errors.UserConflictError as user_conflict_error: return errors.conflict_response(message=str(user_conflict_error)) response_data = { "status": "ok", "user": updated_user_info, "old_info": old_user_info } return jsonify(response_data)
def login(): if request.method == 'GET': return render_template('landing.html', messageStatus="", loginStatus="") elif request.method == 'POST': username = request.form.get('username') password = request.form.get('password') if users.password_and_username_ok(username, password): user_id = users.get_user_id(username) user = User(user_id) login_user(user) user_data = users.get_user_info(user_id) reservations = reservation.get_reservations_for_user(user_id) return render_template('main.html', userData=user_data, listOfReservations=reservations) else: return render_template('landing.html', messageStatus="", loginStatus="login failed")
dir_path = f"data/{user_slug}/" if not os.path.exists(dir_path): os.makedirs(dir_path) if not os.path.exists(f"{dir_path}/uploads"): os.makedirs(f"{dir_path}/uploads") # scrape images from gallery uploads = get_user_uploads(user) for upload in uploads: f = open(f'{dir_path}/uploads/avatar.jpg', 'wb') f.write(requests.get(f'{upload}').content) f.close() # scrape user information & recommended ascents recommended = get_recommended_ascents(user, driver) user_info = get_user_info(user) user_info['recommended_ascents'] = recommended with open(f"{dir_path}/user.json", "w") as outfile: json.dump(user_info, outfile) # scrape bouldering ascents for category in categories: # 'bouldering' | 'sportclimbing' ascents = get_user_ascents(user, category, driver) with open(f"{dir_path}/{category}.json", "w") as outfile: json.dump(ascents, outfile) driver.quit() # # ascents # name = "Tommy's Arete" # category = 'bouldering'