forked from beba/foerderbarometer
properly clean selfbuy data
This commit is contained in:
parent
20e5be26c0
commit
73cd0ff906
|
|
@ -5,6 +5,7 @@ from django.forms import ModelForm
|
||||||
from django.forms.renderers import DjangoTemplates
|
from django.forms.renderers import DjangoTemplates
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils.translation import gettext_lazy as trans
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Project,
|
Project,
|
||||||
|
|
@ -285,6 +286,27 @@ class LiteratureForm(TermsForm):
|
||||||
class Media:
|
class Media:
|
||||||
js = ('dropdown/js/literature.js',)
|
js = ('dropdown/js/literature.js',)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = TermsForm.clean(self)
|
||||||
|
|
||||||
|
if self.errors:
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
|
return self.clean_selfbuy_fields(cleaned_data)
|
||||||
|
|
||||||
|
def clean_selfbuy_fields(self, cleaned_data):
|
||||||
|
if cleaned_data['selfbuy'] == 'TRUE':
|
||||||
|
cleaned_data['selfbuy_data'] = ''
|
||||||
|
cleaned_data['selfbuy_give_data'] = False
|
||||||
|
else:
|
||||||
|
if not cleaned_data.get('selfbuy_data'):
|
||||||
|
self.add_error('selfbuy_data', trans('This field is required.'))
|
||||||
|
|
||||||
|
if not cleaned_data.get('selfbuy_give_data'):
|
||||||
|
self.add_error('selfbuy_give_data', trans('This field is required.'))
|
||||||
|
|
||||||
|
return cleaned_data
|
||||||
|
|
||||||
|
|
||||||
ADULT_CHOICES = {
|
ADULT_CHOICES = {
|
||||||
'TRUE': mark_safe('Ich bin volljährig.'),
|
'TRUE': mark_safe('Ich bin volljährig.'),
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ class AnonymousViewTestCase(TestCase):
|
||||||
'info': 'Test',
|
'info': 'Test',
|
||||||
'source': 'Test',
|
'source': 'Test',
|
||||||
'notes': '',
|
'notes': '',
|
||||||
'selfbuy': 'TRUE',
|
'selfbuy': 'FALSE',
|
||||||
'selfbuy_data': 'NONE',
|
'selfbuy_data': 'Test',
|
||||||
'selfbuy_give_data': True,
|
'selfbuy_give_data': True,
|
||||||
'check': True,
|
'check': True,
|
||||||
'terms_accepted': True,
|
'terms_accepted': True,
|
||||||
|
|
@ -113,8 +113,8 @@ class AnonymousViewTestCase(TestCase):
|
||||||
'source': 'Test',
|
'source': 'Test',
|
||||||
'notes': '',
|
'notes': '',
|
||||||
'selfbuy': 'TRUE',
|
'selfbuy': 'TRUE',
|
||||||
'selfbuy_data': 'NONE',
|
'selfbuy_data': '',
|
||||||
'selfbuy_give_data': True,
|
'selfbuy_give_data': False,
|
||||||
'check': False,
|
'check': False,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,14 +252,7 @@ class ApplicationView(FormView):
|
||||||
|
|
||||||
def prepare_data(self, form):
|
def prepare_data(self, form):
|
||||||
# Collect cleaned data and mark the current type
|
# Collect cleaned data and mark the current type
|
||||||
|
return {**form.cleaned_data, 'choice': self.type_code}
|
||||||
data = {**form.cleaned_data, 'choice': self.type_code}
|
|
||||||
|
|
||||||
# Special rule for literature applications
|
|
||||||
if self.type_code == TYPE_LIT and data.get('selfbuy') == 'TRUE':
|
|
||||||
data['selfbuy_give_data'] = 'False'
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
def save_obj(self, form, data):
|
def save_obj(self, form, data):
|
||||||
# Save model instance
|
# Save model instance
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue