update send email uses

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