Implement kaehmy export table
This commit is contained in:
+73
-55
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user