[TELE-513] use django 2.2 import syntax for reverse

This commit is contained in:
Daniel Muyshond 2021-05-25 17:26:11 +02:00
parent 5c0b6e2686
commit dff0c349c1
3 changed files with 90 additions and 61 deletions

View File

@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.1.2] - 16/10/2020
### Changed
- Use django 2.2 reverse import
(dmuyshond)
## [0.1.2] - 16/10/2020
### Changed
- Use json_loads from Passerelle instead of json.loads()

View File

@ -30,7 +30,7 @@ import suds
from builtins import str
from requests.exceptions import ConnectionError
from django.db import models
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponse, Http404
@ -44,19 +44,20 @@ from .soap import get_client as soap_get_client
from suds.xsd.doctor import ImportDoctor, Import
from suds.transport.http import HttpAuthenticated
def get_client(model):
try:
return soap_get_client(model)
except ConnectionError as e:
raise APIError('i-ImioIaDelib error: %s' % e)
raise APIError("i-ImioIaDelib error: %s" % e)
def format_type(t):
return {'id': str(t), 'text': str(t)}
return {"id": str(t), "text": str(t)}
def format_file(f):
return {'status': f.status, 'id': f.nom, 'timestamp': f.timestamp}
return {"status": f.status, "id": f.nom, "timestamp": f.timestamp}
class FileError(Exception):
@ -68,23 +69,26 @@ class FileNotFoundError(Exception):
class IImioIaDelib(BaseResource):
wsdl_url = models.CharField(max_length=128, blank=False,
verbose_name=_('WSDL URL'),
help_text=_('WSDL URL'))
verify_cert = models.BooleanField(default=True,
verbose_name=_('Check HTTPS Certificate validity'))
username = models.CharField(max_length=128, blank=True,
verbose_name=_('Username'))
password = models.CharField(max_length=128, blank=True,
verbose_name=_('Password'))
keystore = models.FileField(upload_to='iparapheur', null=True, blank=True,
verbose_name=_('Keystore'),
help_text=_('Certificate and private key in PEM format'))
wsdl_url = models.CharField(
max_length=128, blank=False, verbose_name=_("WSDL URL"), help_text=_("WSDL URL")
)
verify_cert = models.BooleanField(
default=True, verbose_name=_("Check HTTPS Certificate validity")
)
username = models.CharField(max_length=128, blank=True, verbose_name=_("Username"))
password = models.CharField(max_length=128, blank=True, verbose_name=_("Password"))
keystore = models.FileField(
upload_to="iparapheur",
null=True,
blank=True,
verbose_name=_("Keystore"),
help_text=_("Certificate and private key in PEM format"),
)
category = _('Business Process Connectors')
category = _("Business Process Connectors")
class Meta:
verbose_name = _('i-ImioIaDelib')
verbose_name = _("i-ImioIaDelib")
@classmethod
def get_verbose_name(cls):
@ -92,32 +96,39 @@ class IImioIaDelib(BaseResource):
@endpoint()
def test(self):
return 'True'
return "True"
@endpoint(serializer_type='json-api', perm='can_access')
@endpoint(serializer_type="json-api", perm="can_access")
def testConnection(self, request):
client = get_client(self)
return dict(client.service.testConnection(''))
return dict(client.service.testConnection(""))
@endpoint(serializer_type='json-api', perm='can_access')
@endpoint(serializer_type="json-api", perm="can_access")
def test_createItem(self, request):
client = get_client(self)
return dict(client.service.createItem('meeting-config-college', 'dirgen',
{'title': 'CREATION DE POINT TS2',
'description': 'My new item description',
'decision': 'My decision'}))
return dict(
client.service.createItem(
"meeting-config-college",
"dirgen",
{
"title": "CREATION DE POINT TS2",
"description": "My new item description",
"decision": "My decision",
},
)
)
# uid="uidplone", showExtraInfos="1", showAnnexes="0", showTemplates="0"
@endpoint(serializer_type='json-api', perm='can_access', methods=['post','get'])
@endpoint(serializer_type="json-api", perm="can_access", methods=["post", "get"])
def getItemInfos(self, request, *args, **kwargs):
id_delib_extraInfos = {}
if request.body:
load = json_loads(request.body)
ws_params = load['extra']
uid = ws_params['uid']
showExtraInfos = ws_params['showExtraInfos'] or "1"
showAnnexes = ws_params['showAnnexes'] or "0"
showTemplates = ws_params['showTemplates'] or "0"
ws_params = load["extra"]
uid = ws_params["uid"]
showExtraInfos = ws_params["showExtraInfos"] or "1"
showAnnexes = ws_params["showAnnexes"] or "0"
showTemplates = ws_params["showTemplates"] or "0"
else:
get = request.GET
uid = "uid" in get and get["uid"]
@ -126,31 +137,39 @@ class IImioIaDelib(BaseResource):
showTemplates = "showTemplates" in get and get["showTemplates"] or "0"
client = get_client(self)
try:
ia_delib_raw = client.service.getItemInfos(uid,
showExtraInfos,
showAnnexes,
showTemplates)
ia_delib_raw = client.service.getItemInfos(
uid, showExtraInfos, showAnnexes, showTemplates
)
except:
raise Exception("Don't find UID IA Delib point ?")
ia_delib_infos = dict((k, v.encode('utf8') if hasattr(v, 'encode') else v) for (k, v) in ia_delib_raw[0]
if k not in ['extraInfos'])
ia_delib_extraInfos = dict((k, v.encode('utf8') if hasattr(v, 'encode') else v) for (k, v) in ia_delib_raw[0]['extraInfos'])
ia_delib_infos = dict(
(k, v.encode("utf8") if hasattr(v, "encode") else v)
for (k, v) in ia_delib_raw[0]
if k not in ["extraInfos"]
)
ia_delib_extraInfos = dict(
(k, v.encode("utf8") if hasattr(v, "encode") else v)
for (k, v) in ia_delib_raw[0]["extraInfos"]
)
ia_delib_infos.update(ia_delib_extraInfos)
return ia_delib_infos
@endpoint(serializer_type='json-api', perm='can_access', methods=['post'])
def createItem_OLD(self, request, meetingConfigId, proposingGroupId, title, description,decision):
creationData ={'title':title,
'description':description,
'decision':decision
}
@endpoint(serializer_type="json-api", perm="can_access", methods=["post"])
def createItem_OLD(
self, request, meetingConfigId, proposingGroupId, title, description, decision
):
creationData = {
"title": title,
"description": description,
"decision": decision,
}
client = get_client(self)
return dict(client.service.createItem(meetingConfigId,
proposingGroupId,
creationData))
return dict(
client.service.createItem(meetingConfigId, proposingGroupId, creationData)
)
@endpoint(serializer_type='json-api', perm='can_access', methods=['post'])
@endpoint(serializer_type="json-api", perm="can_access", methods=["post"])
def createItem(self, request, *args, **kwargs):
data = dict([(x, request.GET[x]) for x in request.GET.keys()])
extraAttrs = {}
@ -158,19 +177,24 @@ class IImioIaDelib(BaseResource):
load = json_loads(request.body)
# get fields from form.
data.update(load.get("fields"))
ws_params = load['extra']
ws_params = load["extra"]
# if 'extraAttrs' in ws_params:
#else:
creationData ={'title':ws_params['title'],
'description':ws_params['description'],
'detailedDescription':ws_params['detailedDescription'],
'decision':ws_params['decision'],
'extraAttrs':extraAttrs
}
# else:
creationData = {
"title": ws_params["title"],
"description": ws_params["description"],
"detailedDescription": ws_params["detailedDescription"],
"decision": ws_params["decision"],
"extraAttrs": extraAttrs,
}
client = get_client(self)
new_point = dict(client.service.createItem(ws_params['meetingConfigId'],
ws_params['proposingGroupId'],
creationData))
new_point = dict(
client.service.createItem(
ws_params["meetingConfigId"],
ws_params["proposingGroupId"],
creationData,
)
)
return new_point
else:
raise ValueError("createItem : request body!")

View File

@ -1 +1 @@
0.1.2
0.1.3