agoraplus: add document endpoint (#10487)
This commit is contained in:
parent
84042784e1
commit
5be56d4aa8
|
@ -780,6 +780,13 @@ class AgoraPlus(BaseResource):
|
|||
cookies = {'portail_session_id': self.get_token()}
|
||||
return requests.get(self.url + endpoint, cookies=cookies).content
|
||||
|
||||
def get_document(self, uri, content_type):
|
||||
cookies = {'portail_session_id': self.get_token()}
|
||||
response = requests.get(self.url + uri, cookies=cookies)
|
||||
if content_type != response.headers['content-type'].split(';')[0].strip().lower():
|
||||
return None
|
||||
return response.content
|
||||
|
||||
|
||||
class AgoraPlusLink(models.Model):
|
||||
'''
|
||||
|
|
|
@ -196,6 +196,16 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<h4>{% trans 'Documents' %}</h4>
|
||||
<ul>
|
||||
<li>{% trans 'Document (pass-through):' %} POST <a href="{% url 'agoraplus-document' slug=object.slug %}"
|
||||
>{{ site_base_uri }}{% url 'agoraplus-document' slug=object.slug %}</a> —
|
||||
{% trans 'JSON payload:' %}
|
||||
<ul>
|
||||
<li><em>uri</em> {% trans 'uri, with query-string' %}</li>
|
||||
<li><em>content_type</em> {% trans 'document must have this content-type' %}</li>
|
||||
</ul>
|
||||
</li>
|
||||
</div>
|
||||
|
||||
{% if perms.base.view_accessright %}
|
||||
|
|
|
@ -102,6 +102,7 @@ public_urlpatterns = patterns('',
|
|||
url(r'^(?P<slug>[\w-]+)/regie/invoice/(?P<invoice_id>[\w,-]+)/pay/$', InvoicePayView.as_view(), name='agoraplus-invoice-payment'),
|
||||
url(r'^(?P<slug>[\w-]+)/regie/invoice/(?P<invoice_id>[\w,-]+)/$', InvoiceView.as_view(), name='agoraplus-invoice'),
|
||||
url(r'^(?P<slug>[\w-]+)/regie/invoice/(?P<invoice_id>[\w,-]+)/pdf/$', InvoicePDFView.as_view(), name='agoraplus-invoice-pdf'),
|
||||
url(r'^(?P<slug>[\w-]+)/document/?$', DocumentView.as_view(), name='agoraplus-document'),
|
||||
)
|
||||
|
||||
management_urlpatterns = patterns('',
|
||||
|
|
|
@ -24,7 +24,7 @@ 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
|
||||
from django.http import HttpResponse, HttpResponseBadRequest
|
||||
|
||||
from passerelle import utils
|
||||
|
||||
|
@ -541,3 +541,26 @@ class InvoicePDFView(DetailView):
|
|||
response['Content-Disposition'] = 'attachment; filename="%s.pdf"' % invoice_id
|
||||
response.write(pdf)
|
||||
return response
|
||||
|
||||
|
||||
class DocumentView(DetailView):
|
||||
@method_decorator(csrf_exempt)
|
||||
def dispatch(self, *args, **kwargs):
|
||||
return super(DocumentView, self).dispatch(*args, **kwargs)
|
||||
|
||||
@utils.protected_api('can_access')
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
uri = data['uri']
|
||||
content_type = data['content_type']
|
||||
except (ValueError, TypeError, KeyError) as e:
|
||||
return HttpResponseBadRequest()
|
||||
document = self.object.get_document(uri, content_type)
|
||||
response = HttpResponse(content_type=content_type)
|
||||
if document is not None:
|
||||
response.write(document)
|
||||
else:
|
||||
response.status_code = 404
|
||||
return response
|
||||
|
|
Loading…
Reference in New Issue