diff --git a/kaehmy/views.py b/kaehmy/views.py index 8e7ab29..9d46404 100644 --- a/kaehmy/views.py +++ b/kaehmy/views.py @@ -24,28 +24,38 @@ from webapp.utils import send_email def list_view(request, *args, **kwargs): """Kaehmy application list""" - role_filter = request.GET.get('role', None) - if role_filter is not None and str(role_filter) != '-1': - applications = Application.objects.filter(custom_roles__id=role_filter) | Application.objects.filter(preset_roles__id=role_filter) + role_filter = request.GET.get("role", None) + if role_filter is not None and str(role_filter) != "-1": + applications = Application.objects.filter( + custom_roles__id=role_filter + ) | Application.objects.filter(preset_roles__id=role_filter) else: applications = Application.objects.all() - applications = applications.order_by('-timestamp') - filter_options_preset = PresetRole.objects.annotate(form_count=Count('forms')).filter(form_count__gt=0) - filter_options_preset_list = [(r.id, r.name, r.form_count) for r in filter_options_preset] - filter_options_custom = CustomRole.objects.annotate(form_count=Count('forms')).filter(form_count__gt=0) - filter_options_custom_list = [(r.id, r.name, r.form_count) for r in filter_options_custom] + applications = applications.order_by("-timestamp") + filter_options_preset = PresetRole.objects.annotate( + form_count=Count("forms") + ).filter(form_count__gt=0) + filter_options_preset_list = [ + (r.id, r.name, r.form_count) for r in filter_options_preset + ] + filter_options_custom = CustomRole.objects.annotate( + form_count=Count("forms") + ).filter(form_count__gt=0) + filter_options_custom_list = [ + (r.id, r.name, r.form_count) for r in filter_options_custom + ] filter_options = filter_options_preset_list + filter_options_custom_list filter_options.sort(key=lambda f: f[1]) context = { - 'applications': applications, - 'application_count': len(applications), - 'filter_options': filter_options + "applications": applications, + "application_count": len(applications), + "filter_options": filter_options, } - return render(request, 'kaehmy:list.html', context) + return render(request, "kaehmy:list.html", context) @ensure_csrf_cookie @@ -56,23 +66,21 @@ def comment(request, *args, **kwargs): form = CommentForm(request.POST) if form.is_valid(): comment = form.save() - email = comment.parent.email name = comment.name - subject = 'Kaehmyysi tai kommenttiisi on vastattu!' - body = (f'{name.capitalize()} on vastannut kaehmyhakemukseesi tai kommenttiisi kaehmypalvelussa.\r\n\r\n' - 'Käy lukemassa viesti osoitteessa https://{URL}/kaehmy') + to_email = comment.parent.email + subject = "Kaehmyysi tai kommenttiisi on vastattu!" + email_body = ( + f"{name.capitalize()} on vastannut kaehmyhakemukseesi tai kommenttiisi kaehmypalvelussa.\r\n\r\n" + "Käy lukemassa viesti osoitteessa https://{URL}/kaehmy" + ) + send_email(to=to_email, subject=subject, body=email_body) + logging.debug(f"Sent kaehmy comment email to recipient <{to_email}>") - send_email(email, subject, body) - logging.debug( - f'Sent kaehmy comment email to recipient <{email}>') - - return redirect('/kaehmy') + return redirect("/kaehmy") else: - context = { - 'error': form.errors - } - return render(request, 'kaehmy:error.html', context) + context = {"error": form.errors} + return render(request, "kaehmy:error.html", context) @require_http_methods(["GET"]) @@ -87,24 +95,24 @@ def statistics_view(request, *args, **kwargs): for preset in preset_roles: people = [form.name for form in preset.forms.all()] - role_list.append((preset.name, len(people), ', '.join(people))) + role_list.append((preset.name, len(people), ", ".join(people))) for custom in custom_roles: people = [form.name for form in custom.forms.all()] - role_list.append((custom.name, len(people), ', '.join(people))) + role_list.append((custom.name, len(people), ", ".join(people))) context = { - 'applications': applications, - 'application_count': len(applications), - 'role_list': role_list + "applications": applications, + "application_count": len(applications), + "role_list": role_list, } - return render(request, 'kaehmy:statistics.html', context) + return render(request, "kaehmy:statistics.html", context) @require_http_methods(["GET"]) def view(request, *args, **kwargs): """Render Kaehmy form page.""" form = ApplicationForm() - return render(request, 'kaehmy:kaehmy.html', {'form': form}) + return render(request, "kaehmy:kaehmy.html", {"form": form}) @ensure_csrf_cookie @@ -114,56 +122,59 @@ def submit(request, *args, **kwargs): form = ApplicationForm(request.POST) if form.is_valid(): application = form.save() - custom_name = form.cleaned_data.get('custom_role_name') - custom_is_board = form.cleaned_data.get('custom_role_is_board') + custom_name = form.cleaned_data.get("custom_role_name") + custom_is_board = form.cleaned_data.get("custom_role_is_board") if len(custom_name) > 0: - custom_role = CustomRole( - name=custom_name, is_board=custom_is_board) + custom_role = CustomRole(name=custom_name, is_board=custom_is_board) custom_role.save() application.custom_roles.add(custom_role) - url = f'https://{URL}/kaehmy' + url = f"https://{URL}/kaehmy" + name = form.cleaned_data.get("name", "Anonymous") + email_body = ( + f"Moikka {name}!\r\n\r\nHienoa, että kilta kiinnostaa! Kaehmysi on vastaanotettu.\r\n" + "Mahdollisista kommenteista tulee ilmoitus sähköpostitse.\r\n\r\n" + "Käy katsomassa kaehmytilanne osoitteessa {url}" + ) - email = form.cleaned_data.get('email', '') - name = form.cleaned_data.get('name', 'Anonymous') - subject = 'Arwokas kirjattu kirje mahdolliselle tulewalle kiltahenkilölle' - body = ('Moikka {}!\r\n\r\nHienoa, että kilta kiinnostaa! Kaehmysi on vastaanotettu.\r\n' - 'Mahdollisista kommenteista tulee ilmoitus sähköpostitse.\r\n\r\n' - 'Käy katsomassa kaehmytilanne osoitteessa {}').format(name, url) + to_email = form.cleaned_data.get("email", "") + subject = "Arwokas kirjattu kirje mahdolliselle tulewalle kiltahenkilölle" - send_email(email, subject, body) - logging.debug('Sent kaehmy email to recipient <{}>'.format(email)) + send_email(to_email, subject, email_body) + logging.debug(f"Sent kaehmy email to recipient <{to_email}>") CHAT_IDS = [channel.channel_id for channel in TelegramChannel.objects.all()] for chat_id in CHAT_IDS: - tg_string = 'https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}'.format( - settings.TELEGRAM_BOT_TOKEN, - chat_id, - 'Uusi New kaehmy! {} -> {}'.format(name, url) + tg_string = ( + "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}".format( + settings.TELEGRAM_BOT_TOKEN, + chat_id, + "Uusi New kaehmy! {} -> {}".format(name, url), + ) ) response = requests.get(tg_string).json() - logging.debug('Telegram API response:\n{}'.format(response)) - logging.debug('Sent kaehmy announcement to {} channels.'.format(len(CHAT_IDS))) + logging.debug("Telegram API response:\n{}".format(response)) + logging.debug("Sent kaehmy announcement to {} channels.".format(len(CHAT_IDS))) else: - context = { - 'error': form.errors - } - return render(request, 'kaehmy:error.html', context) - return HttpResponseRedirect('/kaehmy') + context = {"error": form.errors} + return render(request, "kaehmy:error.html", context) + return HttpResponseRedirect("/kaehmy") -@require_http_methods(['GET']) -@login_required(login_url='/admin/login') +@require_http_methods(["GET"]) +@login_required(login_url="/admin/login") def export_view(request, *args, **kwargs): def make_table(queryset): - table = ExportTable(queryset, - request=request, - exclude=['id'], - attrs={'class': 'table table-bordered table-hover'}) + table = ExportTable( + queryset, + request=request, + exclude=["id"], + attrs={"class": "table table-bordered table-hover"}, + ) - table.paginate(page=request.GET.get('page', 1), per_page=9999) + table.paginate(page=request.GET.get("page", 1), per_page=9999) table_html = convert_table_to_html(table, request) return table_html @@ -172,7 +183,7 @@ def export_view(request, *args, **kwargs): board = filter(lambda q: q.has_any_board_role(), kaehmys) context = { - 'non_board_table': make_table(non_board), - 'board_table': make_table(board), + "non_board_table": make_table(non_board), + "board_table": make_table(board), } - return render(request, 'kaehmy:export.html', context) + return render(request, "kaehmy:export.html", context) diff --git a/locale/en/LC_MESSAGES/django.mo b/locale/en/LC_MESSAGES/django.mo index 6ccda0d..d71fa82 100644 Binary files a/locale/en/LC_MESSAGES/django.mo and b/locale/en/LC_MESSAGES/django.mo differ diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index 7b1289e..a35757c 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-01-18 21:36+0200\n" +"POT-Creation-Date: 2022-01-13 21:51+0200\n" "PO-Revision-Date: 2017-11-02 23:09+0200\n" "Last-Translator: \n" "Language-Team: \n" @@ -112,7 +112,7 @@ msgstr "Preview" msgid "Delete" msgstr "Delete" -#: infoscreen/templates/tabs/add_remove.html:23 kaehmy/models.py:62 +#: infoscreen/templates/tabs/add_remove.html:23 kaehmy/models.py:57 #: kaehmy/templates/list.html:36 webapp/models.py:144 webapp/models.py:173 msgid "Name" msgstr "Name" @@ -189,7 +189,7 @@ msgstr "Phone number (not public)" msgid "Custom roles" msgstr "Custom roles" -#: kaehmy/forms.py:49 kaehmy/templates/kaehmy.html:43 +#: kaehmy/forms.py:49 kaehmy/templates/kaehmy.html:42 msgid "Preset roles" msgstr "Preset roles" @@ -201,153 +201,153 @@ msgstr "Invalid phone number" msgid "Custom role with the same name already exists." msgstr "Custom role with the same name already exists." -#: kaehmy/models.py:18 +#: kaehmy/models.py:13 msgid "Kaehmy" msgstr "Kaehmy" -#: kaehmy/models.py:25 +#: kaehmy/models.py:20 msgid "Corporate affairs" msgstr "Corporate affairs" -#: kaehmy/models.py:26 webapp/templates/freshmen.html:10 +#: kaehmy/models.py:21 webapp/templates/freshmen.html:10 #: webapp/templates/navigation.html:8 msgid "Freshmen" msgstr "Freshmen" -#: kaehmy/models.py:27 webapp/templates/international.html:10 +#: kaehmy/models.py:22 webapp/templates/international.html:10 #: webapp/templates/navigation.html:14 msgid "International" msgstr "International" -#: kaehmy/models.py:28 +#: kaehmy/models.py:23 msgid "External affairs" msgstr "External affairs" -#: kaehmy/models.py:29 +#: kaehmy/models.py:24 msgid "Media" msgstr "" -#: kaehmy/models.py:30 +#: kaehmy/models.py:25 msgid "Technology" msgstr "" -#: kaehmy/models.py:31 +#: kaehmy/models.py:26 msgid "Wellbeing" msgstr "" -#: kaehmy/models.py:32 +#: kaehmy/models.py:27 msgid "Elepaja" msgstr "" -#: kaehmy/models.py:33 +#: kaehmy/models.py:28 msgid "Ceremonies" msgstr "" -#: kaehmy/models.py:34 +#: kaehmy/models.py:29 msgid "Studies" msgstr "" -#: kaehmy/models.py:35 +#: kaehmy/models.py:30 msgid "Sössö magazine" msgstr "Sössö magazine" -#: kaehmy/models.py:36 +#: kaehmy/models.py:31 msgid "Alumni relations" msgstr "Alumni relations" -#: kaehmy/models.py:37 +#: kaehmy/models.py:32 msgid "Others" msgstr "" -#: kaehmy/models.py:39 +#: kaehmy/models.py:34 msgid "Category" msgstr "" -#: kaehmy/models.py:45 +#: kaehmy/models.py:40 msgid "Description" msgstr "Description" -#: kaehmy/models.py:48 +#: kaehmy/models.py:43 msgid "Preset kaehmy role" msgstr "Preset kaehmy role" -#: kaehmy/models.py:49 +#: kaehmy/models.py:44 msgid "Preset kaehmy roles" msgstr "Preset kaehmy roles" -#: kaehmy/models.py:56 +#: kaehmy/models.py:51 msgid "Custom kaehmy role" msgstr "Custom kaehmy role" -#: kaehmy/models.py:57 +#: kaehmy/models.py:52 msgid "Custom kaehmy roles" msgstr "Custom kaehmy roles" -#: kaehmy/models.py:63 kaehmy/templates/list.html:40 members/models.py:14 +#: kaehmy/models.py:58 kaehmy/templates/list.html:40 members/models.py:14 msgid "Email" msgstr "Email" -#: kaehmy/models.py:64 +#: kaehmy/models.py:59 msgid "Timestamp" msgstr "" -#: kaehmy/models.py:78 +#: kaehmy/models.py:73 msgid "Kaehmykommentti" msgstr "Kaehmy comment" -#: kaehmy/models.py:79 +#: kaehmy/models.py:74 msgid "Kaehmykommentit" msgstr "Kaehmy comments" -#: kaehmy/models.py:81 ohlhafv/models.py:36 +#: kaehmy/models.py:76 ohlhafv/models.py:36 msgid "Message" msgstr "" -#: kaehmy/models.py:100 kaehmy/templates/kaehmy.html:12 +#: kaehmy/models.py:95 kaehmy/templates/kaehmy.html:12 msgid "Kaehmylomake" msgstr "Kaehmy application" -#: kaehmy/models.py:101 +#: kaehmy/models.py:96 msgid "Kaehmylomakkeet" msgstr "Kaehmy applications" -#: kaehmy/models.py:104 +#: kaehmy/models.py:99 msgid "Phone number" msgstr "" -#: kaehmy/models.py:105 +#: kaehmy/models.py:100 msgid "Year" msgstr "" -#: kaehmy/models.py:106 +#: kaehmy/models.py:101 msgid "Text" msgstr "" -#: kaehmy/models.py:108 +#: kaehmy/models.py:103 msgid "Custom role name" msgstr "" -#: kaehmy/models.py:110 webapp/models.py:174 +#: kaehmy/models.py:105 webapp/models.py:174 msgid "Board member" msgstr "Board member" -#: kaehmy/models.py:118 +#: kaehmy/models.py:113 msgid "Kaehmy application: {}" msgstr "Kaehmy application: {}" -#: kaehmy/models.py:140 +#: kaehmy/models.py:135 msgid "Board: {}" msgstr "" -#: kaehmy/models.py:146 +#: kaehmy/models.py:141 msgid "Official: {}" msgstr "" -#: kaehmy/models.py:163 +#: kaehmy/models.py:158 msgid "Telegram channel" msgstr "" -#: kaehmy/models.py:164 +#: kaehmy/models.py:159 msgid "Telegram channels" msgstr "" @@ -427,31 +427,27 @@ msgid "Päivämääriä & deadlineja" msgstr "Dates and deadlines" #: kaehmy/templates/kaehmy.html:31 -msgid "Hallitustyrkkypaneeli" -msgstr "Panel for board applicants" +msgid "Vaalikokous, osa 1 (puheenjohtajan valinta) ja hallitustyrkkypaneeli" +msgstr "Election meeting, part 1 (chairman election)" #: kaehmy/templates/kaehmy.html:32 -msgid "Vaalikokous, osa 1 (puheenjohtajan valinta)" -msgstr "Election meeting, part 1 (chairman election)" +msgid "Vaalikokous, osa 2 (hallituksen valinta)" +msgstr "Election meeting, part 2 (board election)" #: kaehmy/templates/kaehmy.html:33 msgid "Toimikunta-appro" msgstr "Guild committee crawl" #: kaehmy/templates/kaehmy.html:34 -msgid "Vaalikokous, osa 2 (hallituksen valinta)" -msgstr "Election meeting, part 2 (board election)" - -#: kaehmy/templates/kaehmy.html:35 msgid "Vaalikokous, osa 3 (toimarien valinta)" msgstr "Election meeting, part 3 (non-board election)" -#: kaehmy/templates/kaehmy.html:78 +#: kaehmy/templates/kaehmy.html:77 #, python-format msgid "" "\n" -" Hyväksyn tietosuojaselosteen ja tietojeni " "tallentamisen.\n" " " @@ -463,7 +459,7 @@ msgstr "" "of personal data.\n" " " -#: kaehmy/templates/kaehmy.html:84 members/templates/settings.html:23 +#: kaehmy/templates/kaehmy.html:83 members/templates/settings.html:23 msgid "Submit" msgstr "Submit" @@ -640,11 +636,11 @@ msgstr "Amazing! Your membership application has been sent." #: members/templates/application_success.html:9 msgid "" -"Vahvistusviesti on lähetetty sähköpostiisi. Ota yhteyttä admin@sahkoinsinoorikilta.fi." -"fi jos viestiä ei näy." +"Vahvistusviesti on lähetetty sähköpostiisi. Ota yhteyttä " +"admin@sahkoinsinoorikilta.fi jos viestiä ei näy." msgstr "" -"Confirmation email is sent to given email address. Contact admin@sahkoinsinoorikilta.fi." -"fi if you didn't receive it." +"Confirmation email is sent to given email address. Contact " +"admin@sahkoinsinoorikilta.fi.fi if you didn't receive it." #: members/templates/application_success.html:10 msgid "Takaisin Sähköinsinöörikillan web-sivuille" @@ -914,11 +910,11 @@ msgstr "Payments in register:" msgid "Language" msgstr "Language" -#: members/templates/settings.html:20 sikweb/base.py:217 +#: members/templates/settings.html:20 sikweb/base.py:216 msgid "Finnish" msgstr "Finnish" -#: members/templates/settings.html:21 sikweb/base.py:218 +#: members/templates/settings.html:21 sikweb/base.py:217 msgid "English" msgstr "English" @@ -1099,9 +1095,9 @@ msgstr "" msgid "Challenge" msgstr "Challenge" -#: ohlhafv/views.py:44 +#: ohlhafv/views.py:45 msgid "Sinut on haastettu Øhlhäfviin!" -msgstr "You have been challenged at Ohlhafv!" +msgstr "You have been challenged to Øhlhäfv!" #: templates/admin/base_site.html:44 msgid "Go" @@ -1153,11 +1149,11 @@ msgstr "" msgid "{}Event: {}" msgstr "" -#: webapp/models.py:91 +#: webapp/models.py:90 msgid "Template question" msgstr "" -#: webapp/models.py:92 +#: webapp/models.py:91 msgid "Template questions" msgstr "" diff --git a/locale/fi/LC_MESSAGES/django.mo b/locale/fi/LC_MESSAGES/django.mo index 219335d..8b2d5e6 100644 Binary files a/locale/fi/LC_MESSAGES/django.mo and b/locale/fi/LC_MESSAGES/django.mo differ diff --git a/locale/fi/LC_MESSAGES/django.po b/locale/fi/LC_MESSAGES/django.po index cf602f6..e9cfe14 100644 --- a/locale/fi/LC_MESSAGES/django.po +++ b/locale/fi/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-01-18 21:36+0200\n" +"POT-Creation-Date: 2022-01-13 21:51+0200\n" "PO-Revision-Date: 2017-11-02 23:04+0200\n" "Last-Translator: \n" "Language-Team: \n" @@ -113,7 +113,7 @@ msgstr "Esikatsele" msgid "Delete" msgstr "Poista" -#: infoscreen/templates/tabs/add_remove.html:23 kaehmy/models.py:62 +#: infoscreen/templates/tabs/add_remove.html:23 kaehmy/models.py:57 #: kaehmy/templates/list.html:36 webapp/models.py:144 webapp/models.py:173 msgid "Name" msgstr "Nimi" @@ -190,7 +190,7 @@ msgstr "Puhelinnumero (ei julkinen)" msgid "Custom roles" msgstr "Uudet virat" -#: kaehmy/forms.py:49 kaehmy/templates/kaehmy.html:43 +#: kaehmy/forms.py:49 kaehmy/templates/kaehmy.html:42 msgid "Preset roles" msgstr "Kaehmyvirat" @@ -202,153 +202,153 @@ msgstr "Virheellinen puhelinnumero" msgid "Custom role with the same name already exists." msgstr "Samanniminen virka on jo olemassa." -#: kaehmy/models.py:18 +#: kaehmy/models.py:13 msgid "Kaehmy" msgstr "Kaehmy" -#: kaehmy/models.py:25 +#: kaehmy/models.py:20 msgid "Corporate affairs" msgstr "Yrityssuhteet" -#: kaehmy/models.py:26 webapp/templates/freshmen.html:10 +#: kaehmy/models.py:21 webapp/templates/freshmen.html:10 #: webapp/templates/navigation.html:8 msgid "Freshmen" msgstr "Fuksit" -#: kaehmy/models.py:27 webapp/templates/international.html:10 +#: kaehmy/models.py:22 webapp/templates/international.html:10 #: webapp/templates/navigation.html:14 msgid "International" msgstr "International" -#: kaehmy/models.py:28 +#: kaehmy/models.py:23 msgid "External affairs" msgstr "Ulkosuhteet" -#: kaehmy/models.py:29 +#: kaehmy/models.py:24 msgid "Media" msgstr "Media" -#: kaehmy/models.py:30 +#: kaehmy/models.py:25 msgid "Technology" msgstr "Teknologia" -#: kaehmy/models.py:31 +#: kaehmy/models.py:26 msgid "Wellbeing" msgstr "Hyvinvointi" -#: kaehmy/models.py:32 +#: kaehmy/models.py:27 msgid "Elepaja" msgstr "Elepaja" -#: kaehmy/models.py:33 +#: kaehmy/models.py:28 msgid "Ceremonies" msgstr "Hupitapahtumat" -#: kaehmy/models.py:34 +#: kaehmy/models.py:29 msgid "Studies" msgstr "Opinnot" -#: kaehmy/models.py:35 +#: kaehmy/models.py:30 msgid "Sössö magazine" msgstr "Kiltalehti Sössö" -#: kaehmy/models.py:36 +#: kaehmy/models.py:31 msgid "Alumni relations" msgstr "Alumnisuhteet" -#: kaehmy/models.py:37 +#: kaehmy/models.py:32 msgid "Others" msgstr "Muut" -#: kaehmy/models.py:39 +#: kaehmy/models.py:34 msgid "Category" msgstr "Kategoria" -#: kaehmy/models.py:45 +#: kaehmy/models.py:40 msgid "Description" msgstr "Kuvaus" -#: kaehmy/models.py:48 +#: kaehmy/models.py:43 msgid "Preset kaehmy role" msgstr "Kaehmyvirka" -#: kaehmy/models.py:49 +#: kaehmy/models.py:44 msgid "Preset kaehmy roles" msgstr "Kaehmyvirat" -#: kaehmy/models.py:56 +#: kaehmy/models.py:51 msgid "Custom kaehmy role" msgstr "Uusi virka" -#: kaehmy/models.py:57 +#: kaehmy/models.py:52 msgid "Custom kaehmy roles" msgstr "Uudet kaehmyvirat" -#: kaehmy/models.py:63 kaehmy/templates/list.html:40 members/models.py:14 +#: kaehmy/models.py:58 kaehmy/templates/list.html:40 members/models.py:14 msgid "Email" msgstr "Sähköposti" -#: kaehmy/models.py:64 +#: kaehmy/models.py:59 msgid "Timestamp" msgstr "Aikaleima" -#: kaehmy/models.py:78 +#: kaehmy/models.py:73 msgid "Kaehmykommentti" msgstr "Kaehmykommentti" -#: kaehmy/models.py:79 +#: kaehmy/models.py:74 msgid "Kaehmykommentit" msgstr "Kaehmykommentit" -#: kaehmy/models.py:81 ohlhafv/models.py:36 +#: kaehmy/models.py:76 ohlhafv/models.py:36 msgid "Message" msgstr "Viesti" -#: kaehmy/models.py:100 kaehmy/templates/kaehmy.html:12 +#: kaehmy/models.py:95 kaehmy/templates/kaehmy.html:12 msgid "Kaehmylomake" msgstr "Kaehmylomake" -#: kaehmy/models.py:101 +#: kaehmy/models.py:96 msgid "Kaehmylomakkeet" msgstr "Kaehmylomakkeet" -#: kaehmy/models.py:104 +#: kaehmy/models.py:99 msgid "Phone number" msgstr "Puhelinnumero" -#: kaehmy/models.py:105 +#: kaehmy/models.py:100 msgid "Year" msgstr "Vuosi" -#: kaehmy/models.py:106 +#: kaehmy/models.py:101 msgid "Text" msgstr "Teksti" -#: kaehmy/models.py:108 +#: kaehmy/models.py:103 msgid "Custom role name" msgstr "Uusi virka" -#: kaehmy/models.py:110 webapp/models.py:174 +#: kaehmy/models.py:105 webapp/models.py:174 msgid "Board member" msgstr "Hallituksen jäsen" -#: kaehmy/models.py:118 +#: kaehmy/models.py:113 msgid "Kaehmy application: {}" msgstr "Kaehmy: {}" -#: kaehmy/models.py:140 +#: kaehmy/models.py:135 msgid "Board: {}" msgstr "Hallitus: {}" -#: kaehmy/models.py:146 +#: kaehmy/models.py:141 msgid "Official: {}" msgstr "Toimari: {}" -#: kaehmy/models.py:163 +#: kaehmy/models.py:158 msgid "Telegram channel" msgstr "Telegram-kanava" -#: kaehmy/models.py:164 +#: kaehmy/models.py:159 msgid "Telegram channels" msgstr "Telegram-kanavat" @@ -404,8 +404,8 @@ msgstr "" " Koska lista ei ole koskaan täydellinen, voit myös ehdottaa ihan " "uutta toimenkuvaa.\n" " Jos sinulla on kysyttävää mistä tahansa virasta, kannattaa " -"konsultoida kaehmyopasta \n" +"konsultoida kaehmyopasta \n" " tai olla yhteydessä kyseistä virkaa tänä vuonna toimittavaan " "henkilöön." @@ -430,37 +430,33 @@ msgid "Päivämääriä & deadlineja" msgstr "Päivämääriä & deadlineja" #: kaehmy/templates/kaehmy.html:31 -msgid "Hallitustyrkkypaneeli" -msgstr "" +msgid "Vaalikokous, osa 1 (puheenjohtajan valinta) ja hallitustyrkkypaneeli" +msgstr "Vaalikokous, osa 1 (puheenjohtajan valinta) ja hallitustyrkkypaneeli" #: kaehmy/templates/kaehmy.html:32 -msgid "Vaalikokous, osa 1 (puheenjohtajan valinta)" -msgstr "Vaalikokous, osa 1 (puheenjohtajan valinta)" +msgid "Vaalikokous, osa 2 (hallituksen valinta)" +msgstr "Vaalikokous, osa 2 (hallituksen valinta)" #: kaehmy/templates/kaehmy.html:33 msgid "Toimikunta-appro" msgstr "" #: kaehmy/templates/kaehmy.html:34 -msgid "Vaalikokous, osa 2 (hallituksen valinta)" -msgstr "Vaalikokous, osa 2 (hallituksen valinta)" - -#: kaehmy/templates/kaehmy.html:35 msgid "Vaalikokous, osa 3 (toimarien valinta)" msgstr "Vaalikokous, osa 3 (toimarien valinta)" -#: kaehmy/templates/kaehmy.html:78 +#: kaehmy/templates/kaehmy.html:77 #, python-format msgid "" "\n" -" Hyväksyn tietosuojaselosteen ja tietojeni " +" Hyväksyn tietosuojaselosteen ja tietojeni " "tallentamisen.\n" " " msgstr "" -#: kaehmy/templates/kaehmy.html:84 members/templates/settings.html:23 +#: kaehmy/templates/kaehmy.html:83 members/templates/settings.html:23 msgid "Submit" msgstr "Lisää" @@ -637,8 +633,8 @@ msgstr "Hienoa! Jäsenhakemuksesi on nyt lähetetty." #: members/templates/application_success.html:9 msgid "" -"Vahvistusviesti on lähetetty sähköpostiisi. Ota yhteyttä admin@sahkoinsinoorikilta.fi." -"fi jos viestiä ei näy." +"Vahvistusviesti on lähetetty sähköpostiisi. Ota yhteyttä " +"admin@sahkoinsinoorikilta.fi jos viestiä ei näy." msgstr "" #: members/templates/application_success.html:10 @@ -905,11 +901,11 @@ msgstr "Maksutapahtumia:" msgid "Language" msgstr "Kieli" -#: members/templates/settings.html:20 sikweb/base.py:217 +#: members/templates/settings.html:20 sikweb/base.py:216 msgid "Finnish" msgstr "suomi" -#: members/templates/settings.html:21 sikweb/base.py:218 +#: members/templates/settings.html:21 sikweb/base.py:217 msgid "English" msgstr "englanti" @@ -1088,7 +1084,7 @@ msgstr "Haasta kaverisi mittelöön!" msgid "Challenge" msgstr "Haasta" -#: ohlhafv/views.py:44 +#: ohlhafv/views.py:45 msgid "Sinut on haastettu Øhlhäfviin!" msgstr "" @@ -1142,11 +1138,11 @@ msgstr "Tapahtuma" msgid "{}Event: {}" msgstr "{}Tapahtuma: {}" -#: webapp/models.py:91 +#: webapp/models.py:90 msgid "Template question" msgstr "Vakiokysymys" -#: webapp/models.py:92 +#: webapp/models.py:91 msgid "Template questions" msgstr "Vakiokysymykset" diff --git a/ohlhafv/views.py b/ohlhafv/views.py index 76067e0..596c5ac 100644 --- a/ohlhafv/views.py +++ b/ohlhafv/views.py @@ -1,33 +1,26 @@ """Ohlhafv views.""" -from django.db.models import Count -from django.shortcuts import render, redirect -from django.contrib.auth import login, logout, authenticate +import logging +from django.shortcuts import render from django.views.decorators.http import require_http_methods from django.views.decorators.csrf import ensure_csrf_cookie -from django.http import HttpResponse, HttpResponseRedirect -from django.contrib.auth.decorators import permission_required, login_required -from django.conf import settings +from django.http import HttpResponseRedirect from django.utils.translation import ugettext_lazy as _ from django.template.loader import render_to_string -import logging -import requests -from dealer.git import git -from sikweb.settings import URL from ohlhafv.models import OhlhafvChallenge from ohlhafv.forms import OhlhafvForm -from ohlhafv.tables import OhlhafvTable -from webapp.utils import send_email from kaehmy.tgbot import TelegramBot +from webapp.utils import send_email +from sikweb.settings import URL @require_http_methods(["GET"]) def ohlhafv_view(request, *args, **kwargs): """Render Ohlhafv form page.""" form = OhlhafvForm() - return render(request, 'ohlhafv:new.html', {'form': form}) + return render(request, "ohlhafv:new.html", {"form": form}) @ensure_csrf_cookie @@ -38,34 +31,33 @@ def ohlhafv_submit(request, *args, **kwargs): if form.is_valid(): form.save() challenge = form.instance - email = form.cleaned_data.get('victim_email', '') + url = f"https://{URL}/ohlhafv/list" - url = f'https://{URL}/ohlhafv/list' - subject = _('Sinut on haastettu Ohlhäfviin!') - - message = render_to_string( - 'ohlhafv:email.html', { - 'challenge': challenge, - 'url': url, - } + email_body = render_to_string( + "ohlhafv:email.html", + { + "challenge": challenge, + "url": url, + }, ) - send_email(email, subject, message) + + to_email = form.cleaned_data.get("victim_email", "") + subject = _("Sinut on haastettu Øhlhäfviin!") + send_email(to=to_email, subject=subject, body=email_body) + logging.debug(f"Sent ohlhafv email to recipient <{to_email}>") try: tg_message = render_to_string( - 'ohlhafv:tgmsg.tpl', { - 'challenge': challenge, - 'url': url}) + "ohlhafv:tgmsg.tpl", {"challenge": challenge, "url": url} + ) bot = TelegramBot() bot.broadcast(tg_message) - except Exception: # tg spam is not critical. Ignore on failure + except Exception: # tg spam is not critical. Ignore on failure pass - logging.debug( - 'Sent ohlhafv email to recipient <{}>'.format(email)) else: pass - return HttpResponseRedirect('/ohlhafv/list/') + return HttpResponseRedirect("/ohlhafv/list/") @ensure_csrf_cookie @@ -73,9 +65,9 @@ def ohlhafv_submit(request, *args, **kwargs): def ohlhafv_list(request, *args, **kwargs): """Present Ohlhafv challenges list.""" challenges = OhlhafvChallenge.objects.all() - challenges = challenges.order_by('-id') + challenges = challenges.order_by("-id") context = { - 'challenges': challenges, - 'challenge_count': len(challenges), + "challenges": challenges, + "challenge_count": len(challenges), } - return render(request, 'ohlhafv:list.html', context) + return render(request, "ohlhafv:list.html", context) diff --git a/webapp/utils.py b/webapp/utils.py index c311eba..c1f6dff 100644 --- a/webapp/utils.py +++ b/webapp/utils.py @@ -1,18 +1,30 @@ """Webapp utils.""" -from django.utils import timezone -import sendgrid -from sendgrid.helpers.mail import * - -from datetime import timedelta import logging -from django.template.loader import render_to_string -from django.core.files.base import ContentFile import base64 import uuid -from sikweb.settings import FRONTEND_URL, EMAIL_API_KEY, DEFAULT_EMAIL_FROM_ADDR, ENABLE_AUTOMATIC_EMAILS import imghdr import markdown +import sendgrid +from django.utils import timezone +from sendgrid.helpers.mail import ( + Email, + To, + Subject, + Mail, + HtmlContent, + PlainTextContent, +) +from django.template.loader import render_to_string +from django.core.files.base import ContentFile +from sikweb.settings import ( + FRONTEND_URL, + EMAIL_API_KEY, + DEFAULT_EMAIL_FROM, + DEFAULT_EMAIL_FROM_ADDR, + ENABLE_AUTOMATIC_EMAILS, +) +from datetime import timedelta def get_file_extension(file_name, decoded_file): @@ -25,15 +37,15 @@ def decode_base64_file(data): # Check if this is a base64 string if isinstance(data, str): # Check if the base64 string is in the "data:" format - if 'data:' in data and ';base64,' in data: + if "data:" in data and ";base64," in data: # Break out the header from the base64 content - header, data = data.split(';base64,') + header, data = data.split(";base64,") # Try to decode the file. Return validation error if it fails. try: decoded_file = base64.b64decode(data) except TypeError: - TypeError('invalid_image') + TypeError("invalid_image") # Generate file name: file_name = str(uuid.uuid4()) @@ -41,7 +53,10 @@ def decode_base64_file(data): # Get the file name extension: file_extension = get_file_extension(file_name, decoded_file) - complete_file_name = "%s.%s" % (file_name, file_extension, ) + complete_file_name = "%s.%s" % ( + file_name, + file_extension, + ) return ContentFile(decoded_file, name=complete_file_name) @@ -51,50 +66,51 @@ def month_from_now(): return timezone.now() + timedelta(days=30) -def send_email(to, subject, body, html=False): - if not ENABLE_AUTOMATIC_EMAILS: +def send_email(to: str, subject: str, body: str, html: bool = False): + if ENABLE_AUTOMATIC_EMAILS is False: logging.debug("Skipping email") logging.debug(f"to: {to}") logging.debug(f"subject: {subject}") logging.debug(f"body: {body}") return - from_email = DEFAULT_EMAIL_FROM_ADDR - to_email = to - sub = subject + from_email = Email(email=DEFAULT_EMAIL_FROM_ADDR, name=DEFAULT_EMAIL_FROM) + to_email = To(email=to) + sub = Subject(subject=subject) html_content = None plain_text_content = None - if (html): - html_content = HtmlContent(body) + if html: + html_content = HtmlContent(content=body) else: - plain_text_content = PlainTextContent(body) + plain_text_content = PlainTextContent(content=body) mail = Mail( from_email=from_email, to_emails=to_email, subject=sub, html_content=html_content, - plain_text_content=plain_text_content + plain_text_content=plain_text_content, ) try: - sg = sendgrid.SendGridAPIClient(EMAIL_API_KEY) + sg = sendgrid.SendGridAPIClient(api_key=EMAIL_API_KEY) response = sg.send(mail) if response.status_code != 202: - raise Exception(f'Failed to send email: {response.body}') + raise Exception(f"Failed to send email: {response.body}") except Exception as ex: - logging.exception('Failed to send email.') + logging.exception("Failed to send email.") def send_signup_email(to, subject, id, uuid, content): message = render_to_string( - 'webapp:signup_email.html', { - 'url': f"https://{FRONTEND_URL}/signup/edit/{id}/{uuid}", - 'content': markdown.markdown(content), - } + "webapp:signup_email.html", + { + "url": f"https://{FRONTEND_URL}/signup/edit/{id}/{uuid}", + "content": markdown.markdown(content), + }, ) return send_email(to, subject, message, True)