Reorganisation : fonctions dans utils
This commit is contained in:
parent
bab7cdfc9d
commit
15f8fa5e13
|
@ -1,5 +1,25 @@
|
|||
import json
|
||||
import urllib
|
||||
import urllib2
|
||||
import urlparse
|
||||
|
||||
from ldap3 import Server, Connection, ALL
|
||||
|
||||
wcs_base = "http://wcs.example.com"
|
||||
form_slug = "/traitement/"
|
||||
ldap_attribute_mapping = { "a":"b",
|
||||
"c":"d"}
|
||||
|
||||
|
||||
# Simple w.c.s. <-> Passerelle REST communication
|
||||
def get_form_entry(wcs_entry_id):
|
||||
data_uri = "/api/forms"+form_slug+str(wcs_entry_id)
|
||||
geturl = wcs_base+data_uri
|
||||
req = urllib2.urlopen(geturl)
|
||||
#return json.dumps(req.read())
|
||||
return req.read()
|
||||
|
||||
# Bind to local OpenLDAP server
|
||||
def ldap_init():
|
||||
server = Server('spare.entrouvert.lan')
|
||||
conn = Connection(server)
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
import os
|
||||
import json
|
||||
import urllib
|
||||
import urllib2
|
||||
import urlparse
|
||||
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
@ -15,55 +10,31 @@ from django.views.generic import View, UpdateView, CreateView
|
|||
|
||||
# Add library search path entry?
|
||||
from passerelle import utils
|
||||
from .utils import ldap_init
|
||||
|
||||
#from .forms import QueryForm
|
||||
#from .models import CsvDataSource, Query
|
||||
|
||||
|
||||
from .utils import ldap_init, get_form_entry
|
||||
|
||||
#TODO
|
||||
# derive csv connector
|
||||
# use ldap3 instead of python-ldap
|
||||
|
||||
wcs_base = "http://wcs.example.com"
|
||||
form_slug = "/traitement/"
|
||||
|
||||
# Create your views here.
|
||||
def dummy_view(request):
|
||||
return HttpResponse("Dummy LDAP connector view.")
|
||||
|
||||
# Simple w.c.s. <-> Passerelle REST communication
|
||||
def get_form_entry(wcs_entry_id):
|
||||
data_uri = "/api/forms"+form_slug+str(wcs_entry_id)
|
||||
geturl = wcs_base+data_uri
|
||||
|
||||
#opener = urllib2.build_opener(urllib2.HTTPHandler)
|
||||
|
||||
req = urllib2.urlopen(geturl)
|
||||
#req.add_header("Accept", "application/json")
|
||||
|
||||
#response = opener.open(req)
|
||||
|
||||
return req.read()
|
||||
#return geturl
|
||||
|
||||
def wcs(request, slug="", wcs_entry_id=0):
|
||||
json_response = get_form_entry(wcs_entry_id)
|
||||
# Initiate the LDAP connection:
|
||||
#res = ldap_init() #OK
|
||||
|
||||
res = get_form_entry(wcs_entry_id)
|
||||
return HttpResponse("Querying w.c.s "+str(res))
|
||||
#return HttpResponse("Querying w.c.s "+str(res))
|
||||
#return HttpResponse(str(wcs_entry_id))
|
||||
return HttpResponse(str(json_response))
|
||||
|
||||
class LDAPView(View, SingleObjectMixin):
|
||||
def get(self, request, *args, **kwargs):
|
||||
return HttpResponse("Got the LDAP!")
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
return HttpResponse("Posted the LDAP!")
|
||||
return HttpResponse("Got the LDAP!")
|
||||
|
||||
# Fetch wcs form entry:
|
||||
#@classmethod
|
||||
|
||||
class LDAPDownload(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
|
Reference in New Issue