summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Marillonnet <pmarillonnet@entrouvert.com>2017-05-29 16:17:50 (GMT)
committerPaul Marillonnet <pmarillonnet@entrouvert.com>2017-05-30 08:30:00 (GMT)
commitea77e8cee787ee368c2d6ec410ca776b0d934b4b (patch)
tree40779bf713f059a5f561d16c07c8f74d663a0358
parent021b93bc16ae99ef45346672c11ad9f1cef4416a (diff)
downloadpaul-synchro-ea77e8cee787ee368c2d6ec410ca776b0d934b4b.zip
paul-synchro-ea77e8cee787ee368c2d6ec410ca776b0d934b4b.tar.gz
paul-synchro-ea77e8cee787ee368c2d6ec410ca776b0d934b4b.tar.bz2
POC Campus Condorcet : traitement des invitations, partie 1
-rw-r--r--django/sp_sso/invite/utils.py26
-rw-r--r--django/sp_sso/invite/views.py12
2 files changed, 38 insertions, 0 deletions
diff --git a/django/sp_sso/invite/utils.py b/django/sp_sso/invite/utils.py
new file mode 100644
index 0000000..68b7991
--- /dev/null
+++ b/django/sp_sso/invite/utils.py
@@ -0,0 +1,26 @@
+import json
+
+from urllib2 import build_opener, HTTPHandler, Request
+
+pocform = 'invitation'
+wcs = 'http://forms-condorcet.dev.entrouvert.org/'
+posturl = wcs+'/api/formdefs/'+pocform+'/submit'
+
+def do_invite(invitation):
+ opener = build_opener(HTTPHandler)
+ # Generate a JSON to bind against the wcs ReST API
+ form = {}
+ form["data"] = invitation # see wcs documentation
+ data = json.dumps(form)
+
+ req = Request(posturl, data)
+ req.add_header("Content-Type", "application/json")
+ req.add_header("Accept", "application/json")
+
+ ret = 0
+ try:
+ opener.open(req)
+ except :
+ ret = -1
+
+ return ret
diff --git a/django/sp_sso/invite/views.py b/django/sp_sso/invite/views.py
index 260c940..8c6c925 100644
--- a/django/sp_sso/invite/views.py
+++ b/django/sp_sso/invite/views.py
@@ -3,6 +3,13 @@ from django.shortcuts import render
from django.utils.translation import ugettext as _
from .forms import InvitationForm
+from .utils import do_invite
+
+invitation_attributes = [
+ 'email',
+ 'message',
+ 'hote_eppn',
+]
# Create your views here.
@@ -15,3 +22,8 @@ class InvitationFormView(FormView):
form_class = InvitationForm
template_name = 'invite/invitation_form.html'
success_url = '/invite/sent' # Mandatory?
+
+ def form_valid(self, form):
+ invitation = {}
+ do_invite(invitation)
+ return super(InvitationFormView, self).form_valid(form)