agoraplus: address update endpoint (#11049)
This commit is contained in:
parent
b08977d964
commit
e6d39aa0a8
|
@ -36,7 +36,8 @@ from .normalize import normalize_reference, normalize_family, \
|
|||
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 .agoraize import agoraize_family, agoraize_child, agoraize_contact, \
|
||||
agoraize_address
|
||||
from .provisioning import provision_attributes, provision_roles
|
||||
|
||||
|
||||
|
@ -778,6 +779,22 @@ class AgoraPlus(BaseResource):
|
|||
res = self.request('reglements/', json=invoice_data)
|
||||
return res.get('code') == '0'
|
||||
|
||||
def update_address(self, family, new_address, leaving_date):
|
||||
new_address = agoraize_address(new_address)
|
||||
address_id = family['address']['id']
|
||||
new_address['id'] = address_id
|
||||
new_address['demenagement'] = 'true'
|
||||
new_address['dateDemenagement'] = denormalize_date(leaving_date)
|
||||
# required by agora but useless
|
||||
new_address['commune']['nom'] = ''
|
||||
new_address['voie']['nom'] = ''
|
||||
endpoint = '/familles/%s/adresses/%s' % (family['id'], address_id)
|
||||
res = self.request(endpoint, json=new_address, 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)
|
||||
if not invoices:
|
||||
|
|
|
@ -67,6 +67,11 @@
|
|||
<li>{% trans 'List of streets of a commune, by type:' %}
|
||||
<a href="{% url 'agoraplus-street-search' slug=object.slug commune_id='commune-id' type_of_street_id='tos-id' %}"
|
||||
>{{ site_base_uri }}{% url 'agoraplus-street-search' slug=object.slug commune_id='commune-id' type_of_street_id='tos-id' %}</a>[id/|?q=…]</li>
|
||||
<li>{% trans 'Update address:' %} POST
|
||||
<a href="{% url 'agoraplus-address-update' slug=object.slug %}"
|
||||
>{{ site_base_uri }}{% url 'agoraplus-address-update' slug=object.slug %}?NameID=…</a>
|
||||
— {% trans 'JSON payload: wcs Formdata with Agora+ fields' %}
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>{% trans "Other references" %}</h4>
|
||||
|
|
|
@ -57,6 +57,8 @@ public_urlpatterns = patterns('',
|
|||
name='agoraplus-street-search'),
|
||||
url(r'^(?P<slug>[\w-]+)/address/streets/((?P<street_id>[\w-]+)/)?$', StreetView.as_view(),
|
||||
name='agoraplus-street'),
|
||||
url(r'^(?P<slug>[\w-]+)/address/?$', AddressUpdateView.as_view(),
|
||||
name='agoraplus-address-update'),
|
||||
|
||||
url(r'^(?P<slug>[\w-]+)/exist/email/$', ExistEmailView.as_view(),
|
||||
name='agoraplus-exist-email'),
|
||||
|
|
|
@ -24,7 +24,8 @@ from django.views.generic import DetailView as GenericDetailView
|
|||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.http import HttpResponse, HttpResponseBadRequest
|
||||
from django.http import HttpResponse, HttpResponseBadRequest, Http404
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle import utils
|
||||
|
||||
|
@ -574,3 +575,13 @@ class DocumentView(DetailView):
|
|||
else:
|
||||
response.status_code = 404
|
||||
return response
|
||||
|
||||
|
||||
class AddressUpdateView(PostFormdataView):
|
||||
def post_data(self, formdata):
|
||||
new_address = formdata.get_address()
|
||||
leaving_date = formdata.get('leaving_date')
|
||||
family = self.object.get_agoraplus_family(login=self.login)
|
||||
if not family:
|
||||
raise Http404(_('no family in Agora+'))
|
||||
return self.object.update_address(family, new_address, leaving_date)
|
||||
|
|
Loading…
Reference in New Issue