From 8188bfc6cd9c651521d47ae5250c9c26b8039496 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Fri, 21 Jul 2017 15:34:05 +0200 Subject: [PATCH] travel grant fields in registration (germany only) --- prawokultury/contact_forms.py | 36 ++++++++++++++++--- prawokultury/countries.py | 8 +++++ prawokultury/settings.d/50-static.py | 1 + prawokultury/static/css/forms.css | 4 +++ prawokultury/static/css/forms.scss | 4 +++ prawokultury/static/js/optional_fields.js | 22 ++++++++++++ .../templates/contact/register/form.html | 8 ++++- .../snippets/field_as_table_row.html | 2 +- 8 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 prawokultury/static/js/optional_fields.js diff --git a/prawokultury/contact_forms.py b/prawokultury/contact_forms.py index 6a5130f..8bd07eb 100644 --- a/prawokultury/contact_forms.py +++ b/prawokultury/contact_forms.py @@ -11,7 +11,7 @@ from django.utils.translation import ugettext_noop as _ from django.utils.safestring import mark_safe from migdal.models import Entry -from prawokultury.countries import COUNTRIES +from prawokultury.countries import COUNTRIES, TRAVEL_GRANT_COUNTRIES mark_safe_lazy = lazy(mark_safe, unicode) @@ -26,12 +26,22 @@ class RegistrationForm(ContactForm): form_title = _('Registration') admin_list = ['first_name', 'last_name', 'organization'] + travel_grant_countries = TRAVEL_GRANT_COUNTRIES + first_name = forms.CharField(label=_('First name'), max_length=128) last_name = forms.CharField(label=_('Last name'), max_length=128) contact = forms.EmailField(label=_('E-mail'), max_length=128) - organization = forms.CharField(label=_('Organization'), - max_length=256, required=False) - country = forms.ChoiceField(label=_('Country'), choices=zip(COUNTRIES, COUNTRIES)) + organization = forms.CharField(label=_('Organization'), max_length=256, required=False) + country = forms.ChoiceField(label=_('Country of residence'), choices=zip(COUNTRIES, COUNTRIES)) + travel_grant = forms.BooleanField( + label=_('I require financial assistance to attend CopyCamp 2017.'), required=False) + travel_grant_motivation = forms.CharField( + label=_('Please write us about yourself and why you want to come to CopyCamp. ' + 'This information will help us evaluate your travel grant application:'), + help_text=_('Financial assistance for German audience is possible ' + 'thanks to the funds of the German Federal Foreign Office transferred by ' + 'the Foundation for Polish-German Cooperation.'), + widget=forms.Textarea, max_length=600, required=False) days = forms.ChoiceField( label=_("I'm planning to show up on"), @@ -144,8 +154,24 @@ class RegistrationForm(ContactForm): raise forms.ValidationError(_('Select at most 3 areas')) return data + def clean(self): + cleaned_data = self.cleaned_data + country = cleaned_data['country'] + travel_grant = cleaned_data['travel_grant'] + motivation = cleaned_data['travel_grant_motivation'] + if country not in self.travel_grant_countries and travel_grant: + raise forms.ValidationError(_('Travel grant is not provided for the selected country')) + if travel_grant and not motivation: + self._errors['travel_grant_motivation'] = _('Please provide this information') + raise forms.ValidationError(_('To apply for a travel grant you must provide additional information.')) + if not travel_grant and motivation: + cleaned_data['motivation'] = '' + return cleaned_data + def main_fields(self): - return [self[name] for name in ('first_name', 'last_name', 'contact', 'organization', 'country', 'days')] + return [self[name] for name in ( + 'first_name', 'last_name', 'contact', 'organization', 'country', + 'travel_grant', 'travel_grant_motivation', 'days')] def survey_fields(self): return [self[name] for name in ( diff --git a/prawokultury/countries.py b/prawokultury/countries.py index 9455b3c..8f95ff6 100644 --- a/prawokultury/countries.py +++ b/prawokultury/countries.py @@ -257,3 +257,11 @@ COUNTRIES = [ u"Zambia", u"Zimbabwe", ] + +TRAVEL_GRANT_COUNTRIES = [ + # u"Czech Republic", + u"Germany", + # u"Hungary", + # u"Poland", + # u"Slovakia", +] \ No newline at end of file diff --git a/prawokultury/settings.d/50-static.py b/prawokultury/settings.d/50-static.py index c5986ae..893848a 100644 --- a/prawokultury/settings.d/50-static.py +++ b/prawokultury/settings.d/50-static.py @@ -38,6 +38,7 @@ PIPELINE_JS = { 'source_filenames': ( 'js/promobox.js', 'js/workshop_form.js', + 'js/optional_fields.js', 'contrib/lightbox/js/lightbox.min.js', ), 'output_filename': 'compressed/base.js', diff --git a/prawokultury/static/css/forms.css b/prawokultury/static/css/forms.css index d6d5d74..44309ec 100644 --- a/prawokultury/static/css/forms.css +++ b/prawokultury/static/css/forms.css @@ -18,6 +18,8 @@ padding: 0 0 0 1.3em; margin: 0 0 .5em 0; list-style: url("/static/img/read-more.png"); } + .submit-form span.error { + color: #e41b13; } .submit-form input, .submit-form textarea, .submit-form select { font-size: 1.2em; background-color: white; @@ -54,3 +56,5 @@ content: none; } .submit-form input[type="radio"] { width: auto; } + +/*# sourceMappingURL=forms.css.map */ diff --git a/prawokultury/static/css/forms.scss b/prawokultury/static/css/forms.scss index 347a946..f3dffd4 100644 --- a/prawokultury/static/css/forms.scss +++ b/prawokultury/static/css/forms.scss @@ -29,6 +29,10 @@ list-style: url("/static/img/read-more.png"); } + span.error { + color: #e41b13; + } + input, textarea, select { font-size: 1.2em; background-color: white; diff --git a/prawokultury/static/js/optional_fields.js b/prawokultury/static/js/optional_fields.js new file mode 100644 index 0000000..cfbae0e --- /dev/null +++ b/prawokultury/static/js/optional_fields.js @@ -0,0 +1,22 @@ +/* globals travelGrantCountries */ + +$(document).ready(function() { + + var countrySelect = $('#id_country'); + var grantCheckbox = $('#id_travel_grant'); + countrySelect.on('change', function () { + var goodCountry = $.inArray($(this).val(), travelGrantCountries) > -1; + grantCheckbox.closest('tr').toggle(goodCountry); + if (!goodCountry) { + grantCheckbox.prop('checked', false); + grantCheckbox.trigger('change'); + } + }); + grantCheckbox.on('change', function () { + var checked = Boolean(this.checked); + $('#id_travel_grant_motivation').closest('tr').toggle(checked); + }); + countrySelect.trigger('change'); + grantCheckbox.trigger('change'); + +}); diff --git a/prawokultury/templates/contact/register/form.html b/prawokultury/templates/contact/register/form.html index 8bb88ca..c58cec5 100644 --- a/prawokultury/templates/contact/register/form.html +++ b/prawokultury/templates/contact/register/form.html @@ -45,6 +45,12 @@ {% endif %} {% endif %} - + {% endblock %} diff --git a/prawokultury/templates/snippets/field_as_table_row.html b/prawokultury/templates/snippets/field_as_table_row.html index 5dcc98e..c98b92f 100644 --- a/prawokultury/templates/snippets/field_as_table_row.html +++ b/prawokultury/templates/snippets/field_as_table_row.html @@ -1,4 +1,4 @@ {{ field.label_tag }} - {{ field.errors }}{{ field }}{% if field.help_text %}
{{ field.help_text }}{% endif %} + {{ field.errors }}{{ field }}{% if field.help_text %}
{{ field.help_text }}{% endif %} \ No newline at end of file -- 2.20.1