Skip to content

Commit

Permalink
Merge branch 'add_words_per_page' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed Jan 26, 2024
2 parents c45d3cd + a136852 commit 2f24a98
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lute/book/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import json
from flask import request
from wtforms import StringField, SelectField, TextAreaField
from wtforms import StringField, SelectField, TextAreaField, IntegerField
from wtforms import ValidationError
from wtforms.validators import DataRequired, Length
from wtforms.validators import DataRequired, Length, NumberRange
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed

Expand Down Expand Up @@ -34,6 +34,11 @@ class NewBookForm(FlaskForm):
)
],
)
max_page_tokens = IntegerField(
"Words per page",
validators=[NumberRange(min=10, max=1500)],
default=250,
)
source_uri = StringField("Text source", validators=[Length(max=255)])
audiofile = FileField(
"Audio file",
Expand Down
3 changes: 2 additions & 1 deletion lute/book/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self):
self.language_id = None
self.title = None
self.text = None
self.max_page_tokens = 250
self.source_uri = None
self.audio_filename = None
self.audio_current_pos = None
Expand Down Expand Up @@ -81,7 +82,7 @@ def _build_db_book(self, book):

b = None
if book.id is None:
b = DBBook.create_book(book.title, lang, book.text)
b = DBBook.create_book(book.title, lang, book.text, book.max_page_tokens)
else:
b = DBBook.find(book.id)
b.title = book.title
Expand Down
5 changes: 5 additions & 0 deletions lute/templates/book/create_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<td>{{ form.textfile() }}</td>
</tr>

<tr>
<td> {{ form.max_page_tokens.label }}</td>
<td> {{ form.max_page_tokens(class="form-control") }}</td>
</tr>

<tr>
<td>{{ form.source_uri.label }}</td>
<td>{{ form.source_uri(class="form-control") }}</td>
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/book/test_Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ def test_save_new(app_context, new_book, repo):
assert book.book_tags == ["tag1", "tag2"], "tags filled"


def test_save_new_respects_book_words_per_page_count(app_context, new_book, repo):
"""
Saving a simple Book object loads the database.
"""
sql = "select BkTitle from books where BkTitle = 'HELLO'"
assert_sql_result(sql, [], "empty table")

new_book.max_page_tokens = 10
new_book.text = (
"One two three four. One two three four five six seven eight nine ten eleven."
)
b = repo.add(new_book)
repo.commit()
assert_sql_result(sql, ["HELLO"], "Saved")
assert b.texts[0].text == "One two three four.", "page 1"
assert (
b.texts[1].text == "One two three four five six seven eight nine ten eleven."
), "page 2"

book = repo.load(b.id)
assert book.title == new_book.title, "found book"
assert book.book_tags == ["tag1", "tag2"], "tags filled"


def test_get_tags(app_context, new_book, repo):
"Helper method test."
assert repo.get_book_tags() == [], "no tags yet"
Expand Down

0 comments on commit 2f24a98

Please sign in to comment.