nanterre: ajoute un ws de vision à plat du réseau (fixes #15210)
Ce ws renvoie l'individu ainsi que son conjoint puis ses enfants dans l'ordre du plus agé au plus jeune. Si le paramètre ?conjoint est passé seul le conjoint est retourné, s'il existe. Si le paramètre ?enfants est passé seuls les enfants sont retournés, s'ils existent.
This commit is contained in:
parent
3eb2fc9710
commit
9960472a9b
|
@ -200,7 +200,7 @@ def test_create_individu(app, rsu_schema):
|
|||
'prenoms': u'kévin',
|
||||
'nom_de_naissance': 'Michalon-Gourde',
|
||||
'genre': 'homme',
|
||||
'date_de_naissance': '2016-03-04',
|
||||
'date_de_naissance': '2015-03-04',
|
||||
'email': '',
|
||||
'telephones': [],
|
||||
}
|
||||
|
@ -387,6 +387,32 @@ def test_create_individu(app, rsu_schema):
|
|||
assert data['union']
|
||||
assert data['union_statut'] == 'pacs/mariage'
|
||||
|
||||
# teste du ws reseau-liste
|
||||
reseau_liste_url = reverse('rsu-api-reseau-liste', kwargs={
|
||||
'identifier': second_id,
|
||||
})
|
||||
response = app.get(reseau_liste_url)
|
||||
assert response.json['err'] == 0
|
||||
assert len(response.json['data']) == 4
|
||||
assert all('text' in x for x in response.json['data'])
|
||||
assert response.json['data'][0]['id'] == second_id
|
||||
assert response.json['data'][1]['id'] == first_id
|
||||
assert response.json['data'][2]['id'] == enfant_id
|
||||
assert response.json['data'][3]['id'] == enfant_id_2
|
||||
|
||||
response = app.get(reseau_liste_url + '?conjoint')
|
||||
assert response.json['err'] == 0
|
||||
assert len(response.json['data']) == 1
|
||||
assert all('text' in x for x in response.json['data'])
|
||||
assert response.json['data'][0]['id'] == first_id
|
||||
|
||||
response = app.get(reseau_liste_url + '?enfants')
|
||||
assert response.json['err'] == 0
|
||||
assert len(response.json['data']) == 2
|
||||
assert all('text' in x for x in response.json['data'])
|
||||
assert response.json['data'][0]['id'] == enfant_id
|
||||
assert response.json['data'][1]['id'] == enfant_id_2
|
||||
|
||||
# changement de situation maritale entre les deux adultes
|
||||
changement_de_situation_maritale_url = reverse('rsu-api-changement-de-situation-maritale',
|
||||
kwargs={
|
||||
|
|
|
@ -33,7 +33,8 @@ from zoo.zoo_data.models import Entity, Relation, Transaction, Log
|
|||
from . import utils
|
||||
|
||||
|
||||
def individu_to_response(individu, add_text=False):
|
||||
def individu_to_response(individu, add_text=False, add_conjoint=True, add_enfant=True,
|
||||
add_parents=True):
|
||||
'''Serialize a person'''
|
||||
d = individu.content.copy()
|
||||
d['id'] = individu.id
|
||||
|
@ -48,11 +49,11 @@ def individu_to_response(individu, add_text=False):
|
|||
d['adresses'] = individu.adresses
|
||||
if hasattr(individu, 'responsabilite_legale'):
|
||||
d['responsabilite_legale'] = individu.responsabilite_legale
|
||||
if hasattr(individu, 'enfants'):
|
||||
if add_enfant and hasattr(individu, 'enfants'):
|
||||
d['enfants'] = [individu_to_response(enfant) for enfant in individu.enfants]
|
||||
if hasattr(individu, 'parents'):
|
||||
if add_parents and hasattr(individu, 'parents'):
|
||||
d['parents'] = [individu_to_response(parent) for parent in individu.parents]
|
||||
if hasattr(individu, utils.UNION_REL):
|
||||
if add_conjoint and hasattr(individu, 'union'):
|
||||
d[utils.UNION_REL] = individu_to_response(individu.union)
|
||||
d['union_statut'] = individu.union_statut
|
||||
if add_text:
|
||||
|
@ -200,6 +201,47 @@ class ReseauView(APIView):
|
|||
reseau = non_atomic_requests(ReseauView.as_view())
|
||||
|
||||
|
||||
class ReseauListView(APIView):
|
||||
def get(self, request, identifier, format=None):
|
||||
qs = Entity.objects.prefetch_related(
|
||||
'left_relations__schema', 'left_relations__right',
|
||||
'right_relations__schema', 'right_relations__left',
|
||||
)
|
||||
# permet de ne voir que le conjoint ou que les enfants
|
||||
conjoint = request.GET.get('conjoint') is not None
|
||||
enfants = request.GET.get('enfants') is not None
|
||||
|
||||
# les deux options ensemble s'annulent
|
||||
if conjoint and enfants:
|
||||
conjoint = False
|
||||
enfants = False
|
||||
|
||||
individu = get_object_or_404(qs, schema__slug=utils.INDIVIDU_ENT, id=identifier)
|
||||
utils.PersonSearch.decorate_individu(individu)
|
||||
data = []
|
||||
# on ajoute l'individu visé que si on n'a pas demandé à ne voir que le conjoint ou que les
|
||||
# enfants
|
||||
if not conjoint and not enfants:
|
||||
data.append(individu_to_response(individu, add_parents=False, add_enfant=False,
|
||||
add_conjoint=False, add_text=True))
|
||||
if hasattr(individu, 'union') and not enfants:
|
||||
data.append(individu_to_response(individu.union, add_text=True))
|
||||
|
||||
if hasattr(individu, 'enfants') and not conjoint:
|
||||
for enfant in individu.enfants:
|
||||
utils.PersonSearch.add_age(enfant)
|
||||
# ordonne les enfants du plus agé au plus jeune
|
||||
for enfant in sorted(individu.enfants, key=lambda e: e.age, reverse=True):
|
||||
data.append(individu_to_response(enfant, add_text=True))
|
||||
|
||||
return Response({
|
||||
'err': 0,
|
||||
'data': data,
|
||||
})
|
||||
|
||||
reseau_liste = ReseauListView.as_view()
|
||||
|
||||
|
||||
class AdresseSerializer(serializers.Serializer):
|
||||
at = serializers.CharField(allow_blank=True)
|
||||
streetnumber = serializers.CharField(allow_blank=True)
|
||||
|
|
|
@ -9,6 +9,8 @@ urlpatterns = [
|
|||
url(r'^import_control/$', import_control, name='demo'),
|
||||
url(r'^search/$', api_views.search, name='rsu-api-search'),
|
||||
url(r'^individu/(?P<identifier>\d+)/$', api_views.reseau, name='rsu-api-reseau'),
|
||||
url(r'^individu/(?P<identifier>\d+)/liste/$', api_views.reseau_liste,
|
||||
name='rsu-api-reseau-liste'),
|
||||
url(r'^individu/(?P<identifier>\d+)/journal/$', api_views.journal, name='rsu-api-journal'),
|
||||
url(r'^individu/(?P<identifier>\d+)/declaration-responsabilite-legale/$',
|
||||
api_views.declaration_responsabilite_legale,
|
||||
|
|
Loading…
Reference in New Issue