diff --git a/locale/en/LC_MESSAGES/django.mo b/locale/en/LC_MESSAGES/django.mo index cc3f55d..467a989 100644 Binary files a/locale/en/LC_MESSAGES/django.mo and b/locale/en/LC_MESSAGES/django.mo differ diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index 7978039..ac4ecc7 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-02 20:52+0300\n" +"POT-Creation-Date: 2017-10-12 00:48+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -33,7 +33,7 @@ msgstr "External website" msgid "Sössö articles" msgstr "Sössö articles" -#: infoscreen/models.py:199 webapp/models.py:70 +#: infoscreen/models.py:199 webapp/models.py:72 msgid "Events" msgstr "Events" @@ -167,8 +167,8 @@ msgstr "Select rotation to edit" msgid "id" msgstr "id" -#: infoscreen/templates/infoscreen_admin.html:141 webapp/models.py:91 -#: webapp/models.py:125 webapp/models.py:138 +#: infoscreen/templates/infoscreen_admin.html:141 webapp/models.py:93 +#: webapp/models.py:126 webapp/templates/kaehmy_list.html:40 msgid "Name" msgstr "Name" @@ -192,7 +192,7 @@ msgid "English" msgstr "English" #: infoscreen/templates/infoscreen_admin.html:166 -#: members/templates/settings.html:23 +#: members/templates/settings.html:23 webapp/templates/kaehmy.html:19 #, fuzzy #| msgid "Submitted" msgid "Submit" @@ -210,7 +210,8 @@ msgstr "First name" msgid "Last name" msgstr "Last name" -#: members/models.py:16 webapp/models.py:126 webapp/models.py:139 +#: members/models.py:16 webapp/models.py:127 +#: webapp/templates/kaehmy_list.html:44 msgid "Email" msgstr "Email" @@ -358,6 +359,7 @@ msgstr "" #: members/templates/member_add_many.html:48 #: members/templates/member_add_many_confirm.html:22 +#: webapp/templates/kaehmy_list.html:52 msgid "Send" msgstr "Send" @@ -536,7 +538,7 @@ msgstr "Successfully updated payment" msgid "Could not update payment object" msgstr "Could not update payment object" -#: members/views/utils.py:116 +#: members/views/utils.py:117 msgid "Missing \"textfield\" POST request field" msgstr "Missing \"textfield\" POST request field" @@ -548,63 +550,79 @@ msgstr "" msgid "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" msgstr "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" -#: webapp/models.py:15 +#: webapp/forms.py:28 +#, fuzzy +#| msgid "Total challenges:" +msgid "Custom roles" +msgstr "Total challenges:" + +#: webapp/forms.py:30 +#, fuzzy +#| msgid "Total challenges:" +msgid "Preset roles" +msgstr "Total challenges:" + +#: webapp/forms.py:40 +msgid "Invalid value" +msgstr "" + +#: webapp/models.py:17 msgid "Webapp" msgstr "" -#: webapp/models.py:26 +#: webapp/models.py:28 msgid "Tag" msgstr "" -#: webapp/models.py:27 +#: webapp/models.py:29 msgid "Tags" msgstr "" -#: webapp/models.py:30 +#: webapp/models.py:32 msgid "Tag: {}" msgstr "" -#: webapp/models.py:50 +#: webapp/models.py:52 msgid "Feed: {}" msgstr "" -#: webapp/models.py:53 +#: webapp/models.py:55 msgid "Feed" msgstr "" -#: webapp/models.py:54 +#: webapp/models.py:56 msgid "Feeds" msgstr "" -#: webapp/models.py:66 +#: webapp/models.py:68 #, fuzzy #| msgid "Events" msgid "Event: {}" msgstr "Events" -#: webapp/models.py:69 +#: webapp/models.py:71 #, fuzzy #| msgid "Events" msgid "Event" msgstr "Events" -#: webapp/models.py:81 +#: webapp/models.py:83 msgid "Registration: {}" msgstr "" -#: webapp/models.py:84 +#: webapp/models.py:86 #, fuzzy #| msgid "Rotation" msgid "Registration" msgstr "Rotation" -#: webapp/models.py:85 +#: webapp/models.py:87 #, fuzzy #| msgid "Rotations" msgid "Registrations" msgstr "Rotations" -#: webapp/models.py:92 +#: webapp/models.py:94 webapp/models.py:166 #, fuzzy #| msgid "Add member" msgid "Board member" @@ -612,42 +630,90 @@ msgstr "Add member" #: webapp/models.py:98 #, fuzzy +#| msgid "Add member" +msgid "board member" +msgstr "Add member" + +#: webapp/models.py:104 +#, fuzzy #| msgid "Duration" msgid "Description" msgstr "Duration" -#: webapp/models.py:99 +#: webapp/models.py:105 msgid "Summary" msgstr "" -#: webapp/models.py:127 +#: webapp/models.py:112 +#, fuzzy +#| msgid "Total challenges:" +msgid "Preset kaehmy role" +msgstr "Total challenges:" + +#: webapp/models.py:113 +#, fuzzy +#| msgid "Total challenges:" +msgid "Preset kaehmy roles" +msgstr "Total challenges:" + +#: webapp/models.py:120 +#, fuzzy +#| msgid "Total challenges:" +msgid "Custom kaehmy role" +msgstr "Total challenges:" + +#: webapp/models.py:121 +#, fuzzy +#| msgid "Total challenges:" +msgid "Custom kaehmy roles" +msgstr "Total challenges:" + +#: webapp/models.py:140 msgid "Message" msgstr "" -#: webapp/models.py:140 +#: webapp/models.py:142 +msgid "Timestamp" +msgstr "" + +#: webapp/models.py:160 webapp/models.py:224 +msgid "Phone number" +msgstr "" + +#: webapp/models.py:161 msgid "Year" msgstr "" -#: webapp/models.py:154 +#: webapp/models.py:162 +msgid "Text" +msgstr "" + +#: webapp/models.py:164 +msgid "Custom role name" +msgstr "" + +#: webapp/models.py:174 +#, fuzzy +#| msgid "Member applications" +msgid "Kaehmy application: {}" +msgstr "Member applications" + +#: webapp/models.py:209 msgid "Role" msgstr "" -#: webapp/models.py:156 +#: webapp/models.py:211 msgid "Start date" msgstr "" -#: webapp/models.py:157 +#: webapp/models.py:212 msgid "End date" msgstr "" -#: webapp/models.py:167 +#: webapp/models.py:222 msgid "Official" msgstr "" -#: webapp/models.py:169 -msgid "Phone number" -msgstr "" - #: webapp/templates/admin_index.html:6 msgid "SIK Admin" msgstr "SIK Admin" @@ -680,6 +746,58 @@ msgstr "International" msgid "Jobs" msgstr "Jobs" +#: webapp/templates/kaehmy.html:12 +msgid "Kaehmy" +msgstr "" + +#: webapp/templates/kaehmy_list.html:24 +msgid "All kaehmys" +msgstr "" + +#: webapp/templates/kaehmy_list.html:28 +#: webapp/templates/kaehmy_statistics.html:14 +#, fuzzy +#| msgid "Total challenges:" +msgid "Total kaehmys:" +msgstr "Total challenges:" + +#: webapp/templates/kaehmy_list.html:36 +msgid "Commenting on post by " +msgstr "" + +#: webapp/templates/kaehmy_list.html:48 +msgid "Comment" +msgstr "" + +#: webapp/templates/kaehmy_list.html:69 +msgid "Show comments" +msgstr "" + +#: webapp/templates/kaehmy_list.html:75 +#, fuzzy +#| msgid "Add payment" +msgid "Add comment" +msgstr "Add payment" + +#: webapp/templates/kaehmy_message.html:11 +msgid "Reply" +msgstr "" + +#: webapp/templates/kaehmy_navigation.html:10 +#, fuzzy +#| msgid "Total challenges:" +msgid "List kaehmys" +msgstr "Total challenges:" + +#: webapp/templates/kaehmy_navigation.html:11 +msgid "New kaehmy" +msgstr "" + +#: webapp/templates/kaehmy_navigation.html:12 +#: webapp/templates/kaehmy_statistics.html:12 +msgid "Statistics" +msgstr "" + #: webapp/templates/login.html:25 webapp/templates/login.html:27 msgid "Username" msgstr "Username" diff --git a/locale/fi/LC_MESSAGES/django.mo b/locale/fi/LC_MESSAGES/django.mo index fbdf6e5..b7afd57 100644 Binary files a/locale/fi/LC_MESSAGES/django.mo and b/locale/fi/LC_MESSAGES/django.mo differ diff --git a/locale/fi/LC_MESSAGES/django.po b/locale/fi/LC_MESSAGES/django.po index df65fb7..5ff63fa 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-02 20:52+0300\n" +"POT-Creation-Date: 2017-10-12 00:48+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -34,7 +34,7 @@ msgstr "Ulkoinen verkkosivu" msgid "Sössö articles" msgstr "Sössön artikkelit" -#: infoscreen/models.py:199 webapp/models.py:70 +#: infoscreen/models.py:199 webapp/models.py:72 msgid "Events" msgstr "Tapahtumat" @@ -168,8 +168,8 @@ msgstr "Valitse muokattava rotaatio" msgid "id" msgstr "id" -#: infoscreen/templates/infoscreen_admin.html:141 webapp/models.py:91 -#: webapp/models.py:125 webapp/models.py:138 +#: infoscreen/templates/infoscreen_admin.html:141 webapp/models.py:93 +#: webapp/models.py:126 webapp/templates/kaehmy_list.html:40 msgid "Name" msgstr "Nimi" @@ -193,7 +193,7 @@ msgid "English" msgstr "englanti" #: infoscreen/templates/infoscreen_admin.html:166 -#: members/templates/settings.html:23 +#: members/templates/settings.html:23 webapp/templates/kaehmy.html:19 msgid "Submit" msgstr "Lisää" @@ -209,7 +209,8 @@ msgstr "Etunimi" msgid "Last name" msgstr "Sukunimi" -#: members/models.py:16 webapp/models.py:126 webapp/models.py:139 +#: members/models.py:16 webapp/models.py:127 +#: webapp/templates/kaehmy_list.html:44 msgid "Email" msgstr "Sähköposti" @@ -351,11 +352,11 @@ msgid "" "The symbol that is used to separate items in one line. Defaults to " "';' (semicolon)." msgstr "" -"Merkki, jota käytetään rivin osien erottamiseen. Oletuksena " -"';' (puolipiste)." +"Merkki, jota käytetään rivin osien erottamiseen. Oletuksena ';' (puolipiste)." #: members/templates/member_add_many.html:48 #: members/templates/member_add_many_confirm.html:22 +#: webapp/templates/kaehmy_list.html:52 msgid "Send" msgstr "Lähetä" @@ -530,7 +531,7 @@ msgstr "Onnistuneesti päivitettiin maksutapahtuma" msgid "Could not update payment object" msgstr "Maksutapahtumaobjektia ei voitu päivittää" -#: members/views/utils.py:116 +#: members/views/utils.py:117 msgid "Missing \"textfield\" POST request field" msgstr "Puuttuva \"textfield\" POST-kenttä" @@ -542,94 +543,142 @@ msgstr "Vaihda" msgid "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" msgstr "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" -#: webapp/models.py:15 +#: webapp/forms.py:28 +msgid "Custom roles" +msgstr "Uudet virat" + +#: webapp/forms.py:30 +msgid "Preset roles" +msgstr "Kaehmyvirat" + +#: webapp/forms.py:40 +msgid "Invalid value" +msgstr "Epäkelpo arvo" + +#: webapp/models.py:17 msgid "Webapp" msgstr "Nettisivut" -#: webapp/models.py:26 +#: webapp/models.py:28 msgid "Tag" msgstr "Tunniste" -#: webapp/models.py:27 +#: webapp/models.py:29 msgid "Tags" msgstr "Tunnisteet" -#: webapp/models.py:30 +#: webapp/models.py:32 msgid "Tag: {}" msgstr "Tunniste: {}" -#: webapp/models.py:50 +#: webapp/models.py:52 msgid "Feed: {}" msgstr "Uutinen: {}" -#: webapp/models.py:53 +#: webapp/models.py:55 msgid "Feed" msgstr "Uutinen" -#: webapp/models.py:54 +#: webapp/models.py:56 msgid "Feeds" msgstr "Uutiset" -#: webapp/models.py:66 +#: webapp/models.py:68 msgid "Event: {}" msgstr "Tapahtuma: {}" -#: webapp/models.py:69 +#: webapp/models.py:71 msgid "Event" msgstr "Tapahtuma" -#: webapp/models.py:81 +#: webapp/models.py:83 msgid "Registration: {}" msgstr "Registration: {}" -#: webapp/models.py:84 +#: webapp/models.py:86 msgid "Registration" msgstr "Ilmoittautuminen" -#: webapp/models.py:85 +#: webapp/models.py:87 msgid "Registrations" msgstr "Ilmoittautumiset" -#: webapp/models.py:92 +#: webapp/models.py:94 webapp/models.py:166 msgid "Board member" msgstr "Hallituksen jäsen" #: webapp/models.py:98 +msgid "board member" +msgstr "Hallituksen jäsen" + +#: webapp/models.py:104 msgid "Description" msgstr "Kuvaus" -#: webapp/models.py:99 +#: webapp/models.py:105 msgid "Summary" msgstr "Tiivistelmä" -#: webapp/models.py:127 +#: webapp/models.py:112 +msgid "Preset kaehmy role" +msgstr "Kaehmyvirka" + +#: webapp/models.py:113 +msgid "Preset kaehmy roles" +msgstr "Kaehmyvirat" + +#: webapp/models.py:120 +msgid "Custom kaehmy role" +msgstr "Uusi virka" + +#: webapp/models.py:121 +msgid "Custom kaehmy roles" +msgstr "Uudet kaehmyvirat" + +#: webapp/models.py:140 msgid "Message" msgstr "Viesti" -#: webapp/models.py:140 +#: webapp/models.py:142 +msgid "Timestamp" +msgstr "Aikaleima" + +#: webapp/models.py:160 webapp/models.py:224 +msgid "Phone number" +msgstr "Puhelinnumero" + +#: webapp/models.py:161 msgid "Year" msgstr "Vuosi" -#: webapp/models.py:154 +#: webapp/models.py:162 +msgid "Text" +msgstr "Teksti" + +#: webapp/models.py:164 +msgid "Custom role name" +msgstr "Uusi virka" + +#: webapp/models.py:174 +msgid "Kaehmy application: {}" +msgstr "Kaehmy: {}" + +#: webapp/models.py:209 msgid "Role" msgstr "Rooli" -#: webapp/models.py:156 +#: webapp/models.py:211 msgid "Start date" msgstr "Alkupäivämäärä" -#: webapp/models.py:157 +#: webapp/models.py:212 msgid "End date" msgstr "Loppupäivämäärä" -#: webapp/models.py:167 +#: webapp/models.py:222 msgid "Official" msgstr "Toimihenkilö" -#: webapp/models.py:169 -msgid "Phone number" -msgstr "Puhelinnumero" - #: webapp/templates/admin_index.html:6 msgid "SIK Admin" msgstr "SIK Hallintapaneeli" @@ -662,6 +711,52 @@ msgstr "International" msgid "Jobs" msgstr "Työpaikat" +#: webapp/templates/kaehmy.html:12 +msgid "Kaehmy" +msgstr "Kaehmy" + +#: webapp/templates/kaehmy_list.html:24 +msgid "All kaehmys" +msgstr "Kaikki kaehmyt" + +#: webapp/templates/kaehmy_list.html:28 +#: webapp/templates/kaehmy_statistics.html:14 +msgid "Total kaehmys:" +msgstr "Kaehmyjä yhteensä:" + +#: webapp/templates/kaehmy_list.html:36 +msgid "Commenting on post by " +msgstr "Kommentoidaan viestiin lähettäjältä" + +#: webapp/templates/kaehmy_list.html:48 +msgid "Comment" +msgstr "Kommentti" + +#: webapp/templates/kaehmy_list.html:69 +msgid "Show comments" +msgstr "Näytä kommentit" + +#: webapp/templates/kaehmy_list.html:75 +msgid "Add comment" +msgstr "Kommentoi" + +#: webapp/templates/kaehmy_message.html:11 +msgid "Reply" +msgstr "Vastaa" + +#: webapp/templates/kaehmy_navigation.html:10 +msgid "List kaehmys" +msgstr "Kaikki kaehmyt" + +#: webapp/templates/kaehmy_navigation.html:11 +msgid "New kaehmy" +msgstr "Uusi kaehmy" + +#: webapp/templates/kaehmy_navigation.html:12 +#: webapp/templates/kaehmy_statistics.html:12 +msgid "Statistics" +msgstr "Kaehmytilastot" + #: webapp/templates/login.html:25 webapp/templates/login.html:27 msgid "Username" msgstr "Käyttäjänimi" @@ -710,5 +805,11 @@ msgstr "Kaikki haasteet" msgid "Total challenges:" msgstr "Haasteita yhteensä:" +#~ msgid "Roles" +#~ msgstr "Roolit" + +#~ msgid "Apply" +#~ msgstr "Hakulomake" + #~ msgid "language" #~ msgstr "Kieli" diff --git a/webapp/forms.py b/webapp/forms.py index 0007eab..4dc78a9 100644 --- a/webapp/forms.py +++ b/webapp/forms.py @@ -1,11 +1,59 @@ +"""File containing webapp forms.""" + from django import forms from django.utils.translation import ugettext_lazy as _ +from django.core.exceptions import ValidationError -from webapp.models import OhlhafvChallenge +from webapp.models import CustomKaehmyRole, PresetKaehmyRole +from webapp.models import OhlhafvChallenge, KaehmyForm, KaehmyMessage + + +class KaehmyForm_Form(forms.ModelForm): + """Class representing Kaehmy form.""" + + class Meta: + """Meta for class KaehmyForm.""" + + model = KaehmyForm + fields = ['name', 'email', 'phone_number', 'year', + 'preset_roles', 'custom_roles', 'custom_role_name', + 'custom_role_is_board', 'text'] + + def __init__(self, *args, **kwargs): + super(KaehmyForm_Form, self).__init__(*args, **kwargs) + + custom_roles_exist = CustomKaehmyRole.objects.all().exists() + self.fields["custom_roles"].widget = forms.widgets.CheckboxSelectMultiple() if custom_roles_exist else forms.HiddenInput() + self.fields["custom_roles"].help_text = "" + self.fields["custom_roles"].label = _('Custom roles') + self.fields["custom_roles"].queryset = CustomKaehmyRole.objects.all() + self.fields["preset_roles"].widget = forms.widgets.CheckboxSelectMultiple(attrs={'title': _('Preset roles')}) + self.fields["preset_roles"].help_text = "" + self.fields["preset_roles"].queryset = PresetKaehmyRole.objects.all() + self.fields["preset_roles"].label = _('Preset roles') + + def clean_phone_number(self): + """Clean phone number field.""" + number = self.cleaned_data.get('phone_number') + if number.isdigit(): + return number + else: + raise ValidationError(_('Invalid value')) + + +class KaehmyCommentForm(forms.ModelForm): + + class Meta: + model = KaehmyMessage + fields = ['name', 'email', 'message', 'parent'] class OhlhafvForm(forms.ModelForm): + """Class representing Ohlhafv form.""" class Meta: + """Meta class for Ohlhafv form.""" + model = OhlhafvChallenge - fields = ['challenger', 'challenger_email', 'victim', 'victim_email', 'series', 'message'] + fields = ['challenger', 'challenger_email', + 'victim', 'victim_email', 'series', 'message'] diff --git a/webapp/migrations/0016_auto_20171011_1828.py b/webapp/migrations/0016_auto_20171011_1828.py new file mode 100644 index 0000000..00c14c7 --- /dev/null +++ b/webapp/migrations/0016_auto_20171011_1828.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 15:28 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0015_auto_20170928_2331'), + ] + + operations = [ + migrations.CreateModel( + name='KaehmyFormSelectedRole', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + migrations.RemoveField( + model_name='customkaehmyrole', + name='form', + ), + migrations.RemoveField( + model_name='presetkaehmyrole', + name='form', + ), + migrations.AddField( + model_name='kaehmyform', + name='custom_roles', + field=models.ManyToManyField(blank=True, related_name='forms', to='webapp.CustomKaehmyRole'), + ), + migrations.AddField( + model_name='kaehmyform', + name='preset_roles', + field=models.ManyToManyField(blank=True, related_name='forms', to='webapp.PresetKaehmyRole'), + ), + ] diff --git a/webapp/migrations/0017_kaehmyform_text.py b/webapp/migrations/0017_kaehmyform_text.py new file mode 100644 index 0000000..bcc7834 --- /dev/null +++ b/webapp/migrations/0017_kaehmyform_text.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 15:45 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0016_auto_20171011_1828'), + ] + + operations = [ + migrations.AddField( + model_name='kaehmyform', + name='text', + field=models.TextField(default='', max_length=300, verbose_name='Text'), + ), + ] diff --git a/webapp/migrations/0018_auto_20171011_1856.py b/webapp/migrations/0018_auto_20171011_1856.py new file mode 100644 index 0000000..4bcbfad --- /dev/null +++ b/webapp/migrations/0018_auto_20171011_1856.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 15:56 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0017_kaehmyform_text'), + ] + + operations = [ + migrations.AlterField( + model_name='kaehmyform', + name='year', + field=models.IntegerField(choices=[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, 'N')], verbose_name='Year'), + ), + ] diff --git a/webapp/migrations/0019_kaehmymessage_timestamp.py b/webapp/migrations/0019_kaehmymessage_timestamp.py new file mode 100644 index 0000000..9764f72 --- /dev/null +++ b/webapp/migrations/0019_kaehmymessage_timestamp.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 16:22 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0018_auto_20171011_1856'), + ] + + operations = [ + migrations.AddField( + model_name='kaehmymessage', + name='timestamp', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Timestamp'), + ), + ] diff --git a/webapp/migrations/0020_auto_20171011_2020.py b/webapp/migrations/0020_auto_20171011_2020.py new file mode 100644 index 0000000..2aabb06 --- /dev/null +++ b/webapp/migrations/0020_auto_20171011_2020.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 17:20 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0019_kaehmymessage_timestamp'), + ] + + operations = [ + migrations.AddField( + model_name='kaehmyform', + name='custom_role_is_board', + field=models.BooleanField(default=False, verbose_name='Board member'), + ), + migrations.AddField( + model_name='kaehmyform', + name='custom_role_name', + field=models.CharField(default='', max_length=255, verbose_name='Custom role name'), + ), + ] diff --git a/webapp/migrations/0020_kaehmyform_phone_number.py b/webapp/migrations/0020_kaehmyform_phone_number.py new file mode 100644 index 0000000..00d930d --- /dev/null +++ b/webapp/migrations/0020_kaehmyform_phone_number.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 16:59 +from __future__ import unicode_literals + +from django.db import migrations +import phonenumber_field.modelfields + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0019_kaehmymessage_timestamp'), + ] + + operations = [ + migrations.AddField( + model_name='kaehmyform', + name='phone_number', + field=phonenumber_field.modelfields.PhoneNumberField(default='', max_length=128, verbose_name='Phone number'), + preserve_default=False, + ), + ] diff --git a/webapp/migrations/0021_merge_20171011_2033.py b/webapp/migrations/0021_merge_20171011_2033.py new file mode 100644 index 0000000..ed9429f --- /dev/null +++ b/webapp/migrations/0021_merge_20171011_2033.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 17:33 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0020_kaehmyform_phone_number'), + ('webapp', '0020_auto_20171011_2020'), + ] + + operations = [ + ] diff --git a/webapp/migrations/0022_auto_20171011_2050.py b/webapp/migrations/0022_auto_20171011_2050.py new file mode 100644 index 0000000..6daeeb6 --- /dev/null +++ b/webapp/migrations/0022_auto_20171011_2050.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 17:50 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0021_merge_20171011_2033'), + ] + + operations = [ + migrations.AlterField( + model_name='kaehmyform', + name='custom_role_is_board', + field=models.BooleanField(verbose_name='Board member'), + ), + migrations.AlterField( + model_name='kaehmyform', + name='custom_role_name', + field=models.CharField(blank=True, max_length=255, verbose_name='Custom role name'), + ), + ] diff --git a/webapp/migrations/0023_remove_kaehmyform_phone_number.py b/webapp/migrations/0023_remove_kaehmyform_phone_number.py new file mode 100644 index 0000000..fc7a28d --- /dev/null +++ b/webapp/migrations/0023_remove_kaehmyform_phone_number.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 18:02 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0022_auto_20171011_2050'), + ] + + operations = [ + migrations.RemoveField( + model_name='kaehmyform', + name='phone_number', + ), + ] diff --git a/webapp/migrations/0024_kaehmyform_phone_number.py b/webapp/migrations/0024_kaehmyform_phone_number.py new file mode 100644 index 0000000..7539bc8 --- /dev/null +++ b/webapp/migrations/0024_kaehmyform_phone_number.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 18:12 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0023_remove_kaehmyform_phone_number'), + ] + + operations = [ + migrations.AddField( + model_name='kaehmyform', + name='phone_number', + field=models.CharField(default='', max_length=10, verbose_name='Phone number'), + ), + ] diff --git a/webapp/migrations/0025_auto_20171011_2235.py b/webapp/migrations/0025_auto_20171011_2235.py new file mode 100644 index 0000000..17ccd0f --- /dev/null +++ b/webapp/migrations/0025_auto_20171011_2235.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 19:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0024_kaehmyform_phone_number'), + ] + + operations = [ + migrations.RemoveField( + model_name='kaehmyform', + name='email', + ), + migrations.RemoveField( + model_name='kaehmyform', + name='name', + ), + migrations.RemoveField( + model_name='kaehmymessage', + name='email', + ), + migrations.RemoveField( + model_name='kaehmymessage', + name='name', + ), + migrations.AddField( + model_name='messageparent', + name='email', + field=models.EmailField(default='not@valid.email', max_length=254, verbose_name='Email'), + ), + migrations.AddField( + model_name='messageparent', + name='name', + field=models.CharField(default='Anonymous', max_length=255, verbose_name='Name'), + ), + ] diff --git a/webapp/migrations/0026_auto_20171011_2236.py b/webapp/migrations/0026_auto_20171011_2236.py new file mode 100644 index 0000000..98ee56b --- /dev/null +++ b/webapp/migrations/0026_auto_20171011_2236.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 19:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0025_auto_20171011_2235'), + ] + + operations = [ + migrations.AlterField( + model_name='messageparent', + name='email', + field=models.EmailField(default='', max_length=254, verbose_name='Email'), + ), + migrations.AlterField( + model_name='messageparent', + name='name', + field=models.CharField(default='', max_length=255, verbose_name='Name'), + ), + ] diff --git a/webapp/migrations/0027_auto_20171012_0037.py b/webapp/migrations/0027_auto_20171012_0037.py new file mode 100644 index 0000000..00de956 --- /dev/null +++ b/webapp/migrations/0027_auto_20171012_0037.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 21:37 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0026_auto_20171011_2236'), + ] + + operations = [ + migrations.DeleteModel( + name='KaehmyFormSelectedRole', + ), + migrations.AlterModelOptions( + name='customkaehmyrole', + options={'verbose_name': 'Custom kaehmy role', 'verbose_name_plural': 'Custom kaehmy roles'}, + ), + migrations.AlterModelOptions( + name='presetkaehmyrole', + options={'verbose_name': 'Preset kaehmy role', 'verbose_name_plural': 'Preset kaehmy roles'}, + ), + ] diff --git a/webapp/models.py b/webapp/models.py index b48add0..9c9c67c 100644 --- a/webapp/models.py +++ b/webapp/models.py @@ -11,6 +11,8 @@ from auditlog.registry import auditlog from phonenumber_field.modelfields import PhoneNumberField from django.contrib.postgres.fields import JSONField +import logging + VERBOSE_NAME = _('Webapp') @@ -91,6 +93,10 @@ class BaseRole(models.Model): name = models.CharField(_('Name'), max_length=255) is_board = models.BooleanField(_('Board member')) + def __str__(self): + n = self.name.capitalize() + return '{} ({})'.format(n, _('board member')) if self.is_board else n + class PresetRole(BaseRole): """Model representing a preset occupation in the guild.""" @@ -102,17 +108,26 @@ class PresetRole(BaseRole): class PresetKaehmyRole(PresetRole): """Model for kaehmy role.""" - form = models.ForeignKey('KaehmyForm', related_name='preset_roles') + class Meta: + verbose_name = _('Preset kaehmy role') + verbose_name_plural = _('Preset kaehmy roles') class CustomKaehmyRole(BaseRole): """Model representing a user-specified custom occupation.""" - form = models.ForeignKey('KaehmyForm', related_name='custom_roles') + class Meta: + verbose_name = _('Custom kaehmy role') + verbose_name_plural = _('Custom kaehmy roles') class MessageParent(models.Model): - pass + + name = models.CharField(_('Name'), max_length=255, default='') + email = models.EmailField(_('Email'), default='') + + def __str__(self): + return 'Message parent #{}'.format(self.id) class KaehmyMessage(MessageParent): @@ -122,10 +137,9 @@ class KaehmyMessage(MessageParent): Every message relates to certain kaehmyform or parent message. """ - name = models.CharField(_('Name'), max_length=255) - email = models.EmailField(_('Email')) message = models.TextField(_('Message')) parent = models.ForeignKey('MessageParent', related_name='messages') + timestamp = models.DateTimeField(_('Timestamp'), default=timezone.now) class KaehmyForm(MessageParent): @@ -134,10 +148,51 @@ class KaehmyForm(MessageParent): Allows user to choose from existing roles or to create custom ones. """ + YEAR_CHOICES = ( + (1, '1'), + (2, '2'), + (3, '3'), + (4, '4'), + (5, 'N'), + ) - name = models.CharField(_('Name'), max_length=255) - email = models.EmailField(_('Email')) - year = models.IntegerField(_('Year')) + phone_number = models.CharField( + _('Phone number'), max_length=10, default="") + year = models.IntegerField(_('Year'), choices=YEAR_CHOICES) + text = models.TextField(_('Text'), default="", max_length=300) + custom_role_name = models.CharField( + _('Custom role name'), max_length=255, blank=True) + custom_role_is_board = models.BooleanField( + _('Board member'), blank=True) + custom_roles = models.ManyToManyField( + 'CustomKaehmyRole', related_name='forms', blank=True) + preset_roles = models.ManyToManyField( + 'PresetKaehmyRole', related_name='forms', blank=True) + + def __str__(self): + """Return model info.""" + return _('Kaehmy application: {}').format(self.name) + + def comment_count(self): + """Count comments for kaehmy.""" + total = 0 + + def recurse(message): + count = 0 + for msg in message.messages.all(): + count += recurse(msg) + + return count + 1 + + for message in self.messages.all(): + total += recurse(message) + + 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) class Role(PresetRole): diff --git a/webapp/static/css/kaehmy_nav.css b/webapp/static/css/kaehmy_nav.css new file mode 100644 index 0000000..0d58e5d --- /dev/null +++ b/webapp/static/css/kaehmy_nav.css @@ -0,0 +1,3 @@ +.kaehmy_navigation { + margin-bottom: 10px; +} diff --git a/webapp/static/css/webapp.css b/webapp/static/css/webapp.css index 242628d..05be3da 100644 --- a/webapp/static/css/webapp.css +++ b/webapp/static/css/webapp.css @@ -6,7 +6,7 @@ } body { - max-width: 700px; + max-width: 1000px; margin-left: auto !important; margin-right: auto !important; } diff --git a/webapp/templates/base.html b/webapp/templates/base.html index d864e21..6edeaf2 100644 --- a/webapp/templates/base.html +++ b/webapp/templates/base.html @@ -16,17 +16,23 @@ - - + + + {% block header %}
{% include "sik_header.html" %}
+ {% endblock %} +
- {% include "navigation.html" %} + {% block navigation %} + {% include "navigation.html" %} + {% endblock %} + {% block content %} {% endblock %}
diff --git a/webapp/templates/error.html b/webapp/templates/error.html new file mode 100644 index 0000000..ccb932f --- /dev/null +++ b/webapp/templates/error.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block navigation %} +{% endblock navigation %} + +{% block content %} + +{% endblock content %} \ No newline at end of file diff --git a/webapp/templates/kaehmy.html b/webapp/templates/kaehmy.html new file mode 100644 index 0000000..5f788dc --- /dev/null +++ b/webapp/templates/kaehmy.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% load bootstrap3 %} +{% load i18n %} + +{% block navigation %} + {% include "kaehmy_navigation.html" %} +{% endblock %} + +{% block content %} +
+

{% trans "Kaehmy" %}

+ +
+
{% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + + {% endbuttons %} +
+
+
+{% endblock content %} diff --git a/webapp/templates/kaehmy_list.html b/webapp/templates/kaehmy_list.html new file mode 100644 index 0000000..d4153d4 --- /dev/null +++ b/webapp/templates/kaehmy_list.html @@ -0,0 +1,89 @@ +{% extends "base.html" %} + +{% load static %} +{% load i18n %} + +{% block navigation %} + {% include "kaehmy_navigation.html" %} +{% endblock %} + +{% block content %} + +
+
+

{% trans "All kaehmys" %}

+
+ +
+
{% trans "Total kaehmys:" %} {{ application_count }}
+
+ +
+
+
+
{% csrf_token %} +
+ {% trans "Commenting on post by " %} + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+ + {% for application in applications %} +
+

{{ application.name }}

+
+
{{ application.all_roles }}
+ +

{{ application.text }}

+ + {% if application.comment_count > 0 %} + + {% endif %} + + + +
+ {% for message in application.messages.all %} + {% include "kaehmy_message.html" with messages=message.messages.all %} + {% endfor %} +
+
+
+ {% endfor %} + +
+{% endblock content %} diff --git a/webapp/templates/kaehmy_message.html b/webapp/templates/kaehmy_message.html new file mode 100644 index 0000000..44230e4 --- /dev/null +++ b/webapp/templates/kaehmy_message.html @@ -0,0 +1,21 @@ +{% load i18n %} + +
+
+

{{ message.name }}

+

{{ message.message }}

+ +
{{ message.timestamp }}
+ +
+ {% for message in messages %} + {% include "kaehmy_message.html" with messages=message.messages.all %} + {% endfor %} +
+ +
+
\ No newline at end of file diff --git a/webapp/templates/kaehmy_navigation.html b/webapp/templates/kaehmy_navigation.html new file mode 100644 index 0000000..125652a --- /dev/null +++ b/webapp/templates/kaehmy_navigation.html @@ -0,0 +1,16 @@ +{% load i18n %} + + diff --git a/webapp/templates/kaehmy_statistics.html b/webapp/templates/kaehmy_statistics.html new file mode 100644 index 0000000..be3e26d --- /dev/null +++ b/webapp/templates/kaehmy_statistics.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% load bootstrap3 %} +{% load i18n %} + +{% block navigation %} + {% include "kaehmy_navigation.html" %} +{% endblock %} + +{% block content %} +
+

{% trans "Statistics" %}

+
+
{% trans "Total kaehmys:" %} {{ application_count }}
+
+ + {% for role in role_list %} +
+

{{ role.0 }} ({{ role.1 }})

+
+ {% endfor %} +
+{% endblock content %} diff --git a/webapp/templates/ohlhafv_list.html b/webapp/templates/ohlhafv_list.html index a21e7e5..057ce06 100644 --- a/webapp/templates/ohlhafv_list.html +++ b/webapp/templates/ohlhafv_list.html @@ -12,7 +12,7 @@
- {% trans "Total challenges:" %} {{ challenge_count }} + {% trans "Total challenges:" %}{{ application_count }}
{{ table|safe }} diff --git a/webapp/templates/sik_header.html b/webapp/templates/sik_header.html index 17ef251..42d5040 100644 --- a/webapp/templates/sik_header.html +++ b/webapp/templates/sik_header.html @@ -3,6 +3,6 @@
diff --git a/webapp/urls.py b/webapp/urls.py index f9a1f04..dcbd61b 100644 --- a/webapp/urls.py +++ b/webapp/urls.py @@ -18,6 +18,11 @@ from webapp.views import event_calendar_view from webapp.views import international_view from webapp.views import sosso_view from webapp.views import contact_view +from webapp.views import kaehmy_view +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 urlpatterns = [ # main @@ -30,6 +35,8 @@ urlpatterns = [ # git revision url(r'^about', about_view), + + # pages url(r'^guild', guild_view), url(r'^freshmen', freshmen_view), url(r'^event_calendar', event_calendar_view), @@ -40,8 +47,15 @@ urlpatterns = [ # corporate url(r'^jobs', jobs_view), + # kaehmy + url(r'^kaehmy/new', kaehmy_view), + url(r'^kaehmy/submit', kaehmy_submit), + url(r'^kaehmy/add_comment', kaehmy_comment), + url(r'^kaehmy/statistics', kaehmy_statistics_view), + url(r'^kaehmy', kaehmy_list_view), + # ohlhafv - url(r'^ohlhafv$', ohlhafv_view), url(r'^ohlhafv/submit', ohlhafv_submit), url(r'^ohlhafv/list', ohlhafv_list), + url(r'^ohlhafv', ohlhafv_view), ] diff --git a/webapp/views.py b/webapp/views.py index 0c2ea69..c0bc21f 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -8,10 +8,27 @@ from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import permission_required, login_required from django.conf import settings import logging -from webapp.models import OhlhafvChallenge -from webapp.forms import OhlhafvForm +from webapp.models import PresetKaehmyRole, CustomKaehmyRole +from webapp.models import OhlhafvChallenge, KaehmyForm +from webapp.forms import OhlhafvForm, KaehmyForm_Form, KaehmyCommentForm from webapp.tables import OhlhafvTable +from django.core.mail import send_mail +from django.conf import settings + + +def send_email(to, subject, body): + success = send_mail( + subject, + body, + settings.DEFAULT_EMAIL_FROM, + [to], + fail_silently=False, + ) + + if success == 0: + raise Exception('Failed to send email!') + @require_http_methods(["GET"]) def main_index(request, *args, **kwargs): @@ -106,6 +123,46 @@ 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) + + 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 http://sika.sahkoinsinoorikilta.fi/kaehmy').format(name) + + send_email(email, subject, body) + logging.debug('Sent kaehmy email to recipient <{}>'.format(email)) + else: + context = { + 'errors': form.errors + } + return render(request, 'error.html', context) + return HttpResponseRedirect('/kaehmy') + + @require_http_methods(["GET"]) def ohlhafv_view(request, *args, **kwargs): """Render Ohlhafv form page.""" @@ -146,3 +203,67 @@ def ohlhafv_list(request, *args, **kwargs): 'challenge_count': len(challenges), } return render(request, 'ohlhafv_list.html', context) + + +@ensure_csrf_cookie +@require_http_methods(["GET"]) +def kaehmy_list_view(request, *args, **kwargs): + """Kaehmy application list""" + + applications = KaehmyForm.objects.all() + + context = { + 'applications': applications, + 'application_count': len(applications) + } + return render(request, 'kaehmy_list.html', context) + + +@ensure_csrf_cookie +@require_http_methods(["POST"]) +def kaehmy_comment(request, *args, **kwargs): + """POST endpoint for commenting""" + + form = KaehmyCommentForm(request.POST) + if form.is_valid(): + comment = form.save() + email = comment.parent.email + name = comment.name + + subject = 'Kaehmyysi tai kommenttiisi on vastattu!' + body = ('{} on vastannut kaehmyhakemukseesi tai kommenttiisi kaehmypalvelussa.\r\n\r\n' + 'Käy lukemassa viesti osoitteessa http://sika.sahkoinsinoorikilta.fi/kaehmy').format(name.capitalize()) + + send_email(email, subject, body) + logging.debug('Sent kaehmy comment email to recipient <{}>'.format(email)) + + return redirect('/kaehmy') + else: + print(form) + context = { + 'errors': form.errors + } + return render(request, 'error.html', context) + + +@require_http_methods(["GET"]) +def kaehmy_statistics_view(request, *args, **kwargs): + """Kaehmys roles listed by applications""" + + applications = KaehmyForm.objects.all() + role_list = [] + + preset_roles = PresetKaehmyRole.objects.all() + custom_roles = CustomKaehmyRole.objects.all() + + for preset in preset_roles: + role_list.append((preset.name, preset.forms.all().count())) + for custom in custom_roles: + role_list.append((custom.name, custom.forms.all().count())) + + context = { + 'applications': applications, + 'application_count': len(applications), + 'role_list': role_list + } + return render(request, 'kaehmy_statistics.html', context)