Add custom role creation to kaehmy form

This commit is contained in:
henu
2017-10-11 20:26:38 +03:00
parent d349916fef
commit 2cf41c9cb9
4 changed files with 45 additions and 8 deletions
+2 -4
View File
@@ -6,13 +6,11 @@ from webapp.models import OhlhafvChallenge, KaehmyForm
class KaehmyForm_Form(forms.ModelForm): class KaehmyForm_Form(forms.ModelForm):
custom_role_name = forms.TextInput(
attrs={'size': 10, 'title': 'Name of the role', })
class Meta: class Meta:
model = KaehmyForm model = KaehmyForm
fields = ['name', 'email', 'year', fields = ['name', 'email', 'year',
'preset_roles', 'custom_roles', 'text'] 'preset_roles', 'custom_roles', 'custom_role_name',
'custom_role_is_board', 'text']
class OhlhafvForm(forms.ModelForm): class OhlhafvForm(forms.ModelForm):
@@ -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'),
),
]
+11 -3
View File
@@ -119,7 +119,7 @@ class KaehmyFormSelectedRole(models.Model):
class MessageParent(models.Model): class MessageParent(models.Model):
def __str__(self): def __str__(self):
return 'Message parent #{}'.format(self.id) return 'Message parent #{}'.format(self.id)
@@ -156,13 +156,21 @@ class KaehmyForm(MessageParent):
email = models.EmailField(_('Email')) email = models.EmailField(_('Email'))
year = models.IntegerField(_('Year'), choices=YEAR_CHOICES) year = models.IntegerField(_('Year'), choices=YEAR_CHOICES)
text = models.TextField(_('Text'), default="", max_length=300) text = models.TextField(_('Text'), default="", max_length=300)
custom_roles = models.ManyToManyField('CustomKaehmyRole', related_name='forms', blank=True) custom_roles = models.ManyToManyField(
preset_roles = models.ManyToManyField('PresetKaehmyRole', related_name='forms', blank=True) 'CustomKaehmyRole', related_name='forms', blank=True)
preset_roles = models.ManyToManyField(
'PresetKaehmyRole', related_name='forms', blank=True)
custom_role_name = models.CharField(
_('Custom role name'), max_length=255, default="")
custom_role_is_board = models.BooleanField(
_('Board member'), default=False)
def __str__(self): def __str__(self):
"""Return model info."""
return _('Kaehmy application: {}').format(self.name) return _('Kaehmy application: {}').format(self.name)
def comment_count(self): def comment_count(self):
"""Count comments for kaehmy."""
total = 0 total = 0
def recurse(message): def recurse(message):
+7 -1
View File
@@ -8,6 +8,7 @@ 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 CustomKaehmyRole
from webapp.models import OhlhafvChallenge, KaehmyForm from webapp.models import OhlhafvChallenge, KaehmyForm
from webapp.forms import OhlhafvForm, KaehmyForm_Form from webapp.forms import OhlhafvForm, KaehmyForm_Form
from webapp.tables import OhlhafvTable from webapp.tables import OhlhafvTable
@@ -120,6 +121,11 @@ def kaehmy_submit(request, *args, **kwargs):
form = KaehmyForm_Form(request.POST) form = KaehmyForm_Form(request.POST)
if form.is_valid(): if form.is_valid():
form.save() form.save()
custom_name = form.cleaned_data.get('custom_role_name')
custom_is_board = form.cleaned_data.get('custom_role_is_board')
custom_role = CustomKaehmyRole(
name=custom_name, is_board=custom_is_board)
custom_role.save()
else: else:
pass pass
# return render(request, 'error.html', {'error': form.errors}) # return render(request, 'error.html', {'error': form.errors})
@@ -174,7 +180,7 @@ def kaehmy_list_view(request, *args, **kwargs):
"""Kaehmy application list""" """Kaehmy application list"""
applications = KaehmyForm.objects.all() applications = KaehmyForm.objects.all()
context = { context = {
'applications': applications, 'applications': applications,
'application_count': len(applications) 'application_count': len(applications)