venissieux-technocarte: create 'garde' cards
This commit is contained in:
parent
b9b15e688c
commit
130b90192b
|
@ -13,9 +13,10 @@ import urllib.parse
|
|||
import requests
|
||||
from wcs.carddef import CardDef
|
||||
|
||||
CARD_ENFANT_SLUG = 'enfants'
|
||||
CARD_ADULTE_SLUG = 'adultes'
|
||||
CARD_ENFANT_SLUG = 'enfants'
|
||||
CARD_FAMILLE_SLUG = 'familles'
|
||||
CARD_GARDE_SLUG = 'gardes'
|
||||
|
||||
USER = 'admin'
|
||||
WCS_BASE_URL = 'https://@wcs.dev.publik.love/api/'
|
||||
|
@ -203,17 +204,40 @@ def create_familles(adultes, enfants):
|
|||
|
||||
api_call(url, data)
|
||||
|
||||
return familles_map
|
||||
|
||||
|
||||
def create_gardes(enfants, familles):
|
||||
gardes = {}
|
||||
url = WCS_BASE_URL + 'cards/%s/submit' % CARD_GARDE_SLUG
|
||||
for _, enfant in enfants.items():
|
||||
publik_id = enfant['publik_id']
|
||||
technocarte_famille_id = enfant['technocarte_famille_id']
|
||||
publik_famille_id = familles[technocarte_famille_id]
|
||||
|
||||
# création garde
|
||||
data = {
|
||||
'enfant': publik_id,
|
||||
'famille': publik_famille_id
|
||||
}
|
||||
resp = api_call(url, data)
|
||||
gardes[publik_id] = str(resp.json()['data']['id'])
|
||||
|
||||
return gardes
|
||||
|
||||
|
||||
def import_data():
|
||||
adultes = create_adultes()
|
||||
enfants = create_enfants()
|
||||
create_familles(adultes, enfants)
|
||||
familles = create_familles(adultes, enfants)
|
||||
create_gardes(enfants, familles)
|
||||
|
||||
|
||||
def reset():
|
||||
CardDef.get_by_urlname(CARD_ENFANT_SLUG).data_class().wipe()
|
||||
CardDef.get_by_urlname(CARD_ADULTE_SLUG).data_class().wipe()
|
||||
CardDef.get_by_urlname(CARD_FAMILLE_SLUG).data_class().wipe()
|
||||
CardDef.get_by_urlname(CARD_GARDE_SLUG).data_class().wipe()
|
||||
|
||||
|
||||
if ACTION == 'import':
|
||||
|
|
Loading…
Reference in New Issue