Skip to content

Commit

Permalink
Form to edit current page.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Oct 24, 2023
1 parent 1b06efe commit 7bd5036
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lute/read/forms.py
Original file line number Diff line number Diff line change
@@ -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')
18 changes: 18 additions & 0 deletions lute/read/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/<int:textid>', 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)
2 changes: 1 addition & 1 deletion lute/templates/read/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h2 style="margin: 0px;">
<img src="{{ url_for('static', filename='/icn/external.png') }}" title="Show source URL" />
</a>
{% endif %}
<a id="editText" href="/text/{{ text.id }}/edit" tabindex="-1">
<a id="editText" href="/read/editpage/{{ text.id }}" tabindex="-1">
<img src="{{ url_for('static', filename='/icn/document--pencil.png') }}"
title="Edit" alt="Edit" />
</a>
Expand Down
39 changes: 39 additions & 0 deletions lute/templates/read/page_edit_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends 'base.html' %}

{% block title %}Edit Text{% endblock %}

{% block body %}

<h1>Edit Text</h1>

{% for field_name, field_errors in form.errors.items() %}
<p>{{ field_name }}
<ul>
{% for error in field_errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
</p>
{% endfor %}

<form method="POST">
{{ form.hidden_tag() }}

<table>
<tr><td>
{{ form.text(class="form-largetextarea") }}
</td></tr>
<tr><td>
<button type="submit" class="btn btn-primary">Save</button>
</td></tr>
</table>
</form>

<table>
<tr><td>
<button onclick="history.back()">Cancel</button>
</td></tr>
</table>

{% endblock %}

0 comments on commit 7bd5036

Please sign in to comment.