Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# (c) 2018-2020
2# MPIB <https://www.mpib-berlin.mpg.de/>,
3# MPI-CBS <https://www.cbs.mpg.de/>,
4# MPIP <http://www.psych.mpg.de/>
5#
6# This file is part of Castellum.
7#
8# Castellum is free software; you can redistribute it and/or modify it
9# under the terms of the GNU Affero General Public License as published
10# by the Free Software Foundation; either version 3 of the License, or
11# (at your option) any later version.
12#
13# Castellum is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public
19# License along with Castellum. If not, see
20# <http://www.gnu.org/licenses/>.
22from django import forms
23from django.utils.translation import gettext_lazy as _
26def _get_age_fields():
27 return [
28 forms.IntegerField(error_messages={}, min_value=0, max_value=1000),
29 forms.ChoiceField(choices=[
30 ('years', _('years')),
31 ('months', _('months')),
32 ('days', _('days')),
33 ]),
34 ]
37class AgeWidget(forms.MultiWidget):
38 template_name = 'recruitment/age_widget.html'
40 def __init__(self, attrs=None):
41 widgets = [field.widget for field in _get_age_fields()]
42 super().__init__(widgets, attrs)
44 def decompress(self, value):
45 if value: 45 ↛ 46line 45 didn't jump to line 46, because the condition on line 45 was never true
46 return list(value)
47 else:
48 return [None, None]
51class AgeField(forms.MultiValueField):
52 widget = AgeWidget
54 def __init__(self, **kwargs):
55 super().__init__(fields=_get_age_fields(), **kwargs)
57 def compress(self, value):
58 return tuple(value)