From b609fd368837188c26a83a128f743a19b87c01e2 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 16 Oct 2017 17:38:39 +0300 Subject: [PATCH] Overall fixes --- coffee_scale/__init__.py | 1 - locale/en/LC_MESSAGES/django.mo | Bin 7141 -> 7141 bytes locale/en/LC_MESSAGES/django.po | 32 +++++---- locale/fi/LC_MESSAGES/django.mo | Bin 11243 -> 11347 bytes locale/fi/LC_MESSAGES/django.po | 44 ++++++------ webapp/admin.py | 3 +- webapp/forms.py | 2 +- webapp/migrations/0031_auto_20171016_1455.py | 20 ++++++ .../migrations/0032_delete_telegrammessage.py | 18 +++++ .../migrations/0033_telegramchannel_name.py | 21 ++++++ webapp/models.py | 27 +++---- webapp/telegram_bot.py | 67 ------------------ webapp/templates/kaehmy_list.html | 8 ++- webapp/views.py | 19 +++-- 14 files changed, 136 insertions(+), 126 deletions(-) create mode 100644 webapp/migrations/0031_auto_20171016_1455.py create mode 100644 webapp/migrations/0032_delete_telegrammessage.py create mode 100644 webapp/migrations/0033_telegramchannel_name.py delete mode 100644 webapp/telegram_bot.py diff --git a/coffee_scale/__init__.py b/coffee_scale/__init__.py index 6ddb4ad..61bc51a 100644 --- a/coffee_scale/__init__.py +++ b/coffee_scale/__init__.py @@ -1,5 +1,4 @@ from . import mqtt import logging -logging.info('Starting mqtt loop') mqtt.client.loop_start() diff --git a/locale/en/LC_MESSAGES/django.mo b/locale/en/LC_MESSAGES/django.mo index 7317b08406262f8865e4c83742c324be129ac244..c8c0421ad767f80ef0f6b216ce76e0fc219cdecd 100644 GIT binary patch delta 17 YcmaEA{?vTK10fbuD`V5mPlOmb0YxDOX#fBK delta 17 YcmaEA{?vTK10fb8DjU;qFB diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index 9070691..366ef4f 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-10-16 12:20+0300\n" +"POT-Creation-Date: 2017-10-16 15:35+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -192,7 +192,7 @@ msgid "English" msgstr "English" #: infoscreen/templates/infoscreen_admin.html:166 -#: members/templates/settings.html:23 webapp/templates/kaehmy.html:19 +#: members/templates/settings.html:23 webapp/templates/kaehmy.html:54 #, fuzzy #| msgid "Submitted" msgid "Submit" @@ -556,17 +556,17 @@ msgstr "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" msgid "Custom roles" msgstr "Total challenges:" -#: webapp/forms.py:30 webapp/forms.py:33 +#: webapp/forms.py:35 webapp/templates/kaehmy.html:30 #, fuzzy #| msgid "Total challenges:" msgid "Preset roles" msgstr "Total challenges:" -#: webapp/forms.py:41 +#: webapp/forms.py:57 msgid "Invalid phone number" msgstr "" -#: webapp/forms.py:49 +#: webapp/forms.py:65 msgid "Custom role with the same name already exists." msgstr "" @@ -750,7 +750,7 @@ msgstr "" msgid "Timestamp" msgstr "" -#: webapp/models.py:178 webapp/models.py:242 +#: webapp/models.py:178 webapp/models.py:249 msgid "Phone number" msgstr "" @@ -772,19 +772,27 @@ msgstr "" msgid "Kaehmy application: {}" msgstr "Member applications" -#: webapp/models.py:227 +#: webapp/models.py:214 +msgid "Board: {}" +msgstr "" + +#: webapp/models.py:220 +msgid "Official: {}" +msgstr "" + +#: webapp/models.py:234 msgid "Role" msgstr "" -#: webapp/models.py:229 +#: webapp/models.py:236 msgid "Start date" msgstr "" -#: webapp/models.py:230 +#: webapp/models.py:237 msgid "End date" msgstr "" -#: webapp/models.py:240 +#: webapp/models.py:247 msgid "Official" msgstr "" @@ -835,11 +843,11 @@ msgstr "" msgid "Comment" msgstr "" -#: webapp/templates/kaehmy_list.html:69 +#: webapp/templates/kaehmy_list.html:73 msgid "Show comments" msgstr "" -#: webapp/templates/kaehmy_list.html:75 +#: webapp/templates/kaehmy_list.html:79 #, fuzzy #| msgid "Add payment" msgid "Add comment" diff --git a/locale/fi/LC_MESSAGES/django.mo b/locale/fi/LC_MESSAGES/django.mo index bae8927ce573a7896898a714e3d376ba0ae543f6..46d2998fde2851710e794df475ef50ca27267252 100644 GIT binary patch delta 4405 zcmZA4d2m(L0mtzJ+04QsAPKUCHAujsgrzhrBKx8s0gP2J1tNg}1%yHoo`5J|q^Ly{ z<3e#kutJ4`(o(qEE>KaYNiY1HdA385G>kS@Y4 zXnSAG#Zsh;FamS192p`JrpFWJVLK zH~<^q?dW;qF&n4E_L-Q@_+fE8VHvuzwdf3=L@%htEPM@{<6GDokHz*n>_z<|dVafR zA+RZ-7&~D9Xa%;Rz6RUkE7lo59E}Zi*n)c64XFvVMt7tOx{|)=M21E0Ko%V)A!COs zbcdGX&A0(w`9X9?PDVdO`#FON@713;@E+Bn7krNH#5d@L87$k5bI|izqURN%9hG1P zmZH}Uj_spk`-EsYdP}FGJ2kgC`|kvn(BJ@xc*4e5e+dg{-;GY>1UkSebihy037kW3 z*Mvo}Zu3{{VP_gHqAP2{*~u-!mekv$D;a>y zIZQ-XG6$XTVzlGc(Z|t=JdK{W1-%8^qHm|#6X6I4Zuv>HqfgPN`XAA7V`?Q$G5OG; z1C_*jDY_FQ(Ve;n-HDm#Lgu0qScq=N3>py?m*Az5cFZ37=JHEccKEFXl1O=$HW907IWYXPofXu8T4NL6}|8a zbO*jh2TtSj=lMD4@6FJiX@SXGguZ?yIGcY<`rrf9xAFPgfw^r{{qJkb`|pLvXmG}- z(SJlfK?h7LOsy~v9k3ZXu{P1}(NeUZ(de^NjxMAcefn3R*KI)0djY+LI|~!3tvf_R z2@N0N_b`JS&J@kDfmGh_QAbYc(3_Vuy8869vdx?{Uz`+h88RyU+z3L?`+|Y(Il;@pdQje8a+acp;wn1-cXUx}?lSJGucK@J4hZ9nkZ7#(IBrqGQqirl12? zN0&q&iEczEUfYHJ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&~VLSN&d6C>ot|ykYWUTW)lxc?W-Kabn>nm^`nN22F=md+-1N diff --git a/locale/fi/LC_MESSAGES/django.po b/locale/fi/LC_MESSAGES/django.po index 76fb992..70e301e 100644 --- a/locale/fi/LC_MESSAGES/django.po +++ b/locale/fi/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-10-16 12:20+0300\n" +"POT-Creation-Date: 2017-10-16 15:35+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -193,7 +193,7 @@ msgid "English" msgstr "englanti" #: infoscreen/templates/infoscreen_admin.html:166 -#: members/templates/settings.html:23 webapp/templates/kaehmy.html:19 +#: members/templates/settings.html:23 webapp/templates/kaehmy.html:54 msgid "Submit" msgstr "Lisää" @@ -547,15 +547,15 @@ msgstr "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" msgid "Custom roles" msgstr "Uudet virat" -#: webapp/forms.py:30 webapp/forms.py:33 +#: webapp/forms.py:35 webapp/templates/kaehmy.html:30 msgid "Preset roles" msgstr "Kaehmyvirat" -#: webapp/forms.py:41 +#: webapp/forms.py:57 msgid "Invalid phone number" msgstr "Virheellinen puhelinnumero" -#: webapp/forms.py:49 +#: webapp/forms.py:65 msgid "Custom role with the same name already exists." msgstr "Samanniminen virka on jo olemassa" @@ -709,7 +709,7 @@ msgstr "Viesti" msgid "Timestamp" msgstr "Aikaleima" -#: webapp/models.py:178 webapp/models.py:242 +#: webapp/models.py:178 webapp/models.py:249 msgid "Phone number" msgstr "Puhelinnumero" @@ -729,19 +729,27 @@ msgstr "Uusi virka" msgid "Kaehmy application: {}" msgstr "Kaehmy: {}" -#: webapp/models.py:227 +#: webapp/models.py:214 +msgid "Board: {}" +msgstr "Hallitus: {}" + +#: webapp/models.py:220 +msgid "Official: {}" +msgstr "Toimari: {}" + +#: webapp/models.py:234 msgid "Role" msgstr "Rooli" -#: webapp/models.py:229 +#: webapp/models.py:236 msgid "Start date" msgstr "Alkupäivämäärä" -#: webapp/models.py:230 +#: webapp/models.py:237 msgid "End date" msgstr "Loppupäivämäärä" -#: webapp/models.py:240 +#: webapp/models.py:247 msgid "Official" msgstr "Toimihenkilö" @@ -790,11 +798,11 @@ msgstr "Kommentoidaan viestiin lähettäjältä" msgid "Comment" msgstr "Kommentti" -#: webapp/templates/kaehmy_list.html:69 +#: webapp/templates/kaehmy_list.html:73 msgid "Show comments" msgstr "Näytä kommentit" -#: webapp/templates/kaehmy_list.html:75 +#: webapp/templates/kaehmy_list.html:79 msgid "Add comment" msgstr "Kommentoi" @@ -862,15 +870,3 @@ msgstr "Kaikki haasteet" #: webapp/templates/ohlhafv_list.html:15 msgid "Total challenges:" msgstr "Haasteita yhteensä:" - -#~ msgid "Invalid value" -#~ msgstr "Epäkelpo arvo" - -#~ msgid "Roles" -#~ msgstr "Roolit" - -#~ msgid "Apply" -#~ msgstr "Hakulomake" - -#~ msgid "language" -#~ msgstr "Kieli" diff --git a/webapp/admin.py b/webapp/admin.py index 2d0d3ba..cb9afd4 100644 --- a/webapp/admin.py +++ b/webapp/admin.py @@ -5,7 +5,7 @@ from webapp.models import Official, Role from webapp.models import Feed, Tag, BaseFeed, Event, Registration from webapp.models import KaehmyForm, KaehmyMessage from webapp.models import CustomKaehmyRole, PresetKaehmyRole -from webapp.models import TelegramChannel, TelegramMessage +from webapp.models import TelegramChannel from modeltranslation.admin import TranslationAdmin from django.contrib.auth.models import Permission # this is needed so that the models get registered for translation @@ -24,4 +24,3 @@ admin.site.register(KaehmyMessage) admin.site.register(CustomKaehmyRole) admin.site.register(PresetKaehmyRole) admin.site.register(TelegramChannel) -admin.site.register(TelegramMessage) diff --git a/webapp/forms.py b/webapp/forms.py index 3c44262..ba273e7 100644 --- a/webapp/forms.py +++ b/webapp/forms.py @@ -30,7 +30,7 @@ class KaehmyForm_Form(forms.ModelForm): for cat_id, category in BaseRole.CATEGORIES: key = 'preset_roles_{}'.format(cat_id) - qset = PresetKaehmyRole.objects.filter(category=cat_id).order_by('category', 'is_board') + qset = PresetKaehmyRole.objects.filter(category=cat_id).order_by('category', '-is_board') self.fields[key] = forms.ModelMultipleChoiceField(qset) self.fields[key].widget = forms.widgets.CheckboxSelectMultiple(attrs={'title': _('Preset roles'), 'name': 'preset_roles'}) self.fields[key].help_text = "" diff --git a/webapp/migrations/0031_auto_20171016_1455.py b/webapp/migrations/0031_auto_20171016_1455.py new file mode 100644 index 0000000..a35466e --- /dev/null +++ b/webapp/migrations/0031_auto_20171016_1455.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-16 11:55 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0030_telegrammessage'), + ] + + operations = [ + migrations.AlterField( + model_name='telegramchannel', + name='channel_id', + field=models.CharField(max_length=255, unique=True), + ), + ] diff --git a/webapp/migrations/0032_delete_telegrammessage.py b/webapp/migrations/0032_delete_telegrammessage.py new file mode 100644 index 0000000..434af97 --- /dev/null +++ b/webapp/migrations/0032_delete_telegrammessage.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-16 14:28 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0031_auto_20171016_1455'), + ] + + operations = [ + migrations.DeleteModel( + name='TelegramMessage', + ), + ] diff --git a/webapp/migrations/0033_telegramchannel_name.py b/webapp/migrations/0033_telegramchannel_name.py new file mode 100644 index 0000000..5a86550 --- /dev/null +++ b/webapp/migrations/0033_telegramchannel_name.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-16 14:31 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0032_delete_telegrammessage'), + ] + + operations = [ + migrations.AddField( + model_name='telegramchannel', + name='name', + field=models.CharField(default='Jan Tuomi private', max_length=255), + preserve_default=False, + ), + ] diff --git a/webapp/models.py b/webapp/models.py index bac9733..2aa1ed5 100644 --- a/webapp/models.py +++ b/webapp/models.py @@ -207,10 +207,17 @@ class KaehmyForm(MessageParent): return total - 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()] - return ', '.join(presets + customs) + def board_roles(self): + presets = [r.name.capitalize() for r in self.preset_roles.filter(is_board=True)] + customs = [r.name.capitalize() for r in self.custom_roles.filter(is_board=True)] + combined = presets + customs + return _('Board: {}').format(', '.join(combined)) if len(combined) > 0 else '' + + def official_roles(self): + presets = [r.name.capitalize() for r in self.preset_roles.filter(is_board=False)] + customs = [r.name.capitalize() for r in self.custom_roles.filter(is_board=False)] + combined = presets + customs + return _('Official: {}').format(', '.join(combined)) if len(combined) > 0 else '' class Role(PresetRole): @@ -264,15 +271,11 @@ class OhlhafvChallenge(models.Model): class TelegramChannel(models.Model): """Model containing the channel id of a Telegram chat""" - channel_id = models.CharField(max_length=255) + name = models.CharField(max_length=255) + channel_id = models.CharField(max_length=255, unique=True) - -class TelegramMessage(models.Model): - """Single Telegram message""" - - message_id = models.CharField(max_length=255, unique=True) - channel_id = models.CharField(max_length=255) - text = models.CharField(max_length=255) + def __str__(self): + return 'Telegram channel: "{}"'.format(self.name) auditlog.register(Tag) diff --git a/webapp/telegram_bot.py b/webapp/telegram_bot.py deleted file mode 100644 index 3da273d..0000000 --- a/webapp/telegram_bot.py +++ /dev/null @@ -1,67 +0,0 @@ -import sys -import asyncio -import logging - -import telepot - -from django.conf import settings -from django.dispatch import receiver -from django.db.models.signals import post_save, post_delete, pre_save - -from webapp.models import TelegramChannel, TelegramMessage - -TOKEN = settings.TELEGRAM_BOT_TOKEN -bot = telepot.Bot(TOKEN) - -logging.getLogger('urllib3.connectionpool').setLevel(logging.WARNING) -logging.getLogger('urllib3.util.retry').setLevel(logging.WARNING) - - -class KaehmyHandler: - - def handle(self, msg): - flavor = telepot.flavor(msg) - - if flavor == 'chat': - text = msg['text'] - id = msg['chat']['id'] - msg_id = msg['message_id'] - if text == '/start': - TelegramChannel.objects.create(channel_id=id) - try: - TelegramMessage.objects.create(message_id=msg_id, channel_id=id, text='Moro! Uudet kaehmyt postataan tälle kanavalle.') - except: - pass - elif text == '/stop': - channels_started = [int(channel.channel_id) for channel in TelegramChannel.objects.all()] - if id in channels_started: - TelegramChannel.objects.get(channel_id=id).delete() - try: - TelegramMessage.objects.create(message_id=msg_id, channel_id=id, text='Lopetetaan kaehmyjen postailu.') - except: - pass - - def announce(self, url, name): - channels_started = [channel.channel_id for channel in TelegramChannel.objects.all()] - logging.debug('Announcing to {} Telegram channels.'.format(len(channels_started))) - for id in channels_started: - bot.sendMessage(id, 'Uusi kaehmy/New kaehmy! {} -> {}'.format(name, url)) - -kaehmy_handler = KaehmyHandler() - - -def main(): - bot.message_loop(kaehmy_handler.handle) - logging.debug('Telepot listening...') - -try: - bot.getMe() - main() -except Exception as ex: - logging.exception('Failed to create Telegram bot with token "{}"'.format(TOKEN)) - - -@receiver(post_save, sender=TelegramMessage, dispatch_uid="save_tg_message") -def save_message(sender, instance, **kwargs): - bot.sendMessage(instance.channel_id, instance.text) - instance.save() \ No newline at end of file diff --git a/webapp/templates/kaehmy_list.html b/webapp/templates/kaehmy_list.html index d4153d4..b5cabcb 100644 --- a/webapp/templates/kaehmy_list.html +++ b/webapp/templates/kaehmy_list.html @@ -60,8 +60,12 @@

{{ application.name }}

-
{{ application.all_roles }}
- + {% if application.board_roles|length > 0 %} +
{{ application.board_roles }}
+ {% endif %} + {% if application.official_roles|length > 0 %} +
{{ application.official_roles }}
+ {% endif %}

{{ application.text }}

{% if application.comment_count > 0 %} diff --git a/webapp/views.py b/webapp/views.py index 316ae94..97f69e4 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -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 = {