From: Seth Woodworth Date: Wed, 27 Feb 2013 19:38:11 +0000 (-0500) Subject: initial broken serverside datatables config X-Git-Tag: release-20150131~508 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=86ce78130d06adfd716a019f11f0cf6e1fd4c6d1;p=oweals%2Fkarmaworld.git initial broken serverside datatables config --- diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index 7e2b316..18ddbc9 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -13,11 +13,29 @@ from django.views.generic.base import View 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 @@ -59,6 +77,20 @@ class CourseSaveView(ModelFormMixin, ProcessFormView): 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() \ diff --git a/karmaworld/templates/courses/course_list.html b/karmaworld/templates/courses/course_list.html index f825849..14b9193 100644 --- a/karmaworld/templates/courses/course_list.html +++ b/karmaworld/templates/courses/course_list.html @@ -16,8 +16,11 @@ {% endblock %} diff --git a/karmaworld/urls.py b/karmaworld/urls.py index caddca9..0c88969 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -12,6 +12,7 @@ from karmaworld.apps.courses.models import Course 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 @@ -21,17 +22,21 @@ admin.autodiscover() # 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\d+)$', raw_file, name='note_raw'), + + # VIEW for displaying a single Course url(r'^(?P[^/]+)/(?P[-A-Za-z0-9_]+)$', \ CourseDetailView.as_view(), name='course_detail'), @@ -48,6 +53,8 @@ urlpatterns = patterns('', # 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'),