from flask import Blueprint, request, render_template, \
	flash, g, session, redirect, url_for, jsonify
from app import db, requires_auth
from flask_cors import CORS
from .models import Paste
import uuid
from datetime import datetime
from app.user.models import User
from pygments import highlight
from pygments.lexers import get_lexer_by_name, guess_lexer
from pygments.formatters import HtmlFormatter
from functools import wraps
from datetime import datetime
from dateutil import parser


def requires_admin(f):
	@wraps(f)
	def decorated(*args, **kwargs):
		if 'user_id' not in session:
			return jsonify(message="Unauthorized", success=False), 401
		user_id = session['user_id']
		user = User.query.filter(User.id == user_id).first()
		if(user.user_type != 2):
			return jsonify(message="Unauthorized", success=False), 401
		return f(*args, **kwargs)
	return decorated

mod_paste = Blueprint('paste', __name__)
CORS(mod_paste)


def is_active(paste):
	return parser.parse(paste.expire_time) > datetime.now()


@mod_paste.route('/create_paste', methods=['GET'])
@requires_auth
def create_form():
	curr_id = session['user_id']
	user = User.query.filter(User.id == curr_id).first()
	return render_template('user.html', username=user.username)


@mod_paste.route('/create_paste', methods=['POST'])
def create_paste():
	title = request.form['title']
	text = request.form['text']
	paste_type = request.form['type']
	if 'user_id' in session:
		user_id = session['user_id']
	else:
		user = User.query.filter(User.username == 'Guest').first()
		user_id = user.id
	lang = request.form['lang']
	time_form = request.form['time']
	expire_time = str(time_form)
	add_time = str(datetime.now())
	url = str(uuid.uuid4())
	report_count = 0
	try:
		paste = Paste(title, text, lang, add_time,
					  expire_time, user_id, url, report_count, paste_type)
		user = User.query.filter(User.id == user_id).first()
		x = user.paste_count
		user.paste_count = x + 1
		db.session.add(paste)
		db.session.commit()
		# jsonify(success=True, paste=paste.to_dict())
		return jsonify({'url': url}), 200
	except:
		return jsonify({'error': 'Error while creating Paste, Please check if all fields are filled'}), 400


@mod_paste.route('/paste', methods=['GET'])
@requires_auth
def get_all_pastes():
	# user_id = session['user_id']
	# pastes = paste.query.filter(paste.user_id == user_id).all()
	if 'user_id' in session:
		curr_id = session['user_id']
		user = User.query.filter(curr_id == User.id).first()
		if user.user_type == 2:
			return render_template('admin_mypaste.html')
		return render_template("mypaste.html")
	else:
		return jsonify({'error': 'Please Login to Continue'}), 400
	# return jsonify(success=True, pastes=[paste.to_dict() for paste in
	# pastes])


@mod_paste.route('/api/paste', methods=['POST'])
@requires_auth
def get_all_pastes_object():
	user_id = session['user_id']
	user = User.query.filter(user_id == User.id).first()
	pastes = Paste.query.filter(Paste.user_id == user_id).all()

	active = []
	for paste in pastes:
		if is_active(paste):
			active.append(paste.to_dict())
		else:
			userid_to_red = paste.user_id
			user_to_red = User.query.filter(userid_to_red == User.id)
			user_to_red.paste_count = user_to_red.paste_count - 1
			db.session.delete(paste)
			db.session.commit()

	return jsonify({'paste_list': active, 'username': user.username}), 200


@mod_paste.route('/<url>/embed', methods=['GET'])
def embed_code_form(url):
	paste = Paste.query.filter(Paste.url == url).first()
	if is_active(paste):
		return render_template('embed.html', paste_text=paste.text, paste_link="http://127.0.0.1:8080/" + url)
	else:
		userid_to_red = paste.user_id
		user_to_red = User.query.filter(User.id == userid_to_red).first()
		user_to_red.paste_count = user_to_red.paste_count - 1
		db.session.delete(paste)
		db.session.commit()
		return render_template("index.html"), 404


# @mod_paste.route('/<url>/embed', methods=['POST'])
# def embed_code(url):
# 	paste = Paste.query.filter(Paste.url == url).first()
# 	return jsonify(paste_text = paste.text,paste_link = url)

@mod_paste.route('/<url>/embed/output', methods=['GET'])
def embed_code_disp(url):
	paste = Paste.query.filter(Paste.url == url).first()
	if is_active(paste):
		return render_template('embed_output.html')
	else:
		userid_to_red = paste.user_id
		user_to_red = User.query.filter(User.id == userid_to_red).first()
		user_to_red.paste_count = user_to_red.paste_count - 1
		db.session.delete(paste)
		db.session.commit()
		return render_template("index.html"), 404

# @mod_paste.route('/paste', methods=['GET'])
# @requires_auth
# def get_all_pastes():
#     # user_id = session['user_id']
#     # pastes = paste.query.filter(paste.user_id == user_id).all()
#     curr_id = session['user_id']
#     user = User.query.filter(User.id == curr_id).first()
#     paste_list = Paste.query.filter(curr_id == Paste.user_id).all()
#     url_pre = "/"
#     for paste in paste_list:
#         paste.url = url_pre + paste.url
#     if user.user_type == 1:
#         return render_template('mypaste.html', paste_list=paste_list)
#     return render_template('admin_mypaste.html',paste_list = paste_list)
#     # return jsonify(success=True, pastes=[paste.to_dict() for paste in
#     # pastes])
#
#
# @mod_paste.route('/api/paste', methods=['POST'])
# @requires_auth
# def get_all_pastes_object():
#     user_id = session['user_id']
#     user = User.query.filter(user_id == User.id).first()
#     pastes = Paste.query.filter(Paste.user_id == user_id).all()
#     active = []
#     for paste in pastes:
#         temp_paste = {}
#         if paste.is_active():
#             temp_paste['title'] = paste.title
#             temp_paste['add_time']=paste.add_time
#             temp_paste['expire_time']=paste.expire_time
#             temp_paste['lang']=paste.lang
#             temp_paste['url']=paste.url
#             active.append(temp_paste)
#
#     return jsonify({'paste_list':active,'username':user.username}),200


# @mod_paste.route('/paste/<id>', methods=['GET'])
# @requires_auth
# def get_paste(id):
#     user_id = session['user_id']
#     paste = paste.query.filter(
#         Paste.id == id, Paste.user_id == user_id).first()
#     if paste is None:
#         return render_template("index.html"),4044
#     else:
#         return jsonify(success=True, paste=paste.to_dict())


# @mod_paste.route('/paste/<id>', methods=['POST'])
# @requires_auth
# def edit_paste(id):
#     user_id = session['user_id']
#     paste = Paste.query.filter(
#         Paste.id == id, Paste.user_id == user_id).first()
#     if paste is None:
#         return render_template("index.html"),4044
#     else:
#         paste.title = request.form['title']
#         paste.text = request.form['text']
#         paste.color = request.form['color']
#         paste.lang = request.form['lang']
#         db.session.commit()
#         return jsonify(success=True)


@mod_paste.route('/<url>/delete', methods=['POST'])
@requires_auth
def delete_paste(url):
	user_id = session['user_id']
	# print(user_id)
	paste = Paste.query.filter(Paste.url == url).first()
	user = User.query.filter(User.id == user_id).first()
	if paste is None:
		return render_template("index.html"), 404
	if is_active(paste):
		if paste.user_id == user_id or user.user_type == 2:
			userid_to_red = paste.user_id
			user_to_red = User.query.filter(User.id == userid_to_red).first()
			user_to_red.paste_count = user_to_red.paste_count - 1
			db.session.delete(paste)
			db.session.commit()
			return jsonify(success=True, user_type=user.user_type), 200
		else:
			return jsonify(success=False), 400
	else:
		userid_to_red = paste.user_id
		user_to_red = User.query.filter(User.id == userid_to_red).first()
		user_to_red.paste_count = user_to_red.paste_count - 1
		db.session.delete(paste)
		db.session.commit()
		return render_template("index.html"), 404


# @mod_paste.route('/<url>', methods=['GET'])
# def display_paste(url):
#     paste = Paste.query.filter(Paste.url == url).first()
#     style = HtmlFormatter().get_style_defs('.highlight')
#     lexer = get_lexer_by_name(paste.lang)
#     formatter = HtmlFormatter(linenos=True, cssclass="highlight")
#     result = highlight(paste.text, lexer, formatter)
# return render_template("view_paste.html", paste_title=paste.title,
# paste_lang=paste.lang, highlight_style=style,
@mod_paste.route('/<url>', methods=['GET'])
# paste_text=result,paste_rawdata = paste.text)
def display_paste(url):
	paste = Paste.query.filter(Paste.url == url).first()
	if Paste.query.filter(Paste.url == url).first() != None:
		if is_active(paste):
			if 'user_id' in session:
				if(paste.paste_type == "1" and session['user_id'] != paste.user_id):
					return render_template("index.html"), 200
				user_id = session['user_id']
				user = User.query.filter(User.id == user_id).first()
				if user.user_type == 1:
					return render_template('view_paste.html')
				if user.user_type == 2:
					return render_template('view_paste_admin.html')
			return render_template("view_paste_guest.html")
		else:
			userid_to_red = paste.user_id
			user_to_red = User.query.filter(User.id == userid_to_red).first()
			user_to_red.paste_count = user_to_red.paste_count - 1
			db.session.delete(paste)
			db.session.commit()
			return render_template("index.html"), 404
	else:
		return render_template("index.html"), 404


@mod_paste.route('/api/<url>', methods=['POST'])
def ret_paste(url):
	paste = Paste.query.filter(Paste.url == url).first()
	user = User.query.filter(paste.user_id == User.id).first()
	if is_active(paste):
		return jsonify({'paste_owner': user.username, 'paste_text': paste.text, 'paste_title': paste.title, 'paste_lang': paste.lang, 'paste_add': paste.add_time, 'paste_expire': paste.expire_time}), 200
	else:
		userid_to_red = paste.user_id
		user_to_red = User.query.filter(User.id == userid_to_red).first()
		user_to_red.paste_count = user_to_red.paste_count - 1
		db.session.delete(paste)
		db.session.commit()
		return render_template("index.html"), 404

# @mod_paste.route('/<url>/add_report', methods=['POST'])
# @requires_auth
# def to_delete(url):
#     paste_to_delete = Paste.query.filter(Paste.url == url).first()
#     if paste_to_delete.report_count > 5:
#         db.session.delete(paste_to_delete)
#     else:
#         paste_to_delete.report_count = paste_to_delete.report_count + 1
#     db.session.commit()
#     curr_id = session['user_id']
#     paste_list = Paste.query.filter(Paste.user_id == curr_id).all()
#     url_pre = "/"
#     for paste in paste_list:
#         paste.url = url_pre + paste.url
#     return render_template('mypaste.html', paste_list=paste_list)


@mod_paste.route('/<url>/edit', methods=['GET'])
@requires_auth
def edit_form(url):
	if 'user_id' in session:
		user_id = session['user_id']
		paste = Paste.query.filter(Paste.url == url).first()
		if is_active(paste):
			if paste.user_id == user_id:
				return render_template('editpaste.html')
			return jsonify(success=False, reply="Not Authorized"), 400
		else:
			userid_to_red = paste.user_id
			user_to_red = User.query.filter(User.id == userid_to_red).first()
			user_to_red.paste_count = user_to_red.paste_count - 1
			db.session.delete(paste)
			db.session.commit()
			return render_template("index.html"), 404
	return jsonify(success=False, reply="Please Login"), 400


@mod_paste.route('/<url>/edit', methods=['POST'])
@requires_auth
def edit_paste(url):
	if 'user_id' in session:
		user_id = session['user_id']
		paste = Paste.query.filter(Paste.url == url).first()
		if not is_active(paste):
			userid_to_red = paste.user_id
			user_to_red = User.query.filter(User.id == userid_to_red).first()
			user_to_red.paste_count = user_to_red.paste_count - 1
			db.session.delete(paste)
			db.session.commit()
			return render_template('index.html'), 404
		if paste.user_id != user_id:
			return jsonify(success=False, reply="Not Authorized"), 400
		title = request.form['title']
		text = request.form['text']
		lang = request.form['lang']
		time_form = request.form['time']
		paste_type = request.form['type']
		expire_time = str(time_form)

		paste.title = title
		paste.text = text
		paste.lang = lang
		paste.expire_time = expire_time
		paste.paste_type = paste_type
		db.session.commit()
		return jsonify(success=True, url=url)
	return jsonify(success=False, reply="Please Login")


@mod_paste.route('/admin/pastes', methods=['GET'])
@requires_admin
def all_pastes():
	paste_list = db.session.all()
	url_pre = "/"
	for paste in paste_list:
		if is_active(paste):
			paste.url = url_pre + paste.url
		else:
			userid_to_red = paste.user_id
			user_to_red = User.query.filter(User.id == userid_to_red).first()
			user_to_red.paste_count = user_to_red.paste_count - 1
			db.session.delete(paste)
			db.session.commit()
	return render_template('allpaste.html', paste_list=paste_list)


@mod_paste.route('/<username>/paste', methods=['GET'])
@requires_admin
def get_user_pastes(username):
	# user_id = session['user_id']
	# pastes = paste.query.filter(paste.user_id == user_id).all()
	if 'user_id' in session:
		return render_template('user_paste.html')
	else:
		return jsonify({'error': 'Please Login to Continue'}), 400
	# return jsonify(success=True, pastes=[paste.to_dict() for paste in
	# pastes])


@mod_paste.route('/<username>/api/paste', methods=['POST'])
#@requires_admin
def get_user_pastes_object(username):
	# admin_id = session['user_id']
	# admin = User.query.filter(admin_id == User.id).first()
	user = User.query.filter(User.username == username).first()
	pastes = Paste.query.filter(Paste.user_id == user.id).all()
	active = []
	for paste in pastes:
		if is_active(paste):
			active.append(paste.to_dict())
		else:
			userid_to_red = paste.user_id
			user_to_red = User.query.filter(User.id == userid_to_red).first()
			user_to_red.paste_count = user_to_red.paste_count - 1
			db.session.delete(paste)
			db.session.commit()
	return jsonify({'paste_list': active, 'username': user.username}), 200

[((29, 12, 29, 40), 'flask.Blueprint', 'Blueprint', ({(29, 22, 29, 29): '"""paste"""', (29, 31, 29, 39): '__name__'}, {}), "('paste', __name__)", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((30, 0, 30, 15), 'flask_cors.CORS', 'CORS', ({(30, 5, 30, 14): 'mod_paste'}, {}), '(mod_paste)', False, 'from flask_cors import CORS\n'), ((18, 2, 18, 10), 'functools.wraps', 'wraps', ({(18, 8, 18, 9): 'f'}, {}), '(f)', False, 'from functools import wraps\n'), ((42, 8, 42, 60), 'flask.render_template', 'render_template', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((356, 8, 356, 52), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((362, 14, 362, 30), 'app.db.session.all', 'db.session.all', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((373, 8, 373, 63), 'flask.render_template', 'render_template', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((34, 8, 34, 39), 'dateutil.parser.parse', 'parser.parse', ({(34, 21, 34, 38): 'paste.expire_time'}, {}), '(paste.expire_time)', False, 'from dateutil import parser\n'), ((34, 42, 34, 56), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n'), ((58, 16, 58, 30), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n'), ((59, 11, 59, 23), 'uuid.uuid4', 'uuid.uuid4', ({}, {}), '()', False, 'import uuid\n'), ((67, 2, 67, 23), 'app.db.session.add', 'db.session.add', ({(67, 17, 67, 22): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((68, 2, 68, 21), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((85, 9, 85, 40), 'flask.render_template', 'render_template', ({(85, 25, 85, 39): '"""mypaste.html"""'}, {}), "('mypaste.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((110, 8, 110, 66), 'flask.jsonify', 'jsonify', ({(110, 16, 110, 65): "{'paste_list': active, 'username': user.username}"}, {}), "({'paste_list': active, 'username': user.username})", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((117, 9, 117, 104), 'flask.render_template', 'render_template', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((122, 2, 122, 26), 'app.db.session.delete', 'db.session.delete', ({(122, 20, 122, 25): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((123, 2, 123, 21), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((136, 9, 136, 45), 'flask.render_template', 'render_template', ({(136, 25, 136, 44): '"""embed_output.html"""'}, {}), "('embed_output.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((141, 2, 141, 26), 'app.db.session.delete', 'db.session.delete', ({(141, 20, 141, 25): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((142, 2, 142, 21), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((235, 2, 235, 26), 'app.db.session.delete', 'db.session.delete', ({(235, 20, 235, 25): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((236, 2, 236, 21), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((286, 2, 286, 26), 'app.db.session.delete', 'db.session.delete', ({(286, 20, 286, 25): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((287, 2, 287, 21), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((324, 8, 324, 52), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((354, 2, 354, 21), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((355, 9, 355, 39), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((382, 9, 382, 43), 'flask.render_template', 'render_template', ({(382, 25, 382, 42): '"""user_paste.html"""'}, {}), "('user_paste.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((406, 8, 406, 66), 'flask.jsonify', 'jsonify', ({(406, 16, 406, 65): "{'paste_list': active, 'username': user.username}"}, {}), "({'paste_list': active, 'username': user.username})", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((41, 8, 41, 45), 'app.user.models.User.query.filter', 'User.query.filter', ({(41, 26, 41, 44): 'User.id == curr_id'}, {}), '(User.id == curr_id)', False, 'from app.user.models import User\n'), ((70, 9, 70, 30), 'flask.jsonify', 'jsonify', ({(70, 17, 70, 29): "{'url': url}"}, {}), "({'url': url})", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((84, 10, 84, 47), 'flask.render_template', 'render_template', ({(84, 26, 84, 46): '"""admin_mypaste.html"""'}, {}), "('admin_mypaste.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((87, 9, 87, 55), 'flask.jsonify', 'jsonify', ({(87, 17, 87, 54): "{'error': 'Please Login to Continue'}"}, {}), "({'error': 'Please Login to Continue'})", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((96, 8, 96, 45), 'app.user.models.User.query.filter', 'User.query.filter', ({(96, 26, 96, 44): 'user_id == User.id'}, {}), '(user_id == User.id)', False, 'from app.user.models import User\n'), ((105, 17, 105, 60), 'app.user.models.User.query.filter', 'User.query.filter', ({(105, 35, 105, 59): 'userid_to_red == User.id'}, {}), '(userid_to_red == User.id)', False, 'from app.user.models import User\n'), ((107, 3, 107, 27), 'app.db.session.delete', 'db.session.delete', ({(107, 21, 107, 26): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((108, 3, 108, 22), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((124, 9, 124, 38), 'flask.render_template', 'render_template', ({(124, 25, 124, 37): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((143, 9, 143, 38), 'flask.render_template', 'render_template', ({(143, 25, 143, 37): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((218, 8, 218, 45), 'app.user.models.User.query.filter', 'User.query.filter', ({(218, 26, 218, 44): 'User.id == user_id'}, {}), '(User.id == user_id)', False, 'from app.user.models import User\n'), ((220, 9, 220, 38), 'flask.render_template', 'render_template', ({(220, 25, 220, 37): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((226, 3, 226, 27), 'app.db.session.delete', 'db.session.delete', ({(226, 21, 226, 26): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((227, 3, 227, 22), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((237, 9, 237, 38), 'flask.render_template', 'render_template', ({(237, 25, 237, 37): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((264, 10, 264, 50), 'flask.render_template', 'render_template', ({(264, 26, 264, 49): '"""view_paste_guest.html"""'}, {}), "('view_paste_guest.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((269, 3, 269, 27), 'app.db.session.delete', 'db.session.delete', ({(269, 21, 269, 26): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((270, 3, 270, 22), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((273, 9, 273, 38), 'flask.render_template', 'render_template', ({(273, 25, 273, 37): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((279, 8, 279, 51), 'app.user.models.User.query.filter', 'User.query.filter', ({(279, 26, 279, 50): 'paste.user_id == User.id'}, {}), '(paste.user_id == User.id)', False, 'from app.user.models import User\n'), ((281, 9, 281, 192), 'flask.jsonify', 'jsonify', ({(281, 17, 281, 191): "{'paste_owner': user.username, 'paste_text': paste.text, 'paste_title':\n    paste.title, 'paste_lang': paste.lang, 'paste_add': paste.add_time,\n    'paste_expire': paste.expire_time}"}, {}), "({'paste_owner': user.username, 'paste_text': paste.text,\n    'paste_title': paste.title, 'paste_lang': paste.lang, 'paste_add':\n    paste.add_time, 'paste_expire': paste.expire_time})", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((288, 9, 288, 38), 'flask.render_template', 'render_template', ({(288, 25, 288, 37): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((321, 3, 321, 27), 'app.db.session.delete', 'db.session.delete', ({(321, 21, 321, 26): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((322, 3, 322, 22), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((337, 3, 337, 27), 'app.db.session.delete', 'db.session.delete', ({(337, 21, 337, 26): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((338, 3, 338, 22), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((371, 3, 371, 27), 'app.db.session.delete', 'db.session.delete', ({(371, 21, 371, 26): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((372, 3, 372, 22), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((384, 9, 384, 55), 'flask.jsonify', 'jsonify', ({(384, 17, 384, 54): "{'error': 'Please Login to Continue'}"}, {}), "({'error': 'Please Login to Continue'})", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((394, 8, 394, 52), 'app.user.models.User.query.filter', 'User.query.filter', ({(394, 26, 394, 51): 'User.username == username'}, {}), '(User.username == username)', False, 'from app.user.models import User\n'), ((404, 3, 404, 27), 'app.db.session.delete', 'db.session.delete', ({(404, 21, 404, 26): 'paste'}, {}), '(paste)', False, 'from app import db, requires_auth\n'), ((405, 3, 405, 22), 'app.db.session.commit', 'db.session.commit', ({}, {}), '()', False, 'from app import db, requires_auth\n'), ((21, 10, 21, 56), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((23, 9, 23, 46), 'app.user.models.User.query.filter', 'User.query.filter', ({(23, 27, 23, 45): 'User.id == user_id'}, {}), '(User.id == user_id)', False, 'from app.user.models import User\n'), ((25, 10, 25, 56), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((53, 9, 53, 52), 'app.user.models.User.query.filter', 'User.query.filter', ({(53, 27, 53, 51): "User.username == 'Guest'"}, {}), "(User.username == 'Guest')", False, 'from app.user.models import User\n'), ((64, 9, 64, 46), 'app.user.models.User.query.filter', 'User.query.filter', ({(64, 27, 64, 45): 'User.id == user_id'}, {}), '(User.id == user_id)', False, 'from app.user.models import User\n'), ((72, 9, 72, 96), 'flask.jsonify', 'jsonify', ({(72, 17, 72, 95): "{'error': 'Error while creating Paste, Please check if all fields are filled'}"}, {}), "({'error':\n    'Error while creating Paste, Please check if all fields are filled'})", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((82, 9, 82, 46), 'app.user.models.User.query.filter', 'User.query.filter', ({(82, 27, 82, 45): 'curr_id == User.id'}, {}), '(curr_id == User.id)', False, 'from app.user.models import User\n'), ((120, 16, 120, 59), 'app.user.models.User.query.filter', 'User.query.filter', ({(120, 34, 120, 58): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((139, 16, 139, 59), 'app.user.models.User.query.filter', 'User.query.filter', ({(139, 34, 139, 58): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((228, 10, 228, 57), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((230, 10, 230, 32), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((233, 16, 233, 59), 'app.user.models.User.query.filter', 'User.query.filter', ({(233, 34, 233, 58): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((271, 10, 271, 39), 'flask.render_template', 'render_template', ({(271, 26, 271, 38): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((284, 16, 284, 59), 'app.user.models.User.query.filter', 'User.query.filter', ({(284, 34, 284, 58): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((315, 11, 315, 44), 'flask.render_template', 'render_template', ({(315, 27, 315, 43): '"""editpaste.html"""'}, {}), "('editpaste.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((316, 10, 316, 56), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((323, 10, 323, 39), 'flask.render_template', 'render_template', ({(323, 26, 323, 38): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((339, 10, 339, 39), 'flask.render_template', 'render_template', ({(339, 26, 339, 38): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((341, 10, 341, 56), 'flask.jsonify', 'jsonify', (), '', False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((224, 17, 224, 60), 'app.user.models.User.query.filter', 'User.query.filter', ({(224, 35, 224, 59): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((261, 12, 261, 46), 'flask.render_template', 'render_template', ({(261, 28, 261, 45): '"""view_paste.html"""'}, {}), "('view_paste.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((263, 12, 263, 52), 'flask.render_template', 'render_template', ({(263, 28, 263, 51): '"""view_paste_admin.html"""'}, {}), "('view_paste_admin.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((267, 17, 267, 60), 'app.user.models.User.query.filter', 'User.query.filter', ({(267, 35, 267, 59): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((319, 17, 319, 60), 'app.user.models.User.query.filter', 'User.query.filter', ({(319, 35, 319, 59): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((335, 17, 335, 60), 'app.user.models.User.query.filter', 'User.query.filter', ({(335, 35, 335, 59): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((369, 17, 369, 60), 'app.user.models.User.query.filter', 'User.query.filter', ({(369, 35, 369, 59): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((402, 17, 402, 60), 'app.user.models.User.query.filter', 'User.query.filter', ({(402, 35, 402, 59): 'User.id == userid_to_red'}, {}), '(User.id == userid_to_red)', False, 'from app.user.models import User\n'), ((257, 12, 257, 41), 'flask.render_template', 'render_template', ({(257, 28, 257, 40): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((259, 11, 259, 48), 'app.user.models.User.query.filter', 'User.query.filter', ({(259, 29, 259, 47): 'User.id == user_id'}, {}), '(User.id == user_id)', False, 'from app.user.models import User\n')]