def profile(profileid): page_context = {} page_context['google_url'] = google_login.authorization_url() user = flask_login.current_user if user.is_anonymous(): user = User() else: page_context['username'] = user.username if len(user.username.strip()) == 0: return redirect(url_for('signup')) if request.method == 'POST' and UPLOADS_FOLDER is not '': return process_upload(request) posts, page_context['postcount'] = sql_controller.get_posts_by_uid(profileid) comments, page_context['commentcount'] = sql_controller.get_comments_by_uid(profileid) page_context['commented_on'] = sql_controller.get_posts_commented_by_uid(profileid) pobj = sql_controller.get_user_by_uid(profileid) if pobj is None: page_context['error'] = 'This user does not exist.' return render_template('noimage.html', page_context = page_context) pemail = pobj.email.lower() page_context['uid'] = user.uid page_context['posts'] = posts page_context['comments'] = comments page_context['nickname'] = sql_controller.get_user_by_uid(profileid)['nickname'] page_context['profileid'] = profileid page_context['avatar'] = hashlib.md5(pemail.encode('utf-8')).hexdigest() page_context['id_to_path'] = id_to_path response = render_template('profile.html', page_context = page_context).format(google_login.authorization_url()) return response
def user_loader(uid): data = sql_controller.get_user_by_uid(uid) if data: user = User() user.email = data['email'] user.username = data['nickname'] user.uid = data['uid'] return user return None
def image(image_id): page_context = {} user = flask_login.current_user if user.is_anonymous(): user = User() else: page_context['username'] = user.username if len(user.username.strip()) == 0: return redirect(url_for('signup')) if request.method == 'POST' and UPLOADS_FOLDER is not '': source = request.form['source'] if source == 'post': return process_upload(request) elif source == 'comment': process_comment(request, image_id) return redirect(url_for('image', image_id = image_id)) elif source == 'commentedit': edit_comment(request) return redirect(url_for('image', image_id = image_id)) elif source == 'deletecomment': sql_controller.delete_comment(request.form['cid']) return redirect(url_for('image', image_id = image_id)) elif source == 'deletepost': sql_controller.delete_post(image_id) return redirect(url_for('index')) post = sql_controller.select_post(image_id) page_context['uid'] = user.uid page_context['google_url'] = google_login.authorization_url() if post is None: page_context['error'] = 'This image does not exist.' return render_template('noimage.html', page_context = page_context) comments = sql_controller.select_comments_for_post(image_id) tags = post['tags'].split(",") page_context['nickname'] = sql_controller.get_user_by_uid(post['uid'])['nickname'] max_comment_length = 100 page_context['auto_comment'] = markov_chain.generate_comment(max_comment_length) response = render_template('index.html', post=post, tags=tags, comments=comments, image='{}/{}.gif'.format(RELATIVE_FOLDER, image_id), page_context = page_context) return response
def get_author(uid): return sql_controller.get_user_by_uid(uid)