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, Http404 from django.shortcuts import render_to_response, get_object_or_404 import json # JSON for jQuery AJAX autocomplete from 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 ##############################################################################