travel grant fields in registration (germany only)
authorJan Szejko <janek37@gmail.com>
Fri, 21 Jul 2017 13:34:05 +0000 (15:34 +0200)
committerJan Szejko <janek37@gmail.com>
Fri, 21 Jul 2017 13:34:05 +0000 (15:34 +0200)
prawokultury/contact_forms.py
prawokultury/countries.py
prawokultury/settings.d/50-static.py
prawokultury/static/css/forms.css
prawokultury/static/css/forms.scss
prawokultury/static/js/optional_fields.js [new file with mode: 0644]
prawokultury/templates/contact/register/form.html
prawokultury/templates/snippets/field_as_table_row.html

index 6a5130f..8bd07eb 100644 (file)
@@ -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 (
index 9455b3c..8f95ff6 100644 (file)
@@ -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
index c5986ae..893848a 100644 (file)
@@ -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',
index d6d5d74..44309ec 100644 (file)
@@ -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 */
index 347a946..f3dffd4 100644 (file)
         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 (file)
index 0000000..cfbae0e
--- /dev/null
@@ -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');
+
+});
index 8bb88ca..c58cec5 100644 (file)
   {% endif %}
 {% endif %}
 
-<script type="text/javascript" src="/static/js/prefill.js"></script>
+<script type="text/javascript">
+    var travelGrantCountries = [
+    {% for country in form.travel_grant_countries %}
+        '{{ country }}'{% if not forloop.last %},{% endif %}
+    {% endfor %}
+    ];
+</script>
 
 {% endblock %}
index 5dcc98e..c98b92f 100644 (file)
@@ -1,4 +1,4 @@
 <tr{% if field.css_classes %} class="{{ field.css_classes }}"{% endif %}>
   <th>{{ field.label_tag }}</th>
-  <td>{{ field.errors }}{{ field }}{% if field.help_text %}<br /><span class="helptext">{{ field.help_text }}</span>{% endif %}</td>
+  <td><span class="error">{{ field.errors }}</span>{{ field }}{% if field.help_text %}<br /><span class="helptext">{{ field.help_text }}</span>{% endif %}</td>
 </tr>
\ No newline at end of file