bgneal@127: """ bgneal@127: Views for the core application. These are mainly shared, common views bgneal@127: used by multiple applications. bgneal@127: """ bgneal@149: from django.contrib.auth.models import User bgneal@149: from django.http import HttpResponse bgneal@149: from django.http import HttpResponseBadRequest bgneal@149: from django.http import HttpResponseForbidden bgneal@127: from django.shortcuts import render_to_response bgneal@127: from django.template import RequestContext bgneal@127: from django.contrib.auth.decorators import login_required bgneal@127: from django.views.decorators.http import require_GET bgneal@127: bgneal@127: @login_required bgneal@127: @require_GET bgneal@127: def markdown_help(request): bgneal@127: """ bgneal@127: This view provides the Markdown help cheat sheet. It is expected bgneal@127: to be called via AJAX. bgneal@127: """ bgneal@127: return render_to_response('core/markdown_help.html') bgneal@149: bgneal@149: bgneal@149: def ajax_users(request): bgneal@149: """ bgneal@149: If the user is authenticated, return a string of usernames whose names start with bgneal@149: the 'q' GET parameter, limited by the 'limit' GET parameters. The names are separated bgneal@149: by newlines. Only active usernames are returned. bgneal@149: If the user is not authenticated, return an empty string. bgneal@149: """ bgneal@149: q = request.GET.get('q', None) bgneal@149: if q is None: bgneal@149: return HttpResponseBadRequest() bgneal@149: bgneal@149: if request.user.is_authenticated(): bgneal@149: q = request.GET.get('q', ' ') bgneal@149: limit = int(request.GET.get('limit', 10)) bgneal@149: users = User.objects.filter(is_active=True, bgneal@149: username__istartswith=q).values_list('username', flat=True)[:limit] bgneal@149: user_list = u"\n".join(users) bgneal@149: return HttpResponse(user_list) bgneal@149: return HttpResponseForbidden()