from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import ProcessFormView
from django.views.generic.edit import ModelFormMixin
+from django.views.generic.list import BaseListView
from karmaworld.apps.courses.forms import CourseForm
from karmaworld.apps.courses.models import Course
from karmaworld.apps.courses.models import School
+
+class JSONCourseMixin(object):
+ """ JSON mixin for returning course lists """
+ response_class = HttpResponse
+
+ def render_to_response(self, context, **response_kwargs):
+ """
+ Returns a JSON response, transforming 'context' to make the payload.
+ """
+ response_kwargs['content_type'] = 'application/json'
+ return self.response_class(
+ # replace convert_context_to_json with our whatever function
+ self.convert_context_to_json(context),
+ **response_kwargs
+ )
+
+
class CourseDetailView(DetailView):
""" Class-based view for the course html page """
model = Course
print "\n\n"
+class CourseAjaxList(BaseListView, JSONCourseMixin):
+
+
+ def get_queryset(self):
+ """ generate a contexual query based on arguments """
+ req = self.request # HTTPrequest is stored in the class
+ print "\nxxxXXXxxx datatables ajax arguments xxxXXXxxx\n"
+ print req
+ print '\n'
+ print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
+ print "printing the request.GET dict"
+ print req.GET
+
+
def school_list(request):
""" Return JSON describing Schools that match q query on name """
if request.method == 'POST' and request.is_ajax() \
from karmaworld.apps.courses.views import AboutView
from karmaworld.apps.courses.views import CourseDetailView
from karmaworld.apps.courses.views import CourseSaveView
+from karmaworld.apps.courses.views import CourseAjaxList
from karmaworld.apps.courses.views import school_list
from karmaworld.apps.notes.views import NoteView
from karmaworld.apps.notes.views import raw_file
# See: https://docs.djangoproject.com/en/dev/topics/http/urls/
urlpatterns = patterns('',
+ ## Administrative URLpatterns
# Admin panel and documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
# Grappelli django-admin improvment suite
url(r'^grappelli/', include('grappelli.urls')),
+ ## Single-serving page URLpatterns
url(r'^terms/$', direct_to_template, { 'template': 'terms.html' }, name='terms'),
-
url(r'^about/$', AboutView.as_view(), name='about'),
+ # VIEW for viewing a Note's gdrive generated html, used as iframe
url(r'^raw/(?P<pk>\d+)$', raw_file, name='note_raw'),
+
+ # VIEW for displaying a single Course
url(r'^(?P<school_slug>[^/]+)/(?P<slug>[-A-Za-z0-9_]+)$', \
CourseDetailView.as_view(), name='course_detail'),
# return json list of schools
url(r'^school/list/$', school_list, name='json_school_list'),
url(r'^course/post/$', CourseSaveView.as_view(), name='api_course_post'),
+ url(r'^course/list/$', CourseAjaxList.as_view(), name='api_course_list'),
+
# ---- end JSON views ----#
url(r'^$', ListView.as_view(model=Course), name='home'),