[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/), 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). 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 ## [0.1.2] - 16/10/2020
### Changed ### Changed
- Use json_loads from Passerelle instead of json.loads() - Use json_loads from Passerelle instead of json.loads()

View File

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

View File

@ -1 +1 @@
0.1.2 0.1.3