Merge branch 'develop' into 'master'

Kaehmy

See merge request !56
This commit is contained in:
Jan Tuomi
2017-10-12 10:30:02 +03:00
32 changed files with 1052 additions and 83 deletions
Binary file not shown.
+149 -31
View File
@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -33,7 +33,7 @@ msgstr "External website"
msgid "Sössö articles" msgid "Sössö articles"
msgstr "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" msgid "Events"
msgstr "Events" msgstr "Events"
@@ -167,8 +167,8 @@ msgstr "Select rotation to edit"
msgid "id" msgid "id"
msgstr "id" msgstr "id"
#: infoscreen/templates/infoscreen_admin.html:141 webapp/models.py:91 #: infoscreen/templates/infoscreen_admin.html:141 webapp/models.py:93
#: webapp/models.py:125 webapp/models.py:138 #: webapp/models.py:126 webapp/templates/kaehmy_list.html:40
msgid "Name" msgid "Name"
msgstr "Name" msgstr "Name"
@@ -192,7 +192,7 @@ msgid "English"
msgstr "English" msgstr "English"
#: infoscreen/templates/infoscreen_admin.html:166 #: infoscreen/templates/infoscreen_admin.html:166
#: members/templates/settings.html:23 #: members/templates/settings.html:23 webapp/templates/kaehmy.html:19
#, fuzzy #, fuzzy
#| msgid "Submitted" #| msgid "Submitted"
msgid "Submit" msgid "Submit"
@@ -210,7 +210,8 @@ msgstr "First name"
msgid "Last name" msgid "Last name"
msgstr "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" msgid "Email"
msgstr "Email" msgstr "Email"
@@ -358,6 +359,7 @@ msgstr ""
#: members/templates/member_add_many.html:48 #: members/templates/member_add_many.html:48
#: members/templates/member_add_many_confirm.html:22 #: members/templates/member_add_many_confirm.html:22
#: webapp/templates/kaehmy_list.html:52
msgid "Send" msgid "Send"
msgstr "Send" msgstr "Send"
@@ -536,7 +538,7 @@ msgstr "Successfully updated payment"
msgid "Could not update payment object" msgid "Could not update payment object"
msgstr "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" msgid "Missing \"textfield\" POST request field"
msgstr "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" msgid "Copyright Aalto-yliopiston Sähköinsinöörikilta ry"
msgstr "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" msgid "Webapp"
msgstr "" msgstr ""
#: webapp/models.py:26 #: webapp/models.py:28
msgid "Tag" msgid "Tag"
msgstr "" msgstr ""
#: webapp/models.py:27 #: webapp/models.py:29
msgid "Tags" msgid "Tags"
msgstr "" msgstr ""
#: webapp/models.py:30 #: webapp/models.py:32
msgid "Tag: {}" msgid "Tag: {}"
msgstr "" msgstr ""
#: webapp/models.py:50 #: webapp/models.py:52
msgid "Feed: {}" msgid "Feed: {}"
msgstr "" msgstr ""
#: webapp/models.py:53 #: webapp/models.py:55
msgid "Feed" msgid "Feed"
msgstr "" msgstr ""
#: webapp/models.py:54 #: webapp/models.py:56
msgid "Feeds" msgid "Feeds"
msgstr "" msgstr ""
#: webapp/models.py:66 #: webapp/models.py:68
#, fuzzy #, fuzzy
#| msgid "Events" #| msgid "Events"
msgid "Event: {}" msgid "Event: {}"
msgstr "Events" msgstr "Events"
#: webapp/models.py:69 #: webapp/models.py:71
#, fuzzy #, fuzzy
#| msgid "Events" #| msgid "Events"
msgid "Event" msgid "Event"
msgstr "Events" msgstr "Events"
#: webapp/models.py:81 #: webapp/models.py:83
msgid "Registration: {}" msgid "Registration: {}"
msgstr "" msgstr ""
#: webapp/models.py:84 #: webapp/models.py:86
#, fuzzy #, fuzzy
#| msgid "Rotation" #| msgid "Rotation"
msgid "Registration" msgid "Registration"
msgstr "Rotation" msgstr "Rotation"
#: webapp/models.py:85 #: webapp/models.py:87
#, fuzzy #, fuzzy
#| msgid "Rotations" #| msgid "Rotations"
msgid "Registrations" msgid "Registrations"
msgstr "Rotations" msgstr "Rotations"
#: webapp/models.py:92 #: webapp/models.py:94 webapp/models.py:166
#, fuzzy #, fuzzy
#| msgid "Add member" #| msgid "Add member"
msgid "Board member" msgid "Board member"
@@ -612,42 +630,90 @@ msgstr "Add member"
#: webapp/models.py:98 #: webapp/models.py:98
#, fuzzy #, fuzzy
#| msgid "Add member"
msgid "board member"
msgstr "Add member"
#: webapp/models.py:104
#, fuzzy
#| msgid "Duration" #| msgid "Duration"
msgid "Description" msgid "Description"
msgstr "Duration" msgstr "Duration"
#: webapp/models.py:99 #: webapp/models.py:105
msgid "Summary" msgid "Summary"
msgstr "" 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" msgid "Message"
msgstr "" 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" msgid "Year"
msgstr "" 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" msgid "Role"
msgstr "" msgstr ""
#: webapp/models.py:156 #: webapp/models.py:211
msgid "Start date" msgid "Start date"
msgstr "" msgstr ""
#: webapp/models.py:157 #: webapp/models.py:212
msgid "End date" msgid "End date"
msgstr "" msgstr ""
#: webapp/models.py:167 #: webapp/models.py:222
msgid "Official" msgid "Official"
msgstr "" msgstr ""
#: webapp/models.py:169
msgid "Phone number"
msgstr ""
#: webapp/templates/admin_index.html:6 #: webapp/templates/admin_index.html:6
msgid "SIK Admin" msgid "SIK Admin"
msgstr "SIK Admin" msgstr "SIK Admin"
@@ -680,6 +746,58 @@ msgstr "International"
msgid "Jobs" msgid "Jobs"
msgstr "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 #: webapp/templates/login.html:25 webapp/templates/login.html:27
msgid "Username" msgid "Username"
msgstr "Username" msgstr "Username"
Binary file not shown.
+134 -33
View File
@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -34,7 +34,7 @@ msgstr "Ulkoinen verkkosivu"
msgid "Sössö articles" msgid "Sössö articles"
msgstr "Sössön artikkelit" msgstr "Sössön artikkelit"
#: infoscreen/models.py:199 webapp/models.py:70 #: infoscreen/models.py:199 webapp/models.py:72
msgid "Events" msgid "Events"
msgstr "Tapahtumat" msgstr "Tapahtumat"
@@ -168,8 +168,8 @@ msgstr "Valitse muokattava rotaatio"
msgid "id" msgid "id"
msgstr "id" msgstr "id"
#: infoscreen/templates/infoscreen_admin.html:141 webapp/models.py:91 #: infoscreen/templates/infoscreen_admin.html:141 webapp/models.py:93
#: webapp/models.py:125 webapp/models.py:138 #: webapp/models.py:126 webapp/templates/kaehmy_list.html:40
msgid "Name" msgid "Name"
msgstr "Nimi" msgstr "Nimi"
@@ -193,7 +193,7 @@ msgid "English"
msgstr "englanti" msgstr "englanti"
#: infoscreen/templates/infoscreen_admin.html:166 #: infoscreen/templates/infoscreen_admin.html:166
#: members/templates/settings.html:23 #: members/templates/settings.html:23 webapp/templates/kaehmy.html:19
msgid "Submit" msgid "Submit"
msgstr "Lisää" msgstr "Lisää"
@@ -209,7 +209,8 @@ msgstr "Etunimi"
msgid "Last name" msgid "Last name"
msgstr "Sukunimi" 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" msgid "Email"
msgstr "Sähköposti" msgstr "Sähköposti"
@@ -351,11 +352,11 @@ msgid ""
"The symbol that is used to separate items in one line. Defaults to " "The symbol that is used to separate items in one line. Defaults to "
"';' (semicolon)." "';' (semicolon)."
msgstr "" msgstr ""
"Merkki, jota käytetään rivin osien erottamiseen. Oletuksena " "Merkki, jota käytetään rivin osien erottamiseen. Oletuksena ';' (puolipiste)."
"';' (puolipiste)."
#: members/templates/member_add_many.html:48 #: members/templates/member_add_many.html:48
#: members/templates/member_add_many_confirm.html:22 #: members/templates/member_add_many_confirm.html:22
#: webapp/templates/kaehmy_list.html:52
msgid "Send" msgid "Send"
msgstr "Lähetä" msgstr "Lähetä"
@@ -530,7 +531,7 @@ msgstr "Onnistuneesti päivitettiin maksutapahtuma"
msgid "Could not update payment object" msgid "Could not update payment object"
msgstr "Maksutapahtumaobjektia ei voitu päivittää" msgstr "Maksutapahtumaobjektia ei voitu päivittää"
#: members/views/utils.py:116 #: members/views/utils.py:117
msgid "Missing \"textfield\" POST request field" msgid "Missing \"textfield\" POST request field"
msgstr "Puuttuva \"textfield\" POST-kenttä" msgstr "Puuttuva \"textfield\" POST-kenttä"
@@ -542,94 +543,142 @@ msgstr "Vaihda"
msgid "Copyright Aalto-yliopiston Sähköinsinöörikilta ry" msgid "Copyright Aalto-yliopiston Sähköinsinöörikilta ry"
msgstr "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" msgid "Webapp"
msgstr "Nettisivut" msgstr "Nettisivut"
#: webapp/models.py:26 #: webapp/models.py:28
msgid "Tag" msgid "Tag"
msgstr "Tunniste" msgstr "Tunniste"
#: webapp/models.py:27 #: webapp/models.py:29
msgid "Tags" msgid "Tags"
msgstr "Tunnisteet" msgstr "Tunnisteet"
#: webapp/models.py:30 #: webapp/models.py:32
msgid "Tag: {}" msgid "Tag: {}"
msgstr "Tunniste: {}" msgstr "Tunniste: {}"
#: webapp/models.py:50 #: webapp/models.py:52
msgid "Feed: {}" msgid "Feed: {}"
msgstr "Uutinen: {}" msgstr "Uutinen: {}"
#: webapp/models.py:53 #: webapp/models.py:55
msgid "Feed" msgid "Feed"
msgstr "Uutinen" msgstr "Uutinen"
#: webapp/models.py:54 #: webapp/models.py:56
msgid "Feeds" msgid "Feeds"
msgstr "Uutiset" msgstr "Uutiset"
#: webapp/models.py:66 #: webapp/models.py:68
msgid "Event: {}" msgid "Event: {}"
msgstr "Tapahtuma: {}" msgstr "Tapahtuma: {}"
#: webapp/models.py:69 #: webapp/models.py:71
msgid "Event" msgid "Event"
msgstr "Tapahtuma" msgstr "Tapahtuma"
#: webapp/models.py:81 #: webapp/models.py:83
msgid "Registration: {}" msgid "Registration: {}"
msgstr "Registration: {}" msgstr "Registration: {}"
#: webapp/models.py:84 #: webapp/models.py:86
msgid "Registration" msgid "Registration"
msgstr "Ilmoittautuminen" msgstr "Ilmoittautuminen"
#: webapp/models.py:85 #: webapp/models.py:87
msgid "Registrations" msgid "Registrations"
msgstr "Ilmoittautumiset" msgstr "Ilmoittautumiset"
#: webapp/models.py:92 #: webapp/models.py:94 webapp/models.py:166
msgid "Board member" msgid "Board member"
msgstr "Hallituksen jäsen" msgstr "Hallituksen jäsen"
#: webapp/models.py:98 #: webapp/models.py:98
msgid "board member"
msgstr "Hallituksen jäsen"
#: webapp/models.py:104
msgid "Description" msgid "Description"
msgstr "Kuvaus" msgstr "Kuvaus"
#: webapp/models.py:99 #: webapp/models.py:105
msgid "Summary" msgid "Summary"
msgstr "Tiivistelmä" 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" msgid "Message"
msgstr "Viesti" 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" msgid "Year"
msgstr "Vuosi" 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" msgid "Role"
msgstr "Rooli" msgstr "Rooli"
#: webapp/models.py:156 #: webapp/models.py:211
msgid "Start date" msgid "Start date"
msgstr "Alkupäivämäärä" msgstr "Alkupäivämäärä"
#: webapp/models.py:157 #: webapp/models.py:212
msgid "End date" msgid "End date"
msgstr "Loppupäivämäärä" msgstr "Loppupäivämäärä"
#: webapp/models.py:167 #: webapp/models.py:222
msgid "Official" msgid "Official"
msgstr "Toimihenkilö" msgstr "Toimihenkilö"
#: webapp/models.py:169
msgid "Phone number"
msgstr "Puhelinnumero"
#: webapp/templates/admin_index.html:6 #: webapp/templates/admin_index.html:6
msgid "SIK Admin" msgid "SIK Admin"
msgstr "SIK Hallintapaneeli" msgstr "SIK Hallintapaneeli"
@@ -662,6 +711,52 @@ msgstr "International"
msgid "Jobs" msgid "Jobs"
msgstr "Työpaikat" 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 #: webapp/templates/login.html:25 webapp/templates/login.html:27
msgid "Username" msgid "Username"
msgstr "Käyttäjänimi" msgstr "Käyttäjänimi"
@@ -710,5 +805,11 @@ msgstr "Kaikki haasteet"
msgid "Total challenges:" msgid "Total challenges:"
msgstr "Haasteita yhteensä:" msgstr "Haasteita yhteensä:"
#~ msgid "Roles"
#~ msgstr "Roolit"
#~ msgid "Apply"
#~ msgstr "Hakulomake"
#~ msgid "language" #~ msgid "language"
#~ msgstr "Kieli" #~ msgstr "Kieli"
+50 -2
View File
@@ -1,11 +1,59 @@
"""File containing webapp forms."""
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ 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 OhlhafvForm(forms.ModelForm):
"""Class representing Ohlhafv form."""
class Meta: class Meta:
"""Meta class for Ohlhafv form."""
model = OhlhafvChallenge model = OhlhafvChallenge
fields = ['challenger', 'challenger_email', 'victim', 'victim_email', 'series', 'message'] fields = ['challenger', 'challenger_email',
'victim', 'victim_email', 'series', 'message']
@@ -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'),
),
]
+20
View File
@@ -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'),
),
]
@@ -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'),
),
]
@@ -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'),
),
]
@@ -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'),
),
]
@@ -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,
),
]
@@ -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 = [
]
@@ -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'),
),
]
@@ -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',
),
]
@@ -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'),
),
]
@@ -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'),
),
]
@@ -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'),
),
]
@@ -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'},
),
]
+63 -8
View File
@@ -11,6 +11,8 @@ from auditlog.registry import auditlog
from phonenumber_field.modelfields import PhoneNumberField from phonenumber_field.modelfields import PhoneNumberField
from django.contrib.postgres.fields import JSONField from django.contrib.postgres.fields import JSONField
import logging
VERBOSE_NAME = _('Webapp') VERBOSE_NAME = _('Webapp')
@@ -91,6 +93,10 @@ class BaseRole(models.Model):
name = models.CharField(_('Name'), max_length=255) name = models.CharField(_('Name'), max_length=255)
is_board = models.BooleanField(_('Board member')) 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): class PresetRole(BaseRole):
"""Model representing a preset occupation in the guild.""" """Model representing a preset occupation in the guild."""
@@ -102,17 +108,26 @@ class PresetRole(BaseRole):
class PresetKaehmyRole(PresetRole): class PresetKaehmyRole(PresetRole):
"""Model for kaehmy role.""" """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): class CustomKaehmyRole(BaseRole):
"""Model representing a user-specified custom occupation.""" """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): 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): class KaehmyMessage(MessageParent):
@@ -122,10 +137,9 @@ class KaehmyMessage(MessageParent):
Every message relates to certain kaehmyform or parent message. Every message relates to certain kaehmyform or parent message.
""" """
name = models.CharField(_('Name'), max_length=255)
email = models.EmailField(_('Email'))
message = models.TextField(_('Message')) message = models.TextField(_('Message'))
parent = models.ForeignKey('MessageParent', related_name='messages') parent = models.ForeignKey('MessageParent', related_name='messages')
timestamp = models.DateTimeField(_('Timestamp'), default=timezone.now)
class KaehmyForm(MessageParent): class KaehmyForm(MessageParent):
@@ -134,10 +148,51 @@ class KaehmyForm(MessageParent):
Allows user to choose from existing roles or to create custom ones. 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) phone_number = models.CharField(
email = models.EmailField(_('Email')) _('Phone number'), max_length=10, default="")
year = models.IntegerField(_('Year')) 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): class Role(PresetRole):
+3
View File
@@ -0,0 +1,3 @@
.kaehmy_navigation {
margin-bottom: 10px;
}
+1 -1
View File
@@ -6,7 +6,7 @@
} }
body { body {
max-width: 700px; max-width: 1000px;
margin-left: auto !important; margin-left: auto !important;
margin-right: auto !important; margin-right: auto !important;
} }
+9 -3
View File
@@ -16,17 +16,23 @@
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="{% static "js/lib/jquery-3.1.0.min.js" %}"></script> <script src="{% static "js/lib/jquery-3.1.0.min.js" %}"></script>
<script src="{% static "js/lib/bootstrap.min.js" %}"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
<link rel="stylesheet" href="{% static "css/lib/bootstrap.min.css" %}"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="{% static "js/lib/underscore-min.js" %}"></script> <script src="{% static "js/lib/underscore-min.js" %}"></script>
</head> </head>
<body> <body>
{% block header %}
<div class="header"> <div class="header">
{% include "sik_header.html" %} {% include "sik_header.html" %}
</div> </div>
{% endblock %}
<div class="page-content"> <div class="page-content">
{% include "navigation.html" %} {% block navigation %}
{% include "navigation.html" %}
{% endblock %}
{% block content %} {% block content %}
{% endblock %} {% endblock %}
</div> </div>
+10
View File
@@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block navigation %}
{% endblock navigation %}
{% block content %}
<div class="alert alert-danger" role="alert">
{{ errors|safe }}
</div>
{% endblock content %}
+25
View File
@@ -0,0 +1,25 @@
{% extends "base.html" %}
{% load bootstrap3 %}
{% load i18n %}
{% block navigation %}
{% include "kaehmy_navigation.html" %}
{% endblock %}
{% block content %}
<div>
<h3 style="padding-top: 1rem">{% trans "Kaehmy" %}</h3>
<div id="input_form">
<form name="kaehmyForm" action="/kaehmy/submit/" method="post" class="form">{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% trans "Submit" %}
</button>
{% endbuttons %}
</form>
</div>
</div>
{% endblock content %}
+89
View File
@@ -0,0 +1,89 @@
{% extends "base.html" %}
{% load static %}
{% load i18n %}
{% block navigation %}
{% include "kaehmy_navigation.html" %}
{% endblock %}
{% block content %}
<script>
function commentOn(id, op) {
setTimeout(function() {
document.getElementById("commentNameField").focus();
}, 50);
document.getElementById("collapse_add_comment").scrollIntoView();
document.getElementById("commentOP").innerHTML = op;
document.getElementById("commentId").value = id;
}
</script>
<div>
<div>
<h2 style="padding-top: 1rem">{% trans "All kaehmys" %}</h2>
</div>
<div>
<h6 style="padding-bottom: 1rem">{% trans "Total kaehmys:" %} {{ application_count }}</h6>
</div>
<div class="collapse" id="collapse_add_comment">
<div class="card">
<div class="card-block">
<form method="POST" action="/kaehmy/add_comment" class="form">{% csrf_token %}
<div class="form-group">
{% trans "Commenting on post by " %} <span id="commentOP"></span>
<input type="hidden" name="parent" id="commentId">
</div>
<div class="form-group">
<label>{% trans "Name" %}</label>
<input id="commentNameField" name="name" type="text" class="form-control" placeholder="Teemu Teekkari">
</div>
<div class="form-group">
<label>{% trans "Email" %}</label>
<input name="email" type="email" class="form-control" placeholder="teemu@teekka.ri">
</div>
<div class="form-group">
<label>{% trans "Comment" %}</label>
<textarea name="message" class="form-control" rows=3 placeholder="Hei!"></textarea>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value={% trans "Send" %}>
</div>
</form>
</div>
</div>
</div>
{% for application in applications %}
<div class="card">
<h4 class="card-header">{{ application.name }}</h4>
<div class="card-block">
<h5 style="padding-bottom: 1rem" class="card-subtitle mb-2 text-muted">{{ application.all_roles }}</h5>
<p class="card-text">{{ application.text }}</p>
{% if application.comment_count > 0 %}
<a type="button" style="cursor: pointer" data-toggle="collapse" data-target="#collapse_{{ application.id }}" aria-expanded="false" aria-controls="collapse_{{ application.id }}">
{% trans "Show comments" %} ({{ application.comment_count }})
</a>
{% endif %}
<div>
<a type="button" onclick="commentOn({{ application.id }}, '{{ application.name }}')" style="cursor: pointer" data-toggle="collapse" data-target="#collapse_add_comment" aria-expanded="false" aria-controls="collapse_add_comment">
{% trans "Add comment" %}
</a>
</div>
<div class="collapse" id="collapse_{{ application.id }}">
{% for message in application.messages.all %}
{% include "kaehmy_message.html" with messages=message.messages.all %}
{% endfor %}
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
+21
View File
@@ -0,0 +1,21 @@
{% load i18n %}
<div class="card" style="margin-top: 0.5rem; margin-bottom: 0">
<div class="card-block">
<h4>{{ message.name }}</h4>
<p>{{ message.message }}</p>
<h6 class="card-subtitle mb-2 text-muted">{{ message.timestamp }}</h6>
<div>
<a type="button" onclick="commentOn({{ message.id }}, '{{ message.name }}')" style="cursor: pointer" data-toggle="collapse" data-target="#collapse_add_comment" aria-expanded="false" aria-controls="collapse_add_comment">
{% trans "Reply" %}
</a>
</div>
<div>
{% for message in messages %}
{% include "kaehmy_message.html" with messages=message.messages.all %}
{% endfor %}
</div>
</div>
</div>
+16
View File
@@ -0,0 +1,16 @@
{% load i18n %}
<link rel="stylesheet" href="/static/css/kaehmy_nav.css">
<div class="kaehmy_navigation">
<nav style="border-bottom: 2px solid #282b3b" class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#kaehmy_nav" aria-controls="kaehmy_nav" aria-expanded="false" aria-label="Toggle navigation">
Menu<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="kaehmy_nav">
<div class="navbar-nav">
<a class="nav-item nav-link" href="/kaehmy">{% trans "List kaehmys" %}</a>
<a class="nav-item nav-link" href="/kaehmy/new">{% trans "New kaehmy" %} <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="/kaehmy/statistics">{% trans "Statistics" %}</a>
</div>
</div>
</nav>
</div>
+23
View File
@@ -0,0 +1,23 @@
{% extends "base.html" %}
{% load bootstrap3 %}
{% load i18n %}
{% block navigation %}
{% include "kaehmy_navigation.html" %}
{% endblock %}
{% block content %}
<div>
<h3>{% trans "Statistics" %}</h3>
<div>
<h6>{% trans "Total kaehmys:" %} {{ application_count }}</h6>
</div>
{% for role in role_list %}
<div>
<p>{{ role.0 }} ({{ role.1 }})</p>
</div>
{% endfor %}
</div>
{% endblock content %}
+1 -1
View File
@@ -12,7 +12,7 @@
</div> </div>
<div class="ohlhafv_count"> <div class="ohlhafv_count">
<span>{% trans "Total challenges:" %} {{ challenge_count }}</span> <span>{% trans "Total challenges:" %}{{ application_count }}</span>
</div> </div>
{{ table|safe }} {{ table|safe }}
+1 -1
View File
@@ -3,6 +3,6 @@
<div class="header-content"> <div class="header-content">
<div class="logo"> <div class="logo">
<a href="/"><img src="/static/img/logo_header.png" alt="Shiit ei kuvaa"></a> <a href="/kaehmy"><img src="/static/img/logo_header.png" alt="Aalto-yliopiston Sähköinsinöörikilta ry"></a>
</div> </div>
</div> </div>
+15 -1
View File
@@ -18,6 +18,11 @@ from webapp.views import event_calendar_view
from webapp.views import international_view from webapp.views import international_view
from webapp.views import sosso_view from webapp.views import sosso_view
from webapp.views import contact_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 = [ urlpatterns = [
# main # main
@@ -30,6 +35,8 @@ urlpatterns = [
# git revision # git revision
url(r'^about', about_view), url(r'^about', about_view),
# pages
url(r'^guild', guild_view), url(r'^guild', guild_view),
url(r'^freshmen', freshmen_view), url(r'^freshmen', freshmen_view),
url(r'^event_calendar', event_calendar_view), url(r'^event_calendar', event_calendar_view),
@@ -40,8 +47,15 @@ urlpatterns = [
# corporate # corporate
url(r'^jobs', jobs_view), 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 # ohlhafv
url(r'^ohlhafv$', ohlhafv_view),
url(r'^ohlhafv/submit', ohlhafv_submit), url(r'^ohlhafv/submit', ohlhafv_submit),
url(r'^ohlhafv/list', ohlhafv_list), url(r'^ohlhafv/list', ohlhafv_list),
url(r'^ohlhafv', ohlhafv_view),
] ]
+123 -2
View File
@@ -8,10 +8,27 @@ from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import permission_required, login_required from django.contrib.auth.decorators import permission_required, login_required
from django.conf import settings from django.conf import settings
import logging import logging
from webapp.models import OhlhafvChallenge from webapp.models import PresetKaehmyRole, CustomKaehmyRole
from webapp.forms import OhlhafvForm from webapp.models import OhlhafvChallenge, KaehmyForm
from webapp.forms import OhlhafvForm, KaehmyForm_Form, KaehmyCommentForm
from webapp.tables import OhlhafvTable 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"]) @require_http_methods(["GET"])
def main_index(request, *args, **kwargs): def main_index(request, *args, **kwargs):
@@ -106,6 +123,46 @@ def contact_view(request, *args, **kwargs):
return render(request, "contact.html", {}) 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"]) @require_http_methods(["GET"])
def ohlhafv_view(request, *args, **kwargs): def ohlhafv_view(request, *args, **kwargs):
"""Render Ohlhafv form page.""" """Render Ohlhafv form page."""
@@ -146,3 +203,67 @@ def ohlhafv_list(request, *args, **kwargs):
'challenge_count': len(challenges), 'challenge_count': len(challenges),
} }
return render(request, 'ohlhafv_list.html', context) 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)