<commit_before>from flask import Blueprint
from flask import abort, flash, redirect, render_template, request, url_for
from flask.ext.login import current_user

from viaduct import application, db
from viaduct.helpers import flash_form_errors

from api import PageAPI
from models import Page, PageRevision, PagePermission
from forms import ChangePathForm, EditPageForm

module = Blueprint('page', __name__)

@application.errorhandler(403)
@application.errorhandler(404)
def get_error_page(error):
	return render_template('page/view_page.htm')

@module.route('/', methods=['GET', 'POST'])
@module.route('/<path:path>', methods=['GET', 'POST'])
def get_page(path=''):
	return render_template('page/view_page.htm', page=True, path=path)

@module.route('/delete/')
@module.route('/delete/<path:page_path>')
def delete_page(page_path='', revision=''):
	page = Page.query.filter(Page.path==page_path).first()
	revisions = PageRevision.query.filter(PageRevision.page_id==page.id).all()
	for revision in revisions:
		db.session.delete(revision)
	db.session.delete(page)
	db.session.commit()
	return redirect('/')

@module.route('/edit/', methods=['GET', 'POST'])
@module.route('/edit/<path:path>', methods=['GET', 'POST'])
def edit_page(path=''):
	rights = PagePermission.get_user_rights(current_user, path)

	if not rights['safe_edit'] or not rights['unsafe_edit']:
		abort(403)

	form = EditPageForm()

	if rights['unsafe_edit']:
		form.content_type.choices += ['1', 'HTML']

	if rights['safe_edit']:
		form.content_type.choices += ['2', 'Markdown']

	page = Page.query.filter(Page.path==path).first()
	revision = None

	if page:
		revision = page.revisions.order_by(PageRevision.timestamp.desc()).first()

	if request.method == 'POST':
		title = request.form['title'].strip()
		content = request.form['content'].strip()
		try:
			priority = int(request.form['priority'].strip())
		except:
			priority = 0

		# A new page is being created
		if not page:
			page = Page(page_path)

			db.session.add(page)
			db.session.commit()

		revision = PageRevision(page, current_user, title, content, priority)<commit_msg>Quick fix.<commit_after>from flask import Blueprint
from flask import abort, flash, redirect, render_template, request, url_for
from flask.ext.login import current_user

from viaduct import application, db
from viaduct.helpers import flash_form_errors

from api import PageAPI
from models import Page, PageRevision, PagePermission
from forms import ChangePathForm, EditPageForm

module = Blueprint('page', __name__)

@application.errorhandler(403)
@application.errorhandler(404)
def get_error_page(error):
	return render_template('page/view_page.htm')

@module.route('/', methods=['GET', 'POST'])
@module.route('/<path:path>', methods=['GET', 'POST'])
def get_page(path=''):
	return render_template('page/view_page.htm', page=True, path=path)

@module.route('/delete/')
@module.route('/delete/<path:page_path>')
def delete_page(page_path='', revision=''):
	page = Page.query.filter(Page.path==page_path).first()
	revisions = PageRevision.query.filter(PageRevision.page_id==page.id).all()
	for revision in revisions:
		db.session.delete(revision)
	db.session.delete(page)
	db.session.commit()
	return redirect('/')

@module.route('/edit/', methods=['GET', 'POST'])
@module.route('/edit/<path:path>', methods=['GET', 'POST'])
def edit_page(path=''):
	rights = PagePermission.get_user_rights(current_user, path)

	if not rights['safe_edit'] or not rights['unsafe_edit']:
		abort(403)

	form = EditPageForm()

	form.content_type.choices = []

	if rights['unsafe_edit']:
		form.content_type.choices.append(('1', 'HTML'))

	if rights['safe_edit']:
		form.content_type.choices.append(('2', 'Markdown'))

	page = Page.query.filter(Page.path==path).first()
	revision = None

	if page:
		revision = page.revisions.order_by(PageRevision.timestamp.desc()).first()

	if request.method == 'POST':
		title = request.form['title'].strip()
		content = request.form['content'].strip()
		try:
			priority = int(request.form['priority'].strip())
		except:
			priority = 0

		# A new page is being created
		if not page:
			page = Page(page_path)

			db.session.add(page)
			db.session.commit()

		revision = PageRevision(page, current_user, title, content, priority)
{'fraction_non_alphanumeric': 0.1599247412982126, 'fraction_numerical': 0.005644402634054563, 'mean_word_length': 5.859677419354838, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1268033', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1376, 'n_words': 299}