annotate core/views.py @ 693:ad69236e8501

For issue #52, update many 3rd party Javascript libraries. Updated to jquery 1.10.2, jquery ui 1.10.3. This broke a lot of stuff. - Found a newer version of the jquery cycle all plugin (3.0.3). - Updated JPlayer to 2.4.0. - Updated to MarkItUp 1.1.14. This also required me to add multiline attributes set to true on various buttons in the markdown set. - As per a stackoverflow post, added some code to get multiline titles in a jQuery UI dialog. They removed that functionality but allow you to put it back. Tweaked the MarkItUp preview CSS to show blockquotes in italic. Did not update TinyMCE at this time. I'm not using the JQuery version and this version appears to work ok for now. What I should do is make a repo for MarkItUp and do a vendor branch thing so I don't have to futz around diffing directories to figure out if I'll lose changes when I update.
author Brian Neal <bgneal@gmail.com>
date Wed, 04 Sep 2013 19:55:20 -0500
parents 89b240fe9297
children e932f2ecd4a7
rev   line source
bgneal@127 1 """
bgneal@127 2 Views for the core application. These are mainly shared, common views
bgneal@127 3 used by multiple applications.
bgneal@679 4
bgneal@127 5 """
bgneal@679 6 import json
bgneal@679 7
bgneal@149 8 from django.contrib.auth.models import User
bgneal@149 9 from django.http import HttpResponse
bgneal@127 10 from django.shortcuts import render_to_response
bgneal@127 11 from django.contrib.auth.decorators import login_required
bgneal@127 12 from django.views.decorators.http import require_GET
bgneal@591 13 from django.views.generic import TemplateView
bgneal@186 14
bgneal@127 15
bgneal@127 16 @login_required
bgneal@127 17 @require_GET
bgneal@127 18 def markdown_help(request):
bgneal@127 19 """
bgneal@127 20 This view provides the Markdown help cheat sheet. It is expected
bgneal@127 21 to be called via AJAX.
bgneal@679 22
bgneal@127 23 """
bgneal@127 24 return render_to_response('core/markdown_help.html')
bgneal@149 25
bgneal@149 26
bgneal@149 27 def ajax_users(request):
bgneal@149 28 """
bgneal@679 29 If the user is authenticated, return a JSON array of strings of usernames
bgneal@679 30 whose names start with the 'q' GET parameter, limited by the 'limit' GET
bgneal@186 31 parameter. Only active usernames are returned.
bgneal@186 32 If the user is not authenticated, return an empty array.
bgneal@679 33
bgneal@149 34 """
bgneal@149 35 q = request.GET.get('q', None)
bgneal@186 36 if q is None or not request.user.is_authenticated():
bgneal@186 37 return HttpResponse(json.dumps([]), content_type='application/json')
bgneal@149 38
bgneal@186 39 limit = int(request.GET.get('limit', 10))
bgneal@679 40 users = User.objects.filter(is_active=True,
bgneal@186 41 username__istartswith=q).values_list('username', flat=True)[:limit]
bgneal@186 42 return HttpResponse(json.dumps(list(users)), content_type='application/json')
bgneal@591 43
bgneal@591 44
bgneal@591 45 class FixedView(TemplateView):
bgneal@591 46 """
bgneal@591 47 For displaying our "fixed" views generated with the custom command
bgneal@591 48 make_fixed_page.
bgneal@591 49
bgneal@591 50 """
bgneal@591 51 template_name = 'fixed/base.html'
bgneal@591 52 title = ''
bgneal@591 53 content_template = ''
bgneal@591 54
bgneal@591 55 def get_context_data(self, **kwargs):
bgneal@591 56 context = super(FixedView, self).get_context_data(**kwargs)
bgneal@591 57 context['title'] = self.title
bgneal@591 58 context['content_template'] = self.content_template
bgneal@591 59 return context