agoraplus: phones numbers update endpoint (#11077)
This commit is contained in:
parent
d4ba2a2ec8
commit
b5d7172555
|
@ -794,6 +794,33 @@ class AgoraPlus(BaseResource):
|
|||
raise Exception((res.get('message') or '').encode('utf-8'))
|
||||
return True
|
||||
|
||||
def get_agoraplus_adult_id(self, adult_id, login):
|
||||
if not adult_id.startswith('sas_'):
|
||||
return adult_id
|
||||
family = self.get_family(login=login)
|
||||
for adult in family['adults']:
|
||||
if adult_id == adult['id']:
|
||||
return adult['original_id']
|
||||
raise ObjectDoesNotExist(_('adult not in Agora+'))
|
||||
|
||||
def update_phone_numbers(self, login, adult_id,
|
||||
new_phone_number, new_cellphone_number):
|
||||
family = self.get_agoraplus_family(login)
|
||||
if not family:
|
||||
raise ObjectDoesNotExist(_('no family in Agora+'))
|
||||
|
||||
# get adult infos
|
||||
agoraplus_adult_id = self.get_agoraplus_adult_id(adult_id, login)
|
||||
endpoint = 'familles/%s/representants/%s' % (family['id'], agoraplus_adult_id)
|
||||
adult_data = self.request(endpoint)
|
||||
adult_data['fixPerso'] = new_phone_number
|
||||
adult_data['mobilePerso'] = new_cellphone_number
|
||||
|
||||
# update adult data
|
||||
res = self.request(endpoint, json=adult_data, method='PUT')
|
||||
if res.get('code') != '1':
|
||||
raise Exception((res.get('message') or '').encode('utf-8'))
|
||||
return True
|
||||
|
||||
def get_invoice_pdf(self, login, invoice_id):
|
||||
invoices = self.get_invoices(login)
|
||||
|
|
|
@ -51,6 +51,9 @@
|
|||
>{{ site_base_uri }}{% url 'agoraplus-user' slug=object.slug %}</a>[?login=…]</li>
|
||||
<li>{% trans 'Authentication:' %} <a href="{% url 'agoraplus-auth' slug=object.slug %}"
|
||||
>{{ site_base_uri }}{% url 'agoraplus-auth' slug=object.slug %}?login=…&password=…</a></li>
|
||||
<li>{% trans 'Update phone number:' %} POST <a href="{% url 'agoraplus-phone-update' slug=object.slug %}"
|
||||
>{{ site_base_uri }}{% url 'agoraplus-phone-update' slug=object.slug %}?NameID=…</a></li>
|
||||
— {% trans 'JSON payload: wcs Formdata with Agora+ fields' %}
|
||||
</ul>
|
||||
|
||||
<h4>{% trans "Address" %}</h4>
|
||||
|
|
|
@ -41,6 +41,8 @@ public_urlpatterns = patterns('',
|
|||
name='agoraplus-user'),
|
||||
url(r'^(?P<slug>[\w-]+)/auth/$', AuthView.as_view(),
|
||||
name='agoraplus-auth'),
|
||||
url(r'^(?P<slug>[\w-]+)/phone/$', PhoneUpdateView.as_view(),
|
||||
name='agoraplus-phone-update'),
|
||||
|
||||
url(r'^(?P<slug>[\w-]+)/reference/(?P<name>[\w-]+)/((?P<reference_id>[\w-]+)/)?$',
|
||||
ReferenceView.as_view(), name='agoraplus-reference'),
|
||||
|
|
|
@ -585,3 +585,15 @@ class AddressUpdateView(PostFormdataView):
|
|||
if not family:
|
||||
raise Http404(_('no family in Agora+'))
|
||||
return self.object.update_address(family, new_address, leaving_date)
|
||||
|
||||
|
||||
class PhoneUpdateView(PostFormdataView):
|
||||
def post_data(self, formdata):
|
||||
adult_id = formdata.get('adult').get('id')
|
||||
new_phone_number = formdata.get('phone')
|
||||
new_cellphone_number = formdata.get('cellphone')
|
||||
try:
|
||||
return self.object.update_phone_numbers(self.login, adult_id,
|
||||
new_phone_number, new_cellphone_number)
|
||||
except ObjectDoesNotExist, e:
|
||||
raise Http404(e.message)
|
||||
|
|
Loading…
Reference in New Issue