From 9ce827019c68b2085d4eadb9f89dd0403ec8442f Mon Sep 17 00:00:00 2001 From: Pekko Sams Date: Fri, 23 Aug 2024 09:35:27 +0300 Subject: [PATCH 1/2] Added default and validation for municipality+translations --- README.md | 2 ++ app.py | 9 +++-- messages.pot | 36 ++++++++++---------- translations/en/LC_MESSAGES/messages.mo | Bin 507 -> 507 bytes translations/en/LC_MESSAGES/messages.po | 40 ++++++++++++---------- translations/fi/LC_MESSAGES/messages.mo | Bin 1743 -> 1722 bytes translations/fi/LC_MESSAGES/messages.po | 42 ++++++++++++++---------- translations/sv/LC_MESSAGES/messages.mo | Bin 1775 -> 1753 bytes translations/sv/LC_MESSAGES/messages.po | 42 ++++++++++++++---------- 9 files changed, 98 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 1a6c37a..603a33f 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ If you change the municipalities emails csv file remember to restart the server Create a virtual environment with something like `python -m venv venv` +activate it +`. ./venv/bin/activate` then install dependencies with `pip install -r requirements.txt`. and run the app with diff --git a/app.py b/app.py index 64f95c8..6205e29 100644 --- a/app.py +++ b/app.py @@ -19,6 +19,7 @@ SelectField, SubmitField, validators, + ValidationError ) from flask_babel import lazy_gettext as _ @@ -47,6 +48,9 @@ def get_locale(): csrf = CSRFProtect(app) app.secret_key = secrets.token_urlsafe(16) +def validate_municipality(form, field): + if field.data == "": + raise ValidationError(_("Please select a valid municipality.")) class FeedbackForm(FlaskForm): subject = SelectField( @@ -71,14 +75,16 @@ class FeedbackForm(FlaskForm): _("Message"), [validators.DataRequired(), validators.Length(1, 2048)], ) + municipality = SelectField( _("My home municipality that receives this feedback"), - choices=indexed_municipalities(), + choices=[("", _("Select a municipality"))] + indexed_municipalities(), render_kw={ "class": "form-select", "data-control": "select2", "data-dropdown-parent": "body", }, + validators=[validate_municipality] ) email = EmailField( _("Email address, if you want an answer to your feedback (Optional)"), @@ -88,7 +94,6 @@ class FeedbackForm(FlaskForm): _("Send"), ) - @app.route(root_path, methods=["GET", "POST"]) def feedback(name=None): form = FeedbackForm() diff --git a/messages.pot b/messages.pot index 237b85e..2a0ea6d 100644 --- a/messages.pot +++ b/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-06-04 16:08+0300\n" +"POT-Creation-Date: 2024-08-23 09:07+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,6 +17,10 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.14.0\n" +#: app.py:53 +msgid "Please select a valid municipality." +msgstr "" + #: app.py:57 msgid "Subject" msgstr "" @@ -69,49 +73,45 @@ msgstr "" msgid "Message" msgstr "" -#: app.py:79 +#: app.py:81 msgid "My home municipality that receives this feedback" msgstr "" -#: app.py:88 +#: app.py:82 +msgid "Select a municipality" +msgstr "" + +#: app.py:91 msgid "Email address, if you want an answer to your feedback (Optional)" msgstr "" -#: app.py:92 +#: app.py:95 msgid "Send" msgstr "" -#: app.py:138 +#: app.py:144 msgid "English" msgstr "" -#: app.py:139 +#: app.py:145 msgid "Finnish" msgstr "" -#: app.py:140 +#: app.py:146 msgid "Swedish" msgstr "" -#: app.py:149 +#: app.py:155 msgid "" "You can leave feedback about the E-library or suggest materials for " "acquisition. Suggestions for materials will not be responded to." msgstr "" -#: app.py:219 +#: app.py:226 msgid "Thank you for your feedback!" msgstr "" -#: app.py:225 +#: app.py:232 msgid "There was a problem sending your message." msgstr "" -#: municipalities.py:51 -msgid "My home municipality is missing from this list" -msgstr "" - -#: municipalities.py:54 -msgid "I don't want to say" -msgstr "" - diff --git a/translations/en/LC_MESSAGES/messages.mo b/translations/en/LC_MESSAGES/messages.mo index 2ccdcb6651ab14c3fd56ae5fee73faf397d31bbd..6cc4e399e435ef404b21e280903fd271b7300d68 100644 GIT binary patch delta 21 ccmey({F`~gJ}wJgBVz>vODhBOjVFv50adF8_5c6? delta 21 ccmey({F`~gJ}xs|0}};9Gb;m&jVFv50abVg@&Et; diff --git a/translations/en/LC_MESSAGES/messages.po b/translations/en/LC_MESSAGES/messages.po index 190b8c6..ee37049 100644 --- a/translations/en/LC_MESSAGES/messages.po +++ b/translations/en/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-06-04 16:08+0300\n" +"POT-Creation-Date: 2024-08-23 09:07+0300\n" "PO-Revision-Date: 2024-04-16 17:50+0300\n" "Last-Translator: FULL NAME \n" "Language: en\n" @@ -18,6 +18,10 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.14.0\n" +#: app.py:53 +msgid "Please select a valid municipality." +msgstr "" + #: app.py:57 msgid "Subject" msgstr "" @@ -70,52 +74,54 @@ msgstr "" msgid "Message" msgstr "" -#: app.py:79 +#: app.py:81 msgid "My home municipality that receives this feedback" msgstr "" -#: app.py:88 +#: app.py:82 +msgid "Select a municipality" +msgstr "" + +#: app.py:91 msgid "Email address, if you want an answer to your feedback (Optional)" msgstr "" -#: app.py:92 +#: app.py:95 msgid "Send" msgstr "" -#: app.py:138 +#: app.py:144 msgid "English" msgstr "" -#: app.py:139 +#: app.py:145 msgid "Finnish" msgstr "Suomi" -#: app.py:140 +#: app.py:146 msgid "Swedish" msgstr "Svenska" -#: app.py:149 +#: app.py:155 msgid "" "You can leave feedback about the E-library or suggest materials for " "acquisition. Suggestions for materials will not be responded to." msgstr "" -#: app.py:219 +#: app.py:226 msgid "Thank you for your feedback!" msgstr "" -#: app.py:225 +#: app.py:232 msgid "There was a problem sending your message." msgstr "" -#: municipalities.py:51 -msgid "My home municipality is missing from this list" -msgstr "" +#~ msgid "Software version" +#~ msgstr "" -#: municipalities.py:54 -msgid "I don't want to say" -msgstr "" +#~ msgid "My home municipality is missing from this list" +#~ msgstr "" -#~ msgid "Software version" +#~ msgid "I don't want to say" #~ msgstr "" diff --git a/translations/fi/LC_MESSAGES/messages.mo b/translations/fi/LC_MESSAGES/messages.mo index 2bf6b81f0f48b7a1f49f9675156e37bd8bf2172a..b26274d2691d82b251b092ae10be1c9841f1b7f8 100644 GIT binary patch delta 422 zcmYk%u}i~H5XbRL+f-4i7E}-fABsUiOVL5=Ac%twRtlofMF=%QNK6Y&6>;d|Dis0_ z{t2$##KF};1QB!*=MFAHaT5GKh~V_O-@TW+m#55a=5nh!AR-Tj$S}TP4}M}EyJ(`7 z5ShX`9KjN%@DTNVFSd?Z@)?ff1_} zDDLAJHsbRZPLr>YS#pQ^-aYCEyrQ1hLH*FLIDg|1SufE)oK3UEqOfTASd7X>EqXWB zqGDpQQ1TtS?x?!sJC#t`>e%+(19j90+=^SH4o`Ek^LO~a-3}7FM&I)M!lKF-R`N^j t$K8))vNt73o8&B&QL}~VGts=bN5w!XT1WnP@AboE*96s;+^75Q>9+Pj$tKC*w2=QtOF^XNBz%NXo6%k?y z2Qh~Qw9&yBdKm7RzUMej-^OXY!FlXp8@qT(b}=f%F#UH-w8S<=kF){YB0Y|Kn8Jg; zWt^gKVg@fT+`Gpae85@!K(fUzhIu^_>16Co%kJHqI?siZupRECz>GJ-s83 zJ$KH?rgDump493rc(K+qj+Qk?YsW3iQp2lBQ(;ndv\n" "Language: fi\n" @@ -18,6 +18,10 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.14.0\n" +#: app.py:53 +msgid "Please select a valid municipality." +msgstr "Valinta on pakollinen." + #: app.py:57 msgid "Subject" msgstr "Aihe" @@ -70,31 +74,35 @@ msgstr "Kirjan nimi" msgid "Message" msgstr "Viesti" -#: app.py:79 +#: app.py:81 msgid "My home municipality that receives this feedback" msgstr "Kotikuntani, jolle palaute osoitetaan" -#: app.py:88 +#: app.py:82 +msgid "Select a municipality" +msgstr "Valitse kotikunta" + +#: app.py:91 msgid "Email address, if you want an answer to your feedback (Optional)" msgstr "Sähköpostiosoite, johon haluat vastauksen palautteellesi (Valinnainen)" -#: app.py:92 +#: app.py:95 msgid "Send" msgstr "Lähetä" -#: app.py:138 +#: app.py:144 msgid "English" msgstr "English " -#: app.py:139 +#: app.py:145 msgid "Finnish" msgstr "Suomi " -#: app.py:140 +#: app.py:146 msgid "Swedish" msgstr "Svenska " -#: app.py:149 +#: app.py:155 msgid "" "You can leave feedback about the E-library or suggest materials for " "acquisition. Suggestions for materials will not be responded to." @@ -102,22 +110,20 @@ msgstr "" "Voit jättää palautetta E-kirjastosta tai ehdottaa hankittavia aineistoja." " Aineistoehdotuksiin ei vastata." -#: app.py:219 +#: app.py:226 msgid "Thank you for your feedback!" msgstr "Kiitos palautteesta!" -#: app.py:225 +#: app.py:232 msgid "There was a problem sending your message." msgstr "Viestin lähetyksessä tapahtui virhe." -#: municipalities.py:51 -msgid "My home municipality is missing from this list" -msgstr "Kotikuntani puuttuu tästä listasta" - -#: municipalities.py:54 -msgid "I don't want to say" -msgstr "En halua kertoa" - #~ msgid "Software version" #~ msgstr "" +#~ msgid "My home municipality is missing from this list" +#~ msgstr "Kotikuntani puuttuu tästä listasta" + +#~ msgid "I don't want to say" +#~ msgstr "En halua kertoa" + diff --git a/translations/sv/LC_MESSAGES/messages.mo b/translations/sv/LC_MESSAGES/messages.mo index c1097425ecfb54d38c09a11208b11e6373bd93ce..f248d302026c43de4b064d8bd5bca72e5a06ab40 100644 GIT binary patch delta 426 zcmYk#y-Px26vy#%)mvfM3%$_L@bp3ym{<*_O-?NZMi>Y!SH0EE>s8c(C~#>Cq~QJw zPOVPOP7N*5P(*9cAPwbIL*EMp!Nd8S^E`*&^B#H%U2W6{MC4Wz8O2BJ#STWXi#pEv zL}oCIW0=AK?xD9|__d0|%%?bs4P3x$JjVyTBs1d|>1TcmNL|)wx}^2t62J9e0tYdP zL%4-rU>1W|$9cR!j7?@;}ha`^Iq$_3%rKW|r+U+;uZr*?rNH z?xt@#p0Z7&YO1Pfo4J}Y)Ujb(c~v}etejP*ubo6>`|t7pb<6RkwczUF@`{Sa6VX`f z&fm~nM_+fJ^{H^WLXc`VE2@;Wt$m|bs#w)REh0PZrhTaLmZJ{LVxd$d(*4pue*pXa BQHuZo delta 413 zcmXZWKT88K9LDja?NwW;|0;^$5D-xZLds%P9lB}3L&506T*|c=00-Qd!4)x;#mqYihZ2IcN{{Q5MmWG zXrqG``k2B1<9lXc8z;zJoWmPj#vXRDk5_abCxsXxf2Kr7Y%=`OHjG8u)3}XeSi<;& zM>vielH+?)e?$Bq8q4VB9l_(>R~zl?{d>2W@Odhq961Rpmf0 z8g=e!qfDSew-r6ftyw=*bw3P!T~(E4P*>)JlbRoz=vz9yO5#9f3oG`zS}PQ7r}vn= xl=+fdRcC&!rhIKYb=qiDy=dRsnW?zOxFIzUcUqM_tzA|3bSt{B?C8z<`Ujs9NUHz< diff --git a/translations/sv/LC_MESSAGES/messages.po b/translations/sv/LC_MESSAGES/messages.po index 53691c6..b7aeaea 100644 --- a/translations/sv/LC_MESSAGES/messages.po +++ b/translations/sv/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2024-06-04 16:08+0300\n" +"POT-Creation-Date: 2024-08-23 09:07+0300\n" "PO-Revision-Date: 2024-04-16 16:43+0300\n" "Last-Translator: FULL NAME \n" "Language: sv\n" @@ -18,6 +18,10 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.14.0\n" +#: app.py:53 +msgid "Please select a valid municipality." +msgstr "Urval är obligatoriskt." + #: app.py:57 msgid "Subject" msgstr "Ämne" @@ -70,31 +74,35 @@ msgstr "Bokens namn" msgid "Message" msgstr "Meddelande" -#: app.py:79 +#: app.py:81 msgid "My home municipality that receives this feedback" msgstr "Min hemkommun som hanterar denna respons" -#: app.py:88 +#: app.py:82 +msgid "Select a municipality" +msgstr "Välj din hemkommun" + +#: app.py:91 msgid "Email address, if you want an answer to your feedback (Optional)" msgstr "Epostaddress, om du vill ha svar på din respons (Valfritt)" -#: app.py:92 +#: app.py:95 msgid "Send" msgstr "Skicka" -#: app.py:138 +#: app.py:144 msgid "English" msgstr "English " -#: app.py:139 +#: app.py:145 msgid "Finnish" msgstr "Suomi " -#: app.py:140 +#: app.py:146 msgid "Swedish" msgstr "Svenska " -#: app.py:149 +#: app.py:155 msgid "" "You can leave feedback about the E-library or suggest materials for " "acquisition. Suggestions for materials will not be responded to." @@ -102,22 +110,20 @@ msgstr "" "Du kan lämna feedback om E-biblioteket eller föreslå material för inköp. " "Förslag på material kommer inte att besvaras" -#: app.py:219 +#: app.py:226 msgid "Thank you for your feedback!" msgstr "Tack för din respons!" -#: app.py:225 +#: app.py:232 msgid "There was a problem sending your message." msgstr "Det uppstod ett problem med att skicka ditt meddelande." -#: municipalities.py:51 -msgid "My home municipality is missing from this list" -msgstr "Min hemkommun fattas från denna meny" - -#: municipalities.py:54 -msgid "I don't want to say" -msgstr "Jag vill inte uppge" - #~ msgid "Software version" #~ msgstr "" +#~ msgid "My home municipality is missing from this list" +#~ msgstr "Min hemkommun fattas från denna meny" + +#~ msgid "I don't want to say" +#~ msgstr "Jag vill inte uppge" + From 280b532101d534e0a37348fed286786f70ab4ec8 Mon Sep 17 00:00:00 2001 From: Pekko Sams Date: Fri, 23 Aug 2024 09:35:59 +0300 Subject: [PATCH 2/2] build dev branch on push --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 12b1863..2c7d244 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,7 +2,7 @@ name: Build on: push: - branches: ["*"] + branches: ["dev"] pull_request: branches: ["main"] release: