Implement kaehmy export table

This commit is contained in:
Jan Tuomi
2017-10-30 12:47:48 +02:00
parent 84f7d86875
commit b09698e859
12 changed files with 176 additions and 98 deletions
+1
View File
@@ -17,3 +17,4 @@ requirements_henu.txt
/collected_static/
mydatabase
settings.json
.vscode/
Binary file not shown.
+28 -15
View File
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-10-28 14:37+0100\n"
"POT-Creation-Date: 2017-10-30 11:39+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -247,10 +247,6 @@ msgstr "Last paid"
msgid "Edit"
msgstr "Edit"
#: .\members\tables.py:20 .\members\tables.py:39 .\members\tables.py:56
msgid "Options"
msgstr "Options"
#: .\members\templates\application_delete_confirm.html:9
#, fuzzy
#| msgid "Are you sure you want to delete this payment?"
@@ -788,7 +784,7 @@ msgstr "Kaehmy application"
msgid "Kaehmylomakkeet"
msgstr "Kaehmy applications"
#: .\webapp\models.py:185 .\webapp\models.py:258
#: .\webapp\models.py:185 .\webapp\models.py:267
msgid "Phone number"
msgstr ""
@@ -818,38 +814,42 @@ msgstr ""
msgid "Official: {}"
msgstr ""
#: .\webapp\models.py:241
#: .\webapp\models.py:250
msgid "Role"
msgstr ""
#: .\webapp\models.py:242
#: .\webapp\models.py:251 .\webapp\tables.py:16
msgid "Roles"
msgstr ""
#: .\webapp\models.py:244
#: .\webapp\models.py:253
msgid "Start date"
msgstr ""
#: .\webapp\models.py:245
#: .\webapp\models.py:254
msgid "End date"
msgstr ""
#: .\webapp\models.py:255
#: .\webapp\models.py:264
msgid "Official"
msgstr ""
#: .\webapp\models.py:256
#: .\webapp\models.py:265
msgid "Officials"
msgstr ""
#: .\webapp\models.py:284
#: .\webapp\models.py:293
msgid "Telegram channel"
msgstr ""
#: .\webapp\models.py:285
#: .\webapp\models.py:294
msgid "Telegram channels"
msgstr ""
#: .\webapp\tables.py:17
msgid "Applied for board"
msgstr ""
#: .\webapp\templates\admin_index.html:6
msgid "SIK Admin"
msgstr "SIK Admin"
@@ -932,6 +932,16 @@ msgstr "Deadline to apply as a non-board official!"
msgid "Vaalikokous, osa 3 (toimarien valinta)"
msgstr "Election meeting, part 3 (non-board election)"
#: .\webapp\templates\kaehmy_export.html:9
#, fuzzy
#| msgid "Applications"
msgid "All applications"
msgstr "Applications"
#: .\webapp\templates\kaehmy_export.html:14
msgid "Front page"
msgstr ""
#: .\webapp\templates\kaehmy_list.html:24
#: .\webapp\templates\kaehmy_list.html:59
msgid "All kaehmys"
@@ -1027,4 +1037,7 @@ msgstr "All challenges"
#: .\webapp\templates\ohlhafv_list.html:15
msgid "Total challenges:"
msgstr "Total challenges:"
msgstr "Total challenges:"
#~ msgid "Options"
#~ msgstr "Options"
Binary file not shown.
+25 -26
View File
@@ -7,15 +7,15 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-10-28 14:37+0100\n"
"POT-Creation-Date: 2017-10-30 11:39+0100\n"
"PO-Revision-Date: 2017-10-29 11:57+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fi\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Last-Translator: \n"
"Language-Team: \n"
"X-Generator: Poedit 2.0.4\n"
#: .\infoscreen\models.py:97
@@ -248,10 +248,6 @@ msgstr "Viimeksi maksettu"
msgid "Edit"
msgstr "Muokkaa"
#: .\members\tables.py:20 .\members\tables.py:39 .\members\tables.py:56
msgid "Options"
msgstr "Asetukset"
#: .\members\templates\application_delete_confirm.html:9
msgid "Are you sure you want to delete this application?"
msgstr "Oletko varma, että haluat poistaa tämän hakemuksen?"
@@ -771,7 +767,7 @@ msgstr "Kaehmylomake"
msgid "Kaehmylomakkeet"
msgstr "Kaehmylomakkeet"
#: .\webapp\models.py:185 .\webapp\models.py:258
#: .\webapp\models.py:185 .\webapp\models.py:267
msgid "Phone number"
msgstr "Puhelinnumero"
@@ -799,38 +795,42 @@ msgstr "Hallitus: {}"
msgid "Official: {}"
msgstr "Toimari: {}"
#: .\webapp\models.py:241
#: .\webapp\models.py:250
msgid "Role"
msgstr "Rooli"
#: .\webapp\models.py:242
#: .\webapp\models.py:251 .\webapp\tables.py:16
msgid "Roles"
msgstr "Roolit"
#: .\webapp\models.py:244
#: .\webapp\models.py:253
msgid "Start date"
msgstr "Alkupäivämäärä"
#: .\webapp\models.py:245
#: .\webapp\models.py:254
msgid "End date"
msgstr "Loppupäivämäärä"
#: .\webapp\models.py:255
#: .\webapp\models.py:264
msgid "Official"
msgstr "Toimihenkilö"
#: .\webapp\models.py:256
#: .\webapp\models.py:265
msgid "Officials"
msgstr "Toimihenkilöt"
#: .\webapp\models.py:284
#: .\webapp\models.py:293
msgid "Telegram channel"
msgstr "Telegram-kanava"
#: .\webapp\models.py:285
#: .\webapp\models.py:294
msgid "Telegram channels"
msgstr "Telegram-kanavat"
#: .\webapp\tables.py:17
msgid "Applied for board"
msgstr "Hakenut hallitukseen"
#: .\webapp\templates\admin_index.html:6
msgid "SIK Admin"
msgstr "SIK Hallintapaneeli"
@@ -916,6 +916,14 @@ msgstr "Haku toimariksi olisi hyvä tehdä ennen tätä!"
msgid "Vaalikokous, osa 3 (toimarien valinta)"
msgstr "Vaalikokous, osa 3 (toimarien valinta)"
#: .\webapp\templates\kaehmy_export.html:9
msgid "All applications"
msgstr "Kaikki kaehmyt"
#: .\webapp\templates\kaehmy_export.html:14
msgid "Front page"
msgstr "Etusivulle"
#: .\webapp\templates\kaehmy_list.html:24
#: .\webapp\templates\kaehmy_list.html:59
msgid "All kaehmys"
@@ -1009,13 +1017,4 @@ msgstr "Kaikki haasteet"
#: .\webapp\templates\ohlhafv_list.html:15
msgid "Total challenges:"
msgstr "Haasteita yhteensä:"
#~ msgid "Could not accept application object"
#~ msgstr "Hakemusobjektia ei voitu hyväksyä"
#~ msgid "Could not update member object"
#~ msgstr "Jäsenobjektia ei voitu päivittää"
#~ msgid "Summary"
#~ msgstr "Tiivistelmä"
msgstr "Haasteita yhteensä:"
+9
View File
@@ -226,6 +226,15 @@ class KaehmyForm(MessageParent):
combined = presets + customs
return _('Official: {}').format(', '.join(combined)) if len(combined) > 0 else ''
def all_roles(self):
presets = [r.name.capitalize() for r in self.preset_roles.all()]
customs = [r.name.capitalize() for r in self.custom_roles.all()]
combined = presets + customs
return ', '.join(combined) if len(combined) > 0 else ''
def has_any_board_role(self):
return self.preset_roles.filter(is_board=True).exists() or self.custom_roles.filter(is_board=True)
class Role(PresetRole):
"""
+13 -1
View File
@@ -1,8 +1,20 @@
import django_tables2 as tables
from django.utils.translation import ugettext as _
from webapp.models import OhlhafvChallenge
from webapp.models import OhlhafvChallenge, KaehmyForm
class OhlhafvTable(tables.Table):
class Meta:
model = OhlhafvChallenge
class KaehmyExportTable(tables.Table):
class Meta:
model = KaehmyForm
exclude = ['text', 'messageparent_ptr', 'custom_role_name', 'custom_role_is_board']
all_roles = tables.Column(verbose_name=_('Roles'))
has_any_board_role = tables.BooleanColumn(verbose_name=_('Applied for board'))
def __init__(self, *args, **kwargs):
super(KaehmyExportTable, self).__init__(*args, **kwargs)
+7
View File
@@ -1,5 +1,12 @@
{% extends "base.html" %}
{% load static %}
{% load i18n %}
{% block navigation %}
{% include "kaehmy_navigation.html" %}
{% endblock %}
{% block header %}
<div class="kaehmy_header">
{% include "kaehmy_header.html" %}
+1 -1
View File
@@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "kaehmy_base.html" %}
{% load static %}
{% load i18n %}
+17
View File
@@ -0,0 +1,17 @@
{% extends "kaehmy_base.html" %}
{% load static %}
{% load i18n %}
{% block content %}
<div>
<div>
<h2 style="padding-top: 1rem">{% trans "All applications" %}</h2>
</div>
{{ table|safe }}
<div>
<a href="/kaehmy" class="btn btn-primary">{% trans "Front page" %}</a>
</div>
</div>
{% endblock content %}
+2
View File
@@ -23,6 +23,7 @@ from webapp.views import kaehmy_list_view
from webapp.views import kaehmy_submit
from webapp.views import kaehmy_comment
from webapp.views import kaehmy_statistics_view
from webapp.views import kaehmy_export_view
urlpatterns = [
# main
@@ -52,6 +53,7 @@ urlpatterns = [
url(r'^kaehmy/submit', kaehmy_submit),
url(r'^kaehmy/add_comment', kaehmy_comment),
url(r'^kaehmy/statistics', kaehmy_statistics_view),
url(r'^kaehmy/export', kaehmy_export_view),
url(r'^kaehmy', kaehmy_list_view),
# ohlhafv
+73 -55
View File
@@ -16,7 +16,8 @@ from dealer.git import git
from webapp.models import PresetKaehmyRole, CustomKaehmyRole
from webapp.models import OhlhafvChallenge, KaehmyForm, TelegramChannel
from webapp.forms import OhlhafvForm, KaehmyForm_Form, KaehmyCommentForm
from webapp.tables import OhlhafvTable
from webapp.tables import OhlhafvTable, KaehmyExportTable
from members.views.utils import *
from django.core.mail import send_mail
@@ -136,60 +137,6 @@ def contact_view(request, *args, **kwargs):
return render(request, "contact.html", {})
@require_http_methods(["GET"])
def kaehmy_view(request, *args, **kwargs):
"""Render Kaehmy form page."""
form = KaehmyForm_Form()
return render(request, 'kaehmy.html', {'form': form})
@ensure_csrf_cookie
@require_http_methods(["POST"])
def kaehmy_submit(request, *args, **kwargs):
"""Submit Kaehmy form."""
form = KaehmyForm_Form(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')
if len(custom_name) > 0:
custom_role = CustomKaehmyRole(
name=custom_name, is_board=custom_is_board)
custom_role.save()
application.custom_roles.add(custom_role)
url = 'https://sika.sahkoinsinoorikilta.fi/kaehmy'
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)
send_email(email, subject, body)
logging.debug('Sent kaehmy email to recipient <{}>'.format(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 kaehmy/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)))
else:
context = {
'error': form.errors
}
return render(request, 'kaehmy_error.html', context)
return HttpResponseRedirect('/kaehmy')
@require_http_methods(["GET"])
def ohlhafv_view(request, *args, **kwargs):
"""Render Ohlhafv form page."""
@@ -311,3 +258,74 @@ def kaehmy_statistics_view(request, *args, **kwargs):
'role_list': role_list
}
return render(request, 'kaehmy_statistics.html', context)
@require_http_methods(["GET"])
def kaehmy_view(request, *args, **kwargs):
"""Render Kaehmy form page."""
form = KaehmyForm_Form()
return render(request, 'kaehmy.html', {'form': form})
@ensure_csrf_cookie
@require_http_methods(["POST"])
def kaehmy_submit(request, *args, **kwargs):
"""Submit Kaehmy form."""
form = KaehmyForm_Form(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')
if len(custom_name) > 0:
custom_role = CustomKaehmyRole(
name=custom_name, is_board=custom_is_board)
custom_role.save()
application.custom_roles.add(custom_role)
url = 'https://sika.sahkoinsinoorikilta.fi/kaehmy'
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)
send_email(email, subject, body)
logging.debug('Sent kaehmy email to recipient <{}>'.format(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 kaehmy/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)))
else:
context = {
'error': form.errors
}
return render(request, 'kaehmy_error.html', context)
return HttpResponseRedirect('/kaehmy')
@require_http_methods(['GET'])
def kaehmy_export_view(request, *args, **kwargs):
kaehmys = KaehmyForm.objects.all()
table = KaehmyExportTable(kaehmys,
request=request,
exclude=['id'],
attrs={'class': 'table table-bordered table-hover'})
table.paginate(page=request.GET.get('page', 1), per_page=9999)
table_html = convert_table_to_html(table, request)
context = {
'table': table_html,
}
return render(request, 'kaehmy_export.html', context)