nanterre: add text field to search results for use with Select2
This commit is contained in:
parent
0cc3e7732b
commit
39c01c86d5
|
@ -1,3 +1,5 @@
|
|||
import isodate
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.db.models.query import Q
|
||||
|
||||
|
@ -11,7 +13,7 @@ from zoo.zoo_data.models import Entity, Relation, Transaction
|
|||
from . import utils
|
||||
|
||||
|
||||
def individu_to_response(individu):
|
||||
def individu_to_response(individu, add_text=False):
|
||||
'''Serialize a person'''
|
||||
d = individu.content.copy()
|
||||
d['id'] = individu.id
|
||||
|
@ -33,6 +35,13 @@ def individu_to_response(individu):
|
|||
if hasattr(individu, 'union'):
|
||||
d['union'] = individu_to_response(individu.union)
|
||||
d['union_statut'] = individu.union_statut
|
||||
if add_text:
|
||||
date_de_naissance = isodate.parse_date(d['date_de_naissance']).strftime('%d/%m/%Y')
|
||||
d['text'] = u'{} {} - {} {}'.format(
|
||||
d['prenoms'], d['nom_d_usage'] or d['nom_de_naissance'],
|
||||
date_de_naissance, d['genre'])
|
||||
if d.get('email'):
|
||||
d['text'] += ' - ' + d['email']
|
||||
return d
|
||||
|
||||
|
||||
|
@ -74,7 +83,8 @@ class SearchView(APIView):
|
|||
if key.startswith('cle_'):
|
||||
cle = request.GET[key]
|
||||
search = search.search_identifier(cle, key=key[4:])
|
||||
data = [individu_to_response(person) for person in search[offset:offset + limit]]
|
||||
data = [individu_to_response(person, add_text=True)
|
||||
for person in search[offset:offset + limit]]
|
||||
return Response({
|
||||
'err': 0,
|
||||
'offset': offset,
|
||||
|
|
Loading…
Reference in New Issue