diff --git a/forms.py b/forms.py index 0aa6af5..68cfe3e 100644 --- a/forms.py +++ b/forms.py @@ -1,9 +1,10 @@ from flask import request -from flask_wtf import FlaskForm +from flask_wtf import FlaskForm, Form from wtforms import DateField, HiddenField, SelectField, SelectMultipleField, \ StringField from wtforms import ( TimeField, + FormField ) from wtforms.validators import DataRequired from wtforms.widgets import TextArea @@ -13,6 +14,14 @@ hymns = [('', 'None')] + [(h.ref, f'{h.ref} - {h.title}') for h in Music.neh_hymns()] +translations = [('', 'None')] + [(h.translation, f'{h.translation}') for h in + Music.neh_hymns()] + +class AnthemForm(Form): + title = StringField('Anthem') + composer = StringField('Anthem composer') + lyrics = StringField('Anthem lyrics', widget=TextArea()) + translation = SelectField('Anthem Translation', choices=translations) class PewSheetForm(FlaskForm): title = HiddenField('Title') @@ -35,9 +44,7 @@ class PewSheetForm(FlaskForm): offertory_hymn = SelectField('Offertory Hymn', choices=hymns) recessional_hymn = SelectField('Recessional Hymn', choices=hymns) - anthem_title = StringField('Anthem') - anthem_composer = StringField('Anthem composer') - anthem_lyrics = StringField('Anthem lyrics', widget=TextArea()) + anthem_group = FormField(AnthemForm) class Meta: csrf = False diff --git a/models.py b/models.py index 8ba9eba..43a566b 100644 --- a/models.py +++ b/models.py @@ -17,7 +17,7 @@ from models_base import get if typing.TYPE_CHECKING: - from forms import PewSheetForm + from forms import PewSheetForm, AnthemForm from utils import get_neh_df, advent, closest_sunday_to, NoPandasError, logger @@ -182,6 +182,7 @@ class Music: composer: Optional[str] = field() lyrics: Optional[str] = field() ref: Optional[str] = field() + translation: Optional[str] = field() @classmethod def neh_hymns(cls) -> List['Music']: @@ -203,7 +204,8 @@ def nehref2num(nehref: str) -> typing.Tuple[int, str]: category='Hymn', composer=None, lyrics=None, - ref=f'NEH: {record.number}' + ref=f'NEH: {record.number}', + translation=f'Words/translation available at NEH: {record.number}, {record.firstLine}' ) for record in records ] hymns.sort(key=lambda m: nehref2num(m.ref or "")) @@ -419,7 +421,7 @@ def items(self) -> List[PewSheetItem]: if self.anthem: items.append( - ServiceItem('Anthem', [self.anthem.lyrics], + ServiceItem('Anthem', [self.anthem.lyrics, self.anthem.translation], f'{self.anthem.title}. {self.anthem.composer}')) if self.recessional_hymn: @@ -438,13 +440,15 @@ def from_form(cls, form: 'PewSheetForm') -> 'Service': else: secondary_feasts = [] - if form.anthem_title.data or form.anthem_composer.data or form.anthem_lyrics.data: + if form.anthem_group.data: + ag = form.anthem_group anthem = Music( - title=form.anthem_title.data, - composer=form.anthem_composer.data, - lyrics=form.anthem_lyrics.data, + title=ag.title.data, + composer=ag.composer.data, + lyrics=ag.lyrics.data, category='Anthem', - ref=None + ref=None, + translation=ag.translation.data ) else: anthem = None diff --git a/requirements.txt b/requirements.txt index 6b00309..ea2de42 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,6 @@ python-dotenv~=0.21.0 python-slugify~=7.0.0 PyYAML~=6.0 WTForms~=3.0.1 -setuptools~=50.3.2 +setuptools~=71.1.0 openpyxl==3.0.9 Werkzeug~=2.2.2 diff --git a/templates/serviceForm.html b/templates/serviceForm.html index 54d55e8..b4f2708 100644 --- a/templates/serviceForm.html +++ b/templates/serviceForm.html @@ -122,11 +122,11 @@

- {{ form.anthem_title.label(class='col-sm-2 col-form-label') }} + {{ form.anthem_group.title.label(class='col-sm-2 col-form-label') }}
- {{ form.anthem_title(class='form-control') }} - {% if form.anthem_title.errors %} - {% for error in form.anthem_title.errors %} + {{ form.anthem_group.title(class='form-control') }} + {% if form.anthem_group.title.errors %} + {% for error in form.anthem_group.title.errors %} {{ error }} @@ -136,11 +136,11 @@

- {{ form.anthem_composer.label(class='col-sm-2 col-form-label') }} + {{ form.anthem_group.translation.label(class='col-sm-2 col-form-label') }}
- {{ form.anthem_composer(class='form-control') }} - {% if form.anthem_composer.errors %} - {% for error in form.anthem_composer.errors %} + {{ form.anthem_group.translation(class='form-select') }} + {% if form.anthem_group.translation.errors %} + {% for error in form.anthem_group.translation.errors %} {{ error }} @@ -150,11 +150,25 @@

- {{ form.anthem_lyrics.label(class='col-sm-2 col-form-label') }} + {{ form.anthem_group.composer.label(class='col-sm-2 col-form-label') }}
- {{ form.anthem_lyrics(class='form-control') }} - {% if form.anthem_lyrics.errors %} - {% for error in form.anthem_lyrics.errors %} + {{ form.anthem_group.composer(class='form-control') }} + {% if form.anthem_group.composer.errors %} + {% for error in form.anthem_group.composer.errors %} + + {{ error }} + + {% endfor %} + {% endif %} +
+
+ +
+ {{ form.anthem_group.lyrics.label(class='col-sm-2 col-form-label') }} +
+ {{ form.anthem_group.lyrics(class='form-control') }} + {% if form.anthem_group.lyrics.errors %} + {% for error in form.anthem_group.lyrics.errors %} {{ error }} diff --git a/tests/test_pypew.py b/tests/test_pypew.py index 6ca018e..522d061 100644 --- a/tests/test_pypew.py +++ b/tests/test_pypew.py @@ -77,7 +77,8 @@ def test_neh_lookup(self): category='Hymn', composer=None, lyrics=None, - ref='NEH: 1a') + ref='NEH: 1a', + translation = 'Words/translation available at NEH: 1a, Creator of the stars of night') ) def test_neh_lookup_unsuccessful(self): @@ -223,6 +224,7 @@ def test_pew_sheet_docx_view(self, m_create_docx): 'introit_hymn': '', 'offertory_hymn': '', 'recessional_hymn': '', + 'anthem_group-translation': '' } ) )