Overall fixes
This commit is contained in:
+14
-5
@@ -7,15 +7,16 @@ 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
|
||||
|
||||
import logging
|
||||
import requests
|
||||
|
||||
from webapp.models import PresetKaehmyRole, CustomKaehmyRole
|
||||
from webapp.models import OhlhafvChallenge, KaehmyForm
|
||||
from webapp.models import OhlhafvChallenge, KaehmyForm, TelegramChannel
|
||||
from webapp.forms import OhlhafvForm, KaehmyForm_Form, KaehmyCommentForm
|
||||
from webapp.tables import OhlhafvTable
|
||||
from webapp.telegram_bot import kaehmy_handler
|
||||
|
||||
from django.core.mail import send_mail
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def send_email(to, subject, body):
|
||||
@@ -159,8 +160,16 @@ def kaehmy_submit(request, *args, **kwargs):
|
||||
send_email(email, subject, body)
|
||||
logging.debug('Sent kaehmy email to recipient <{}>'.format(email))
|
||||
|
||||
kaehmy_handler.announce(url, name)
|
||||
logging.debug('Sent kaehmy announcement to telegram.')
|
||||
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 = {
|
||||
|
||||
Reference in New Issue
Block a user