Skip to content

Commit

Permalink
Bug 859564: Make 'expected_graduation_year' field required when student.
Browse files Browse the repository at this point in the history
  • Loading branch information
glogiotatidis authored and pmac committed May 9, 2013
1 parent 67c8cea commit 0188a5a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions apps/mozorg/forms.py
Expand Up @@ -11,7 +11,7 @@

from django import forms
from django.conf import settings
from django.forms import ValidationError, widgets
from django.forms import widgets
from django.utils.safestring import mark_safe

import basket
Expand Down Expand Up @@ -257,8 +257,9 @@ def __init__(self, *args, **kwargs):
def clean(self, *args, **kwargs):
super(ContributeUniversityAmbassadorForm, self).clean(*args, **kwargs)
if (self.cleaned_data.get('current_status', '') == 'student'
and not self.cleaned_data.get('expected_graduation_year', '')):
raise ValidationError(_('Select graduation year'))
and not self.cleaned_data.get('expected_graduation_year', '')):
self._errors['expected_graduation_year'] = (
self.error_class([_('This field is required.')]))
return self.cleaned_data

def clean_expected_graduation_year(self):
Expand All @@ -279,7 +280,7 @@ def newsletters(self):
'nl_firefox_flicks', 'nl_about_mozilla']:
if self.cleaned_data.get(newsletter, False):
newsletters.append(newsletter[3:].replace('_', '-'))
return ','.join(newsletters)
return newsletters

def save(self):
data = self.cleaned_data
Expand Down
Expand Up @@ -61,12 +61,17 @@ <h3>{{ _('School Information') }}</h3>
<div class="field">
{{ field_with_attrs(form.current_status, required='required') }}
<span class="required">*</span>
<div class="field {% if not form.expected_graduation_year.value() and not form.non_field_errors() %} hide {% endif %}"
<div class="field {% if not form.expected_graduation_year.value() and not form.expected_graduation_year.errors %} hide {% endif %}"
id="expected_graduation_year">
{{ field_with_attrs(form.expected_graduation_year)|safe }}
{% if not form.expected_graduation_year.value() and not form.expected_graduation_year.errors %}
{{ form.expected_graduation_year }}
{% else %}
{{ field_with_attrs(form.expected_graduation_year, required='required') }}
{% endif %}
<span class="required">*</span>
</div>
{{ form.current_status.errors }}
{{ form.non_field_errors() }}
{{ form.expected_graduation_year.errors }}
</div>
<div class="field">
{{ form.area }}
Expand All @@ -86,7 +91,7 @@ <h3>{{ _('School Information') }}</h3>
<div class="field field-privacy">
<label for="id_age_confirmation">
{{ field_with_attrs(form.age_confirmation, required='required') }}
{{ field_with_attrs(form.age_confirmation) }}
{{ field_with_attrs(form.age_confirmation) }}
<span class="title">{{ form.age_confirmation.label }}</span>
</label>
{{ form.age_confirmation.errors }}
Expand Down
2 changes: 1 addition & 1 deletion apps/mozorg/tests/test_views.py
Expand Up @@ -66,7 +66,7 @@ def test_subscribe(self, mock_subscribe, mock_request):
with self.activate('en-US'):
c.post(reverse('mozorg.contribute_university_ambassadors'), data)
mock_subscribe.assert_called_with(
data['email'], 'ambassadors,about-mozilla', format=u'H',
data['email'], ['ambassadors', 'about-mozilla'], format=u'H',
country=u'gr', source_url=u'',
welcome_message='Student_Ambassadors_Welcome')
mock_request.assert_called_with('post',
Expand Down
2 changes: 2 additions & 0 deletions media/js/contribute-university-ambassadors.js
Expand Up @@ -7,10 +7,12 @@ $(document).ready(function(){
function toggle_field(field, cmp, value) {
if (cmp.value === value) {
field.parent().slideDown();
field.attr('required', 'required');
}
else {
field.parent().slideUp();
field.val('');
field.removeAttr('required');
}
}
$current_status_obj.on('change', function() {
Expand Down

0 comments on commit 0188a5a

Please sign in to comment.