Change custom and preset roles to checkboxes

This commit is contained in:
henu
2017-10-11 23:15:42 +03:00
parent 4e53098e23
commit a7b8be9c87
2 changed files with 13 additions and 4 deletions
+10 -1
View File
@@ -4,10 +4,10 @@ from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
from webapp.models import CustomKaehmyRole, PresetKaehmyRole
from webapp.models import OhlhafvChallenge, KaehmyForm, KaehmyMessage
class KaehmyForm_Form(forms.ModelForm):
"""Class representing Kaehmy form."""
@@ -19,6 +19,15 @@ class KaehmyForm_Form(forms.ModelForm):
'preset_roles', 'custom_roles', 'custom_role_name',
'custom_role_is_board', 'text']
def __init__(self, *args, **kwargs):
super(KaehmyForm_Form, self).__init__(*args, **kwargs)
self.fields["custom_roles"].widget = forms.widgets.CheckboxSelectMultiple()
self.fields["custom_roles"].help_text = ""
self.fields["custom_roles"].queryset = CustomKaehmyRole.objects.all()
self.fields["preset_roles"].widget = forms.widgets.CheckboxSelectMultiple()
self.fields["preset_roles"].help_text = ""
self.fields["preset_roles"].queryset = PresetKaehmyRole.objects.all()
def clean_phone_number(self):
"""Clean phone number field."""
number = self.cleaned_data.get('phone_number')
+3 -3
View File
@@ -151,7 +151,7 @@ def kaehmy_submit(request, *args, **kwargs):
'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)
# send_email(email, subject, body)
logging.debug('Sent kaehmy email to recipient <{}>'.format(email))
else:
context = {
@@ -234,7 +234,7 @@ def kaehmy_comment(request, *args, **kwargs):
send_email(email, subject, body)
logging.debug('Sent kaehmy comment email to recipient <{}>'.format(email))
return redirect('/kaehmy')
else:
print(form)
@@ -258,7 +258,7 @@ def kaehmy_statistics_view(request, *args, **kwargs):
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),