TP1 apprentissage codage connecteur
connecteur permettant d'utiliser l'API de Pastell pour créer des flux Pastell
This commit is contained in:
parent
e5e53db359
commit
9585a0b6fc
|
@ -0,0 +1,10 @@
|
|||
Metadata-Version: 1.0
|
||||
Name: passerelle-reunion-pastell
|
||||
Version: 0
|
||||
Summary: UNKNOWN
|
||||
Home-page: UNKNOWN
|
||||
Author: CR Reunion
|
||||
Author-email: nicolas.clain@cr-reunion.fr
|
||||
License: UNKNOWN
|
||||
Description: UNKNOWN
|
||||
Platform: UNKNOWN
|
|
@ -0,0 +1,7 @@
|
|||
setup.py
|
||||
passerelle_reunion_pastell/__init__.py
|
||||
passerelle_reunion_pastell/models.py
|
||||
passerelle_reunion_pastell.egg-info/PKG-INFO
|
||||
passerelle_reunion_pastell.egg-info/SOURCES.txt
|
||||
passerelle_reunion_pastell.egg-info/dependency_links.txt
|
||||
passerelle_reunion_pastell.egg-info/top_level.txt
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
passerelle_reunion_pastell
|
|
@ -0,0 +1,31 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2019-10-15 11:27
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('base', '0015_auto_20190921_0347'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PastellReunionConnector',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=50, verbose_name='Title')),
|
||||
('description', models.TextField(verbose_name='Description')),
|
||||
('slug', models.SlugField(unique=True, verbose_name='Identifier')),
|
||||
('url', models.URLField(max_length=128, verbose_name='Pastell API URL')),
|
||||
('users', models.ManyToManyField(blank=True, related_name='_pastellreunionconnector_users_+', related_query_name='+', to='base.ApiUser')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Connecteur pastell r\xe9union',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2019-10-15 11:58
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('passerelle_reunion_pastell', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='pastellreunionconnector',
|
||||
name='type_flux',
|
||||
field=models.CharField(default=b'Type_flux', max_length=128, verbose_name='Pastell type de flux'),
|
||||
),
|
||||
]
|
|
@ -1,16 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.utils.api import endpoint
|
||||
# from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
||||
class ReunionConnector(BaseResource):
|
||||
|
||||
class PastellReunionConnector(BaseResource):
|
||||
|
||||
url = models.URLField(max_length=128, verbose_name=_('Pastell API URL'))
|
||||
# id_e = models.IntegerField(verbose_name=_('Pastell id entité'))
|
||||
type_flux = models.CharField(max_length=128, verbose_name=_('Pastell type de flux'), default='Type_flux')
|
||||
|
||||
category = 'Divers'
|
||||
|
||||
class Meta:
|
||||
verbose_name = u'Connecteur pastell réunion'
|
||||
|
||||
@endpoint(description_get=_('CreateDocument'), methods=['post'], perm='can_access')
|
||||
def createDocument(self, request):
|
||||
# try:
|
||||
# data = json.loads(request.body)
|
||||
# except ValueError as e:
|
||||
# return True, "could not decode body to json: %s" % e, None
|
||||
|
||||
# url = self.url + '/api/v2/entite/' + self.id_e + '/document'
|
||||
|
||||
res = self.requests.post(self.url, auth = ('admin', 'dF7#A9pn?'), data = {'type' : self.type_flux}, verify=False)
|
||||
return {'data': {'response': res.status_code}}
|
||||
|
|
Reference in New Issue