On Mon, Dec 17, 2012 at 1:03 PM, Kevin Cole <[email protected]> wrote:

> Also asked on StackOverflow
>
>
> http://stackoverflow.com/questions/13918785/django-ldap-search-results-disappear
>
> Why in the code below, does the global *direktorie* return the correct
> data in the *login()* debug template, yet when I try to access the same
> variable from *autoname()* it says the list has a length of *0*? I don't
> reference *direktorie* in any other places in *views.py* -- or anywhere
> else for that matter. (All of the code below is merely an attempt to
> discover what I'm doing wrong. I don't really care about the length of the
> returned list. I just want to know it's being seen and has roughly the
> right number of entries.)
>
> ##############################################################################
>
> from django.http           import HttpResponse, HttpResponseRedirect, 
> Http404from django.shortcuts      import render_to_response, 
> get_object_or_404import json                      # JSON for jQuery AJAX 
> autocompletefrom   eldappery import *        # LDAP for jQuery AJAX 
> autocomplete
>
> direktorie = []
> ##############################################################################
> def login(request):
>   """LDAP Login routine"""
>   global direktorie
>
>   if request.method == "POST":                   # If submitted...
>     if request.POST["username"] and request.POST["password"]:
>       username = request.POST["username"]
>       password = request.POST["password"]
>       LDAPfeed = dapperize(username, password)   # ...login
>       if LDAPfeed:
>         direktorie = fetch_names(LDAPfeed,"")    # ...get everybody
>         ls  = locals()                           # DEBUG!
>         gs  = globals()                          # DEBUG!
>         return render_to_response("debug.html",
>                                   {"ls": ls,
>                                    "gs": gs})    # DEBUG! Works! (direktorie 
> full)
>       else:
>         return HttpResponseRedirect("/login/")
>   return render_to_response("login.html",
>                             context_instance=RequestContext(request))
> ##############################################################################
>
> def autoname(request):
>   """Auto-complete names"""
>   global direktorie
>   if request.is_ajax():#   results = [{"id":    5,#               "label": 
> 5,#               "value": 5}]                # DEBUG! Works! (5 in template)
>     results = [{"id":    len(direktorie),
>                 "label": len(direktorie),
>                 "value": len(direktorie)}]  # DEBUG! Doesn't work! (0 in 
> template)
>     data = json.dumps(results)              # Convert to JSON string
>   else:                                     # No results returned!
>     data = "fail"                           # Error...
>   mimetype = "application/json"             # MIME type = JSON
>   return HttpResponse(data, mimetype)       # Send JSON back to web page
> ##############################################################################
>
>
>  Perhaps in the thread in which autoname is run, login has not yet been
run.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to