def status_view(request):
	if not request.user.is_staff:
		raise Http404()
	tn = mgmtlib.connect()
	status = mgmtlib.get_status(tn)
	mgmtlib.quit(tn)
	status = mgmtlib.parse_status(status)
	users = status['users']
	sessions = Connection.objects.filter(time_end=None)
	userlist = User.objects.all()
	return render_to_response("status.html", locals(), context_instance=RequestContext(request))
setup_environ(settings)

from django.db import connection
#from django.contrib.auth.models import User
from purple.app.models import *

import os
import sys
import datetime
import mgmtlib


tn = mgmtlib.connect()
status = mgmtlib.get_status(tn)
mgmtlib.quit(tn)
status = mgmtlib.parse_status(status)
print status['users']

for u in status['users']:
	if u[0] == "UNDEF":
		continue # not yet connected
	try:
		user = User.objects.get(username=u[0])
	except User.DoesNotExist:
		print "user does not exist"
		continue
	try:
		c = Connection.objects.get(user=user, time_end=None)
	except Connection.DoesNotExist:
		print "missing a waiting connection"
		continue