nanterre: mettre état civil et adresses en majuscule (fixes #15771)

This commit is contained in:
Benjamin Dauvergne 2017-04-05 15:46:37 +02:00
parent 0f70a1551f
commit 2d52c993b4
4 changed files with 26 additions and 16 deletions

View File

@ -6,4 +6,4 @@ init:
. ~/.virtualenvs/zoo/bin/activate; ./manage.py migrate && ./manage.py loaddata fixtures/admin.json rsu && ./manage.py runserver
publish:
rsync --delete -avz ./* bdauvergne@nanterre.dev:zoo/
rsync --delete -avz ./ bdauvergne@nanterre.dev:zoo/

View File

@ -6,7 +6,7 @@ import datetime
from django.core.urlresolvers import reverse
from zoo.zoo_data.models import Entity, Relation, Log
from zoo.zoo_nanterre.utils import PersonSearch
from zoo.zoo_nanterre.utils import PersonSearch, adresse as get_individu_adresse
def test_person_search(db, rsu):
@ -64,7 +64,7 @@ def test_create_individu(app, rsu_schema):
response = app.post_json(create_url, params={
'prenoms': 'Jean Eude',
'nom_de_naissance': 'Michalon-Gourde',
'nom_d_usage': '',
'nom_d_usage': u'Grégoire',
'date_de_naissance': '1992-03-04',
'genre': 'homme',
'email': '',
@ -78,7 +78,7 @@ def test_create_individu(app, rsu_schema):
'at': '',
'streetnumber': '123',
'streetnumberext': '',
'streetname': 'ALLE DE L\'ARLEQUIN',
'streetname': 'ALLe DE L\'ARLEQUIN',
'ext1': '',
'ext2': '',
'streetmatriculation': '00032',
@ -95,7 +95,11 @@ def test_create_individu(app, rsu_schema):
entity = Entity.objects.get(id=first_id)
assert entity.content['prenoms'] == 'JEAN EUDE'
assert entity.content['nom_de_naissance'] == 'MICHALON-GOURDE'
assert entity.content['nom_d_usage'] == u'GRÉGOIRE'
assert entity.content['date_de_naissance'] == '1992-03-04'
adresse = get_individu_adresse(entity)
assert adresse.content['streetname'] == 'ALLE DE L\'ARLEQUIN'
assert Entity.objects.filter(schema__slug='individu').count() == 1
assert Entity.objects.filter(schema__slug='adresse').count() == 1
@ -106,12 +110,14 @@ def test_create_individu(app, rsu_schema):
'identifier': first_id})
response = app.post_json(update_url, params={
'nom_d_usage': 'Grégorio',
'date_de_naissance': '1991-03-04',
})
assert response.json['err'] == 0
assert response.json['data']['id'] == first_id
entity.refresh_from_db()
assert entity.content['date_de_naissance'] == '1991-03-04'
assert entity.content['nom_d_usage'] == u'GRÉGORIO'
assert Entity.objects.count() == 2
assert Entity.objects.filter(schema__slug='individu').count() == 1

View File

@ -165,11 +165,11 @@ class ReseauView(APIView):
v = serializer.validated_data
individu.modified = transaction
if 'prenoms' in v:
individu.content['prenoms'] = v['prenoms']
individu.content['prenoms'] = v['prenoms'].upper()
if 'nom_de_naissance' in v:
individu.content['nom_de_naissance'] = v['nom_de_naissance']
individu.content['nom_de_naissance'] = v['nom_de_naissance'].upper()
if 'nom_d_usage' in v:
individu.content['nom_d_usage'] = v['nom_d_usage']
individu.content['nom_d_usage'] = v['nom_d_usage'].upper()
if 'date_de_naissance' in v:
individu.content['date_de_naissance'] = v['date_de_naissance'].isoformat()
if 'genre' in v:
@ -186,16 +186,12 @@ class ReseauView(APIView):
individu.content['telephones'] = v['telephones']
individu.save()
if individu.content['statut_legal'] == 'majeur' and utils.ADRESSE_ENT in v:
for adresse, rel in utils.adresses(individu):
adresse.content = v[utils.ADRESSE_ENT]
rel.modified = individu.modified
adresse.save()
rel.save()
break
else: # it should never happen
raise NotImplementedError
adresse = utils.adresse(individu)
adresse.content = v[utils.ADRESSE_ENT]
adresse.modified = individu.modified
adresse.save()
# no need to update children and husband/wife adresses,
# they sould already have the same
# they sould already have the same address
return Response({
'err': 0,
'data': individu_to_response(individu),
@ -281,6 +277,7 @@ class CreateIndividu(APIView):
'email': v['email'],
})
content = v[utils.ADRESSE_ENT].copy()
utils.upper_dict(content)
content['adresse_inconnnue'] = False
individu.save()
adresse = Entity.objects.create(

View File

@ -483,3 +483,10 @@ def integrity_check():
if key.content['statut_legal'] == 'mineur' and value > 2:
yield ("l'enfant %s n'a pas d'adresse" % key)
def upper_dict(d):
'''Transform all string values in d to uppercase'''
for key, value in d.items():
if isinstance(value, unicode):
d[key] = value.upper()