Skip to content

Commit

Permalink
Merge pull request #54 from annttu/birthyear
Browse files Browse the repository at this point in the history
Birthyear and csvbill import fix
  • Loading branch information
annttu committed Jan 1, 2013
2 parents d30db3e + 0bf3ab9 commit 7009974
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
25 changes: 12 additions & 13 deletions membership/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ def __init__(self, *args, **kwargs):
def clean(self, value):
return super(OrganizationRegistrationNumber, self).clean(value).replace(" ", "")

class DateOfBirthField(forms.DateField):
class YearOfBirthField(forms.RegexField):
def __init__(self, *args, **kwargs):
super(DateOfBirthField, self).__init__(initial=date.today,
input_formats = ['%d.%m.%Y','%Y-%m-%d','%m/%d/%Y'],*args, **kwargs)
super(YearOfBirthField, self).__init__(regex=r"^(1[9]|2[01])\d\d$",
min_length=4, max_length=4, *args, **kwargs)

def clean(self, value):
c = super(DateOfBirthField, self).clean(value)
year_ago = date.today() - timedelta(days=365)
years_ago = date.today() - timedelta(days=365 * MAX_AGE)
if c > year_ago:
raise forms.ValidationError(_("You must be at least 1 year old"))
elif c < years_ago:
raise forms.ValidationError(_("You can't be more than %(years)s years old" % {"years":MAX_AGE}))
c = super(YearOfBirthField, self).clean(value)
try:
c = int(c)
if c > datetime.now().year:
raise forms.ValidationError(_('Invalid year of birth'))
except ValueError:
raise forms.ValidationError(_('Invalid year of birth'))
return c


Expand All @@ -72,10 +72,9 @@ class PersonMembershipForm(forms.Form):
municipality = forms.CharField(max_length=30, min_length=2,
label=_('Home municipality'),
help_text=_(u'Finnish municipality'))
birth_date = DateOfBirthField(label=_("Date of birth"),
help_text=_(u'Date of birth on format dd.mm.YYYY'),
birth_year = YearOfBirthField(label=_("Year of birth"),
help_text=_(u'Year of birth on format YYYY'),
required=True)
birth_date.widget.format = '%d.%m.%Y'
extra_info = forms.CharField(label=_('Additional information'),
widget=forms.Textarea(attrs={'cols': '40'}),
required=False,
Expand Down
8 changes: 4 additions & 4 deletions membership/management/commands/csvbills.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,16 @@ def process_csv(file_handle, user=None):
try:
cycle = attach_payment_to_cycle(payment, user=user)
if cycle:
msg = _("Attached payment {payment} to cycle {cycle}"). \
replace("{payment}", unicode(payment)).replace("{cycle}", unicode(cycle))
msg = _("Attached payment %(payment)s to cycle %(cycle)s") % {
'payment': unicode(payment), 'cycle': unicode(cycle)}
logger.info(msg)
return_messages.append(msg)
return_messages.append((None, None, msg))
num_attached = num_attached + 1
sum_attached = sum_attached + payment.amount
else:
# Payment not attached to cycle because enough payments were attached
msg = _("Billing cycle already paid for %s. Payment not attached.") % payment
return_messages.append(msg)
return_messages.append((None, None, msg))
logger.info(msg)
num_notattached = num_notattached + 1
sum_notattached = sum_notattached + payment.amount
Expand Down
4 changes: 2 additions & 2 deletions membership/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Meta:

municipality = models.CharField(_('Home municipality'), max_length=128, blank=True)
nationality = models.CharField(_('Nationality'), max_length=128)
birth_date = models.DateField(_('Date of birth'), null=True, blank=True)
birth_year = models.IntegerField(_('Year of birth'), null=True, blank=True)
organization_registration_number = models.CharField(_('Organization registration number'), max_length=15, null=True, blank=True)

person = models.ForeignKey('Contact', related_name='person_set', verbose_name=_('Person'), blank=True, null=True)
Expand Down Expand Up @@ -322,7 +322,7 @@ def delete_membership(self, user):
self.tech_contact = None
self.organization = None
self.municipality = ''
self.birth_date = None
self.birth_year = None
self.organization_registration_number = None
self.save()
for contact in contacts:
Expand Down
12 changes: 6 additions & 6 deletions membership/templates/membership/new_person_application.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ <h2>Henkilöjäsenen jäsenhakemus</h2>
<span class="error{% if form.municipality.help_text %} newline{% endif %}">{{ error }}</span>
{% endfor %}
</p>
<p{% if form.birth_date.errors %} class="error"{% endif %}>
<label for="id_birth_date">{{ form.birth_date.label }}</label>
{{ form.birth_date }} <span class="required">*</span>
<span class="help">{{ form.birth_date.help_text }}</span>
{% for error in form.birth_date.errors %}
<span class="error{% if form.birth_date.help_text %} newline{% endif %}">{{ error }}</span>
<p{% if form.birth_year.errors %} class="error"{% endif %}>
<label for="id_birth_year">{{ form.birth_year.label }}</label>
{{ form.birth_year }} <span class="required">*</span>
<span class="help">{{ form.birth_year.help_text }}</span>
{% for error in form.birth_year.errors %}
<span class="error{% if form.birth_year.help_text %} newline{% endif %}">{{ error }}</span>
{% endfor %}
</p>

Expand Down
2 changes: 1 addition & 1 deletion membership/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def setUp(self):
"municipality": "Vaasa",
"extra_info": u"Mää oon testikäyttäjä.",
"unix_login": "luser",
"birth_date": "02.02.1993",
"birth_year": "1993",
"email_forward": "y.aikas",
"mysql_database": "yes",
"postgresql_database": "yes",
Expand Down
4 changes: 2 additions & 2 deletions membership/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def person_application(request, template_name='membership/new_person_application
'unix_login', 'extra_info',
'mysql_database', 'postgresql_database',
'login_vhost', 'poll', 'poll_other',
'birth_date']:
'birth_year']:
contact_dict[k] = v

person = Contact(**contact_dict)
Expand All @@ -82,7 +82,7 @@ def person_application(request, template_name='membership/new_person_application
nationality=f['nationality'],
municipality=f['municipality'],
public_memberlist=f['public_memberlist'],
birth_date=f['birth_date'],
birth_year=f['birth_year'],
extra_info=f['extra_info'])
membership.save()

Expand Down
2 changes: 1 addition & 1 deletion sikteeri/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
# encoding: utf-8

VERSION = '''1.2.0'''
VERSION = '''1.2.1'''

0 comments on commit 7009974

Please sign in to comment.