make date fields timezone aware and ignore them if empty

This commit is contained in:
Serghei Mihai 2014-09-24 17:22:02 +02:00
parent 8105c94198
commit 44e0786840
1 changed files with 6 additions and 1 deletions

View File

@ -5,6 +5,7 @@ from datetime import datetime
from django.db import models, transaction
from django.conf import settings
from django.utils.timezone import make_aware, get_current_timezone
SEXES = (
('G', 'Homme'),
@ -182,7 +183,11 @@ class FactureManager(models.Manager):
for date_type in ('date_generation', 'date_limite_paie',
'debut_pge', 'fin_pge', 'date_reglement',
'date_passage_perception'):
params[date_type] = datetime.strptime(params[date_type], INPUT_DATE_FORMAT)
try:
params[date_type] = datetime.strptime(params[date_type], INPUT_DATE_FORMAT)
params[date_type] = make_aware(params[date_type], get_current_timezone())
except ValueError:
params.pop(date_type)
params['active'] = path.exists(settings.INVOICES_LOCATION_PATTERN.format(invoice_id = params['id']))
family = Famille.objects.get(pk = params.pop('famille'))
params['famille'] = family