def user_settings(): if 'username' in session.keys(): logged_in = accounts.account_details( session['username'])['displayname'] account = accounts.account_details(session['username']) else: redirect(url_for('login')) if request.method == "GET": return render_template('settings.html', title="Settings", logged_in=logged_in, account=account, theme=accounts.get_theme( session['username'].lower())) elif request.method == "POST": print(request.files) print(request.form) if 'username' not in session.keys(): return redirect(url_for('login')) updated_profile = { 'bio': request.form['bio'], 'gender': request.form['gender'], 'location': request.form['location'] } if 'profile_pic' in request.files.keys(): profile_pic = files.upload_file(request.files['profile_pic']) if request.files['profile_pic'].content_type in [ 'image/jpg', 'image/jpeg', 'image/png' ]: updated_profile['profile_pic'] = profile_pic else: if 'profile_pic' in accounts.account_details( session['username'].lower())['profile'].keys(): profile_pic = accounts.account_details( session['username'].lower())['profile']['profile_pic'] updated_profile['profile_pic'] = profile_pic else: if 'profile_pic' in accounts.account_details( session['username'].lower())['profile'].keys(): profile_pic = accounts.account_details( session['username'].lower())['profile']['profile_pic'] updated_profile['profile_pic'] = profile_pic accounts.set_theme(session['username'].lower(), request.form['theme']) if request.form['gender'] == "Non-Binary": updated_profile['gender'] = request.form['gender-custom'] print(updated_profile) username = session['username'] accounts.update_profile(username, updated_profile) account = accounts.account_details(session['username']) return render_template('settings.html', title="Settings", saved=True, logged_in=logged_in, account=account, theme=accounts.get_theme( session['username'].lower()))
def profile(name=None): logged_in = session['username'] if ('username' in session.keys()) else False if not logged_in and name is None: return redirect(url_for('index')) if logged_in and name is None: name = session['username'] name = name.lower() logged_in = accounts.get_display_name( session['username']) if 'username' in session.keys() else False posts = list(timeline.user_posts_by_username(name)) if 'pinned' in accounts.account_details(name).keys(): pinned = timeline.post_details( accounts.account_details(name)['pinned']) else: pinned = False return render_template('profile.html', title=accounts.get_display_name(name) + "'s profile", user=accounts.account_details(name), logged_in=logged_in, theme=accounts.get_theme(logged_in), following=accounts.is_following(logged_in, name), followers=accounts.get_followers(name), posts=posts, pinned=pinned)
def global_timeline(): if 'username' not in session.keys(): logged_in = False else: logged_in = accounts.get_display_name(session['username']) return render_template('global.html', title="Global Timeline", logged_in=logged_in if logged_in else "anonymous", posts=timeline.global_timeline(), theme=accounts.get_theme(logged_in))
def mentions(): if 'username' not in session.keys(): return redirect(url_for('login')) logged_in = session['username'].lower() return render_template("mentions.html", title="Mentions", logged_in=logged_in, theme=accounts.get_theme( session['username'].lower()), posts=timeline.get_mentions(logged_in))
def messages_blank(): logged_in = session['username'] if ('username' in session.keys()) else False if 'username' not in session: return redirect(url_for('login')) if request.method == "GET": return render_template('messages.html', title="Messages", logged_in=logged_in, theme=accounts.get_theme(logged_in)) elif request.method == "POST": return redirect('/messages/' + request.form['messageuser'])
def timeline_view(): if 'username' in session.keys(): logged_in = accounts.get_display_name(session['username']) else: return redirect(url_for('login')) posts = timeline.timeline_for_user(session['username']) return render_template('timeline.html', title="Timeline", logged_in=logged_in, posts=posts, theme=accounts.get_theme(logged_in))
def findtag(tagname=None): logged_in = session['username'] if ('username' in session.keys()) else False if request.method == 'GET': return render_template('timeline.html', title=str("#" + tagname), logged_in=logged_in, posts=timeline.find_posts_by_hashtag(tagname), theme=accounts.get_theme(logged_in)) elif request.method == 'POST': return redirect('/tag/' + request.form['tagname'])
def messaging(user): logged_in = session['username'] if ('username' in session.keys()) else False if 'username' not in session: return redirect(url_for('login')) if request.method == "GET": return render_template( "messages.html", title="Messages", logged_in=logged_in, messaging=accounts.get_display_name(user.lower()), messages=messages.get_messages(logged_in, user.lower()), theme=accounts.get_theme(logged_in)) elif request.method == "POST": messages.send_message(accounts.get_display_name(logged_in.lower()), accounts.get_display_name(user.lower()), request.form['message_content']) return redirect(request.referrer)
def reply_to_post(post_id): if 'username' not in session.keys(): return redirect(url_for('login')) logged_in = session['username'] if ('username' in session.keys()) else False if request.method == "GET": return render_template('reply.html', title="Reply to " + timeline.post_details(post_id)['poster'], logged_in=logged_in, posts=timeline.get_full_replies(post_id)[:-1], reply_to=timeline.post_details(post_id), theme=accounts.get_theme(logged_in)) elif request.method == "POST": timeline.post_status(logged_in, request.form['status'], replyTo=post_id) return redirect(url_for('profile'))