From 7bd50360e47efd1ae86e47e01bd3dc8fd742ec30 Mon Sep 17 00:00:00 2001
From: Jeff Zohrab
Date: Mon, 23 Oct 2023 20:57:35 -0700
Subject: [PATCH] Form to edit current page.
---
lute/read/forms.py | 13 +++++++++
lute/read/routes.py | 18 ++++++++++++
lute/templates/read/index.html | 2 +-
lute/templates/read/page_edit_form.html | 39 +++++++++++++++++++++++++
4 files changed, 71 insertions(+), 1 deletion(-)
create mode 100644 lute/read/forms.py
create mode 100644 lute/templates/read/page_edit_form.html
diff --git a/lute/read/forms.py b/lute/read/forms.py
new file mode 100644
index 00000000..12686468
--- /dev/null
+++ b/lute/read/forms.py
@@ -0,0 +1,13 @@
+"""
+Forms while reading.
+"""
+
+from flask_wtf import FlaskForm
+from wtforms import TextAreaField
+
+
+class TextForm(FlaskForm):
+ """
+ Text page - for editing a page.
+ """
+ text = TextAreaField('Text')
diff --git a/lute/read/routes.py b/lute/read/routes.py
index ed5a2ed1..c403f99c 100644
--- a/lute/read/routes.py
+++ b/lute/read/routes.py
@@ -7,6 +7,7 @@
from flask import Blueprint, render_template, flash, redirect
from lute.read.service import get_paragraphs, set_unknowns_to_known
+from lute.read.forms import TextForm
from lute.term.model import Repository
from lute.term.forms import TermForm
from lute.models.book import Book, Text
@@ -223,3 +224,20 @@ def make_array(t):
@bp.route('/keyboard_shortcuts', methods=['GET'])
def keyboard_shortcuts():
return render_template('read/keyboard_shortcuts.html')
+
+
+@bp.route('/editpage/', methods=['GET', 'POST'])
+def edit_page(textid):
+ "Edit the text on a page."
+ text = db.session.get(Text, textid)
+ if text is None:
+ return redirect('/', 302)
+ form = TextForm(obj=text)
+
+ if form.validate_on_submit():
+ form.populate_obj(text)
+ db.session.add(text)
+ db.session.commit()
+ return redirect(f'/read/{text.book.id}/page/{text.order}', 302)
+
+ return render_template('read/page_edit_form.html', form=form)
diff --git a/lute/templates/read/index.html b/lute/templates/read/index.html
index 06085449..70285cee 100644
--- a/lute/templates/read/index.html
+++ b/lute/templates/read/index.html
@@ -45,7 +45,7 @@
{% endif %}
-
+
diff --git a/lute/templates/read/page_edit_form.html b/lute/templates/read/page_edit_form.html
new file mode 100644
index 00000000..16a36601
--- /dev/null
+++ b/lute/templates/read/page_edit_form.html
@@ -0,0 +1,39 @@
+{% extends 'base.html' %}
+
+{% block title %}Edit Text{% endblock %}
+
+{% block body %}
+
+Edit Text
+
+{% for field_name, field_errors in form.errors.items() %}
+
{{ field_name }}
+
+ {% for error in field_errors %}
+ - {{ error }}
+ {% endfor %}
+
+
+{% endfor %}
+
+
+
+
+
+{% endblock %}
+