From 3a27559c83378fc541e0e80c83e778f57fb828c0 Mon Sep 17 00:00:00 2001 From: Charles Holbrow Date: Thu, 21 Mar 2013 14:28:36 -0400 Subject: [PATCH] removing remnants of server-side filtering, including school_name field from Course model --- karmaworld/apps/courses/models.py | 3 -- karmaworld/apps/courses/views.py | 53 ------------------- karmaworld/templates/courses/course_list.html | 2 - karmaworld/urls.py | 2 - 4 files changed, 60 deletions(-) diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index 1c35803..40e5a32 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -75,9 +75,6 @@ class Course(models.Model): instructor_name = models.CharField(max_length=255, blank=True, null=True) instructor_email = models.EmailField(blank=True, null=True) - # Save school name redundantly to speed filtering - school_name = models.CharField(max_length=255, blank=True, null=True) - updated_at = models.DateTimeField(default=datetime.datetime.utcnow) created_at = models.DateTimeField(auto_now_add=True) diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index 08159d8..d65330c 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -61,59 +61,6 @@ class CourseSaveView(ModelFormMixin, ProcessFormView): print "\n\n" -class CourseAjaxList(BaseListView): - - def get_queryset(self): - """ generate a contexual query based on arguments """ - - req = self.request # HTTPrequest is stored in the class - - # Handle empty argument sSearch - if req.GET['sSearch'] == '': - return [] - - search_query = req.GET['sSearch'] - - search_strings = search_query.strip().split(' ') - queries = [ - ( - Q(name__icontains=s) | - Q(instructor_name__icontains=s) | - Q(school_name__icontains=s) - ) - for s in search_strings - ] - - full_query = queries.pop() - for q in queries: - full_query &= q - - object_list = Course.objects.filter(full_query).values_list( - 'school__name', - 'name', - 'instructor_name', - 'file_count', - 'updated_at') - - # this works too - # return map(lambda row: [row[:3], row[4].strftime("%I%p // %a %b %d %Y")], object_list) - return [[a, b, c, d, e.strftime("%I%p // %a %b %d %Y")] for a, b, c, d, e in object_list] - - def render_to_response(self, context, **response_kwargs): - """ Returns a JSON response, transforming 'context' to make the payload """ - response_dict = { - 'aaData': self.object_list, - 'iTotalRecords': len(self.object_list), - 'iTotalDisplayRecords': len(self.object_list), - 'sEcho': int(self.request.GET['sEcho']) - } - return HttpResponse( - # replace convert_context_to_json with our whatever function - json.dumps(response_dict), - content_type = 'application/json' - ) - - 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 41e9ece..240f8fa 100644 --- a/karmaworld/templates/courses/course_list.html +++ b/karmaworld/templates/courses/course_list.html @@ -76,8 +76,6 @@ $(document).ready(function() { }], // Initial sorting 'aaSorting': [[2,'desc']] - // Use out Ajax endpoing to populate the list - //'sAjaxSource': "{% url 'api_course_list' %}" }); $('.dataTables_filter input').attr("placeholder", "search courses"); // TODO: can't prepend html to .dataTables_filter input html for fontawesome search icon diff --git a/karmaworld/urls.py b/karmaworld/urls.py index 0c88969..60d06e6 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -12,7 +12,6 @@ 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 @@ -53,7 +52,6 @@ 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 ----# -- 2.25.1