agoraplus: children school enrollments endpoint (#11038)

This commit is contained in:
Serghei Mihai 2016-05-25 11:00:58 +02:00
parent 6b0fbbe9e7
commit d8a50456d8
5 changed files with 36 additions and 1 deletions

View File

@ -33,7 +33,8 @@ from passerelle.base.models import BaseResource
from .normalize import normalize_reference, normalize_family, \
normalize_school, normalize_person, denormalize_date, PROVISIONING_DOMAIN, \
normalize_invoice, normalize_planning, normalize_date, normalize_nursery_enroll_results
normalize_invoice, normalize_planning, normalize_date, normalize_nursery_enroll_results, \
normalize_school_enrollment
from .finalize import finalize_family
from .agoraize import agoraize_family, agoraize_child, agoraize_contact
from .provisioning import provision_attributes, provision_roles
@ -733,6 +734,13 @@ class AgoraPlus(BaseResource):
child_id = child.get('original_id') or child['id']
child['plannings'] = self.get_plannings(child_id)
def get_school_enrollment(self, child):
url = 'enfants/%s/inscriptions_scols/' % child['id']
enrollments = self.request(url)
if not isinstance(enrollments, list):
return []
return [normalize_school_enrollment(e) for e in enrollments]
def get_invoices(self, login):
if not login: # unlinked account
return []

View File

@ -348,3 +348,15 @@ def normalize_nursery_enroll_results(results):
new_result['maintain_date'] = ''
new_result['maintain_date_fr'] = ''
return new_result
def normalize_school_enrollment(enrollment):
child = enrollment['enfant']
year = enrollment['anneeRef']
child_fullname = '%s %s' % (child['prenom'], child['nom'])
school = enrollment['etablissementAffectation']
enrollment_level = enrollment['niveau']
return {'id': enrollment['idInscScol'], 'child_id': child['id'],
'year_id': year['id'],
'text': '%s, %s / %s, %s' % (child_fullname, school['name'],
enrollment_level['name'], year['name']),
}

View File

@ -158,6 +158,9 @@
>{{ site_base_uri }}{% url 'agoraplus-school-enrollment' slug=object.slug %}</a>
— {% trans 'JSON payload: wcs Formdata with Agora+ fields' %}
</li>
<li>{% trans 'Children school enrollments:' %} GET <a href="{% url 'agoraplus-school-enrollments' slug=object.slug %}"
>{{ site_base_uri }}{% url 'agoraplus-school-enrollments' slug=object.slug %}?NameID=…</a>
</li>
<li>{% trans 'Nursery Enrollment:' %} POST <a href="{% url 'agoraplus-nursery-enrollment' slug=object.slug %}"
>{{ site_base_uri }}{% url 'agoraplus-nursery-enrollment' slug=object.slug %}</a>
— {% trans 'JSON payload: wcs Formdata with Agora+ fields' %}

View File

@ -93,6 +93,8 @@ public_urlpatterns = patterns('',
name='agoraplus-incomes-declaration'),
url(r'^(?P<slug>[\w-]+)/school-enrollment/?$', SchoolEnrollmentView.as_view(),
name='agoraplus-school-enrollment'),
url(r'^(?P<slug>[\w-]+)/school-enrollments/?$', SchoolEnrollmentsView.as_view(),
name='agoraplus-school-enrollments'),
url(r'^(?P<slug>[\w-]+)/nursery-enrollment/?$', NurseryEnrollmentView.as_view(),
name='agoraplus-nursery-enrollment'),
url(r'^(?P<slug>[\w-]+)/nursery-enrollment-result/(?P<enroll_id>[\w-]+)/?$', NurseryEnrollmentResultView.as_view(),

View File

@ -488,6 +488,16 @@ class SchoolEnrollmentView(PostFormdataView):
return self.object.school_enrollment(data)
class SchoolEnrollmentsView(DetailView):
def get_data(self, request, *args, **kwargs):
family = self.object.get_agoraplus_family(login=self.login)
enrollments = []
for child in family.get('children') or []:
enrollment = self.object.get_school_enrollment(child)
enrollments.extend(enrollment)
return enrollments
class NurseryEnrollmentView(PostFormdataView):
def post_data(self, formdata):
data = formdata.get_nursery_enrollment()