def campuses(request): prefix = request.GET.get('q') limit = request.GET.get('limit', '10') try: limit = int(limit) except ValueError: limit = 10 limit = clamp(limit, 1, 1000) if prefix: cursor = connections['ak'].cursor() prefix = prefix + '%' cursor.execute("SELECT distinct value FROM core_userfield " "WHERE name=\"campus\" and value LIKE %s ORDER BY value LIMIT %s", [prefix, limit]) values = [row[0] for row in cursor.fetchall()] if not values: prefix = '%' + prefix cursor.execute("SELECT distinct value FROM core_userfield " "WHERE name=\"campus\" and value LIKE %s ORDER BY value LIMIT %s", [prefix, limit]) values = [row[0] for row in cursor.fetchall()] else: values = [] return HttpResponse(json.dumps(values), content_type='application/json')
def sources(request): prefix = request.GET.get('q') limit = request.GET.get('limit', '10') try: limit = int(limit) except ValueError: limit = 10 limit = clamp(limit, 1, 1000) if prefix: cursor = connections['ak'].cursor() prefix = prefix + '%' cursor.execute("SELECT distinct source FROM core_user " "WHERE source LIKE %s ORDER BY source LIMIT %s", [prefix, limit]) sources = [row[0] for row in cursor.fetchall()] else: sources = [] return HttpResponse(json.dumps(sources), content_type='application/json')