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

[((885, 913), 'flask.Blueprint', 'Blueprint', (['"""paste"""', '__name__'], {}), "('paste', __name__)\n", (894, 913), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((914, 929), 'flask_cors.CORS', 'CORS', (['mod_paste'], {}), '(mod_paste)\n', (918, 929), False, 'from flask_cors import CORS\n'), ((516, 524), 'functools.wraps', 'wraps', (['f'], {}), '(f)\n', (521, 524), False, 'from functools import wraps\n'), ((1190, 1242), 'flask.render_template', 'render_template', (['"""user.html"""'], {'username': 'user.username'}), "('user.html', username=user.username)\n", (1205, 1242), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((12287, 12331), 'flask.jsonify', 'jsonify', ([], {'success': '(False)', 'reply': '"""Please Login"""'}), "(success=False, reply='Please Login')\n", (12294, 12331), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((12433, 12449), 'app.db.session.all', 'db.session.all', ([], {}), '()\n', (12447, 12449), False, 'from app import db, requires_auth\n'), ((12775, 12830), 'flask.render_template', 'render_template', (['"""allpaste.html"""'], {'paste_list': 'paste_list'}), "('allpaste.html', paste_list=paste_list)\n", (12790, 12830), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((962, 993), 'dateutil.parser.parse', 'parser.parse', (['paste.expire_time'], {}), '(paste.expire_time)\n', (974, 993), False, 'from dateutil import parser\n'), ((996, 1010), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (1008, 1010), False, 'from datetime import datetime\n'), ((1666, 1680), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (1678, 1680), False, 'from datetime import datetime\n'), ((1693, 1705), 'uuid.uuid4', 'uuid.uuid4', ([], {}), '()\n', (1703, 1705), False, 'import uuid\n'), ((1943, 1964), 'app.db.session.add', 'db.session.add', (['paste'], {}), '(paste)\n', (1957, 1964), False, 'from app import db, requires_auth\n'), ((1967, 1986), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (1984, 1986), False, 'from app import db, requires_auth\n'), ((2556, 2587), 'flask.render_template', 'render_template', (['"""mypaste.html"""'], {}), "('mypaste.html')\n", (2571, 2587), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((3289, 3347), 'flask.jsonify', 'jsonify', (["{'paste_list': active, 'username': user.username}"], {}), "({'paste_list': active, 'username': user.username})\n", (3296, 3347), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((3516, 3616), 'flask.render_template', 'render_template', (['"""embed.html"""'], {'paste_text': 'paste.text', 'paste_link': "('http://127.0.0.1:8080/' + url)"}), "('embed.html', paste_text=paste.text, paste_link=\n    'http://127.0.0.1:8080/' + url)\n", (3531, 3616), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((3777, 3801), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (3794, 3801), False, 'from app import db, requires_auth\n'), ((3804, 3823), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (3821, 3823), False, 'from app import db, requires_auth\n'), ((4231, 4267), 'flask.render_template', 'render_template', (['"""embed_output.html"""'], {}), "('embed_output.html')\n", (4246, 4267), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((4433, 4457), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (4450, 4457), False, 'from app import db, requires_auth\n'), ((4460, 4479), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (4477, 4479), False, 'from app import db, requires_auth\n'), ((7767, 7791), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (7784, 7791), False, 'from app import db, requires_auth\n'), ((7794, 7813), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (7811, 7813), False, 'from app import db, requires_auth\n'), ((9914, 9938), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (9931, 9938), False, 'from app import db, requires_auth\n'), ((9941, 9960), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (9958, 9960), False, 'from app import db, requires_auth\n'), ((11269, 11313), 'flask.jsonify', 'jsonify', ([], {'success': '(False)', 'reply': '"""Please Login"""'}), "(success=False, reply='Please Login')\n", (11276, 11313), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((12219, 12238), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (12236, 12238), False, 'from app import db, requires_auth\n'), ((12248, 12278), 'flask.jsonify', 'jsonify', ([], {'success': '(True)', 'url': 'url'}), '(success=True, url=url)\n', (12255, 12278), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((13065, 13099), 'flask.render_template', 'render_template', (['"""user_paste.html"""'], {}), "('user_paste.html')\n", (13080, 13099), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((13897, 13955), 'flask.jsonify', 'jsonify', (["{'paste_list': active, 'username': user.username}"], {}), "({'paste_list': active, 'username': user.username})\n", (13904, 13955), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((1136, 1173), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == curr_id)'], {}), '(User.id == curr_id)\n', (1153, 1173), False, 'from app.user.models import User\n'), ((2045, 2066), 'flask.jsonify', 'jsonify', (["{'url': url}"], {}), "({'url': url})\n", (2052, 2066), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((2509, 2546), 'flask.render_template', 'render_template', (['"""admin_mypaste.html"""'], {}), "('admin_mypaste.html')\n", (2524, 2546), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((2604, 2650), 'flask.jsonify', 'jsonify', (["{'error': 'Please Login to Continue'}"], {}), "({'error': 'Please Login to Continue'})\n", (2611, 2650), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((2870, 2907), 'app.user.models.User.query.filter', 'User.query.filter', (['(user_id == User.id)'], {}), '(user_id == User.id)\n', (2887, 2907), False, 'from app.user.models import User\n'), ((3128, 3171), 'app.user.models.User.query.filter', 'User.query.filter', (['(userid_to_red == User.id)'], {}), '(userid_to_red == User.id)\n', (3145, 3171), False, 'from app.user.models import User\n'), ((3232, 3256), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (3249, 3256), False, 'from app import db, requires_auth\n'), ((3260, 3279), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (3277, 3279), False, 'from app import db, requires_auth\n'), ((3833, 3862), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (3848, 3862), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((4489, 4518), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (4504, 4518), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((7098, 7135), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == user_id)'], {}), '(User.id == user_id)\n', (7115, 7135), False, 'from app.user.models import User\n'), ((7172, 7201), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (7187, 7201), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((7445, 7469), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (7462, 7469), False, 'from app import db, requires_auth\n'), ((7473, 7492), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (7490, 7492), False, 'from app import db, requires_auth\n'), ((7823, 7852), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (7838, 7852), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((8989, 9029), 'flask.render_template', 'render_template', (['"""view_paste_guest.html"""'], {}), "('view_paste_guest.html')\n", (9004, 9029), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((9200, 9224), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (9217, 9224), False, 'from app import db, requires_auth\n'), ((9228, 9247), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (9245, 9247), False, 'from app import db, requires_auth\n'), ((9309, 9338), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (9324, 9338), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((9477, 9520), 'app.user.models.User.query.filter', 'User.query.filter', (['(paste.user_id == User.id)'], {}), '(paste.user_id == User.id)\n', (9494, 9520), False, 'from app.user.models import User\n'), ((9560, 9751), 'flask.jsonify', 'jsonify', (["{'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})\n", (9567, 9751), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((9970, 9999), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (9985, 9999), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((11168, 11192), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (11185, 11192), False, 'from app import db, requires_auth\n'), ((11196, 11215), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (11213, 11215), False, 'from app import db, requires_auth\n'), ((11708, 11732), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (11725, 11732), False, 'from app import db, requires_auth\n'), ((11736, 11755), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (11753, 11755), False, 'from app import db, requires_auth\n'), ((12719, 12743), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (12736, 12743), False, 'from app import db, requires_auth\n'), ((12747, 12766), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (12764, 12766), False, 'from app import db, requires_auth\n'), ((13116, 13162), 'flask.jsonify', 'jsonify', (["{'error': 'Please Login to Continue'}"], {}), "({'error': 'Please Login to Continue'})\n", (13123, 13162), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((13465, 13509), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.username == username)'], {}), '(User.username == username)\n', (13482, 13509), False, 'from app.user.models import User\n'), ((13841, 13865), 'app.db.session.delete', 'db.session.delete', (['paste'], {}), '(paste)\n', (13858, 13865), False, 'from app import db, requires_auth\n'), ((13869, 13888), 'app.db.session.commit', 'db.session.commit', ([], {}), '()\n', (13886, 13888), False, 'from app import db, requires_auth\n'), ((599, 645), 'flask.jsonify', 'jsonify', ([], {'message': '"""Unauthorized"""', 'success': '(False)'}), "(message='Unauthorized', success=False)\n", (606, 645), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((691, 728), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == user_id)'], {}), '(User.id == user_id)\n', (708, 728), False, 'from app.user.models import User\n'), ((774, 820), 'flask.jsonify', 'jsonify', ([], {'message': '"""Unauthorized"""', 'success': '(False)'}), "(message='Unauthorized', success=False)\n", (781, 820), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((1485, 1528), 'app.user.models.User.query.filter', 'User.query.filter', (["(User.username == 'Guest')"], {}), "(User.username == 'Guest')\n", (1502, 1528), False, 'from app.user.models import User\n'), ((1845, 1882), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == user_id)'], {}), '(User.id == user_id)\n', (1862, 1882), False, 'from app.user.models import User\n'), ((2090, 2181), 'flask.jsonify', 'jsonify', (["{'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'})\n", (2097, 2181), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((2427, 2464), 'app.user.models.User.query.filter', 'User.query.filter', (['(curr_id == User.id)'], {}), '(curr_id == User.id)\n', (2444, 2464), False, 'from app.user.models import User\n'), ((3667, 3710), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (3684, 3710), False, 'from app.user.models import User\n'), ((4323, 4366), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (4340, 4366), False, 'from app.user.models import User\n'), ((7503, 7550), 'flask.jsonify', 'jsonify', ([], {'success': '(True)', 'user_type': 'user.user_type'}), '(success=True, user_type=user.user_type)\n', (7510, 7550), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((7574, 7596), 'flask.jsonify', 'jsonify', ([], {'success': '(False)'}), '(success=False)\n', (7581, 7596), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((7657, 7700), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (7674, 7700), False, 'from app.user.models import User\n'), ((9258, 9287), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (9273, 9287), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((9804, 9847), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (9821, 9847), False, 'from app.user.models import User\n'), ((10902, 10935), 'flask.render_template', 'render_template', (['"""editpaste.html"""'], {}), "('editpaste.html')\n", (10917, 10935), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((10946, 10992), 'flask.jsonify', 'jsonify', ([], {'success': '(False)', 'reply': '"""Not Authorized"""'}), "(success=False, reply='Not Authorized')\n", (10953, 10992), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((11226, 11255), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (11241, 11255), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((11766, 11795), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (11781, 11795), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((11842, 11888), 'flask.jsonify', 'jsonify', ([], {'success': '(False)', 'reply': '"""Not Authorized"""'}), "(success=False, reply='Not Authorized')\n", (11849, 11888), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((7333, 7376), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (7350, 7376), False, 'from app.user.models import User\n'), ((8863, 8897), 'flask.render_template', 'render_template', (['"""view_paste.html"""'], {}), "('view_paste.html')\n", (8878, 8897), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((8938, 8978), 'flask.render_template', 'render_template', (['"""view_paste_admin.html"""'], {}), "('view_paste_admin.html')\n", (8953, 8978), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((9088, 9131), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (9105, 9131), False, 'from app.user.models import User\n'), ((11056, 11099), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (11073, 11099), False, 'from app.user.models import User\n'), ((11596, 11639), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (11613, 11639), False, 'from app.user.models import User\n'), ((12607, 12650), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (12624, 12650), False, 'from app.user.models import User\n'), ((13729, 13772), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == userid_to_red)'], {}), '(User.id == userid_to_red)\n', (13746, 13772), False, 'from app.user.models import User\n'), ((8698, 8727), 'flask.render_template', 'render_template', (['"""index.html"""'], {}), "('index.html')\n", (8713, 8727), False, 'from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, jsonify\n'), ((8777, 8814), 'app.user.models.User.query.filter', 'User.query.filter', (['(User.id == user_id)'], {}), '(User.id == user_id)\n', (8794, 8814), False, 'from app.user.models import User\n')]