removing remnants of server-side filtering, including school_name field from Course...
authorCharles Holbrow <charlesholbrow@gmail.com>
Thu, 21 Mar 2013 18:28:36 +0000 (14:28 -0400)
committerCharles Holbrow <charlesholbrow@gmail.com>
Thu, 21 Mar 2013 18:28:36 +0000 (14:28 -0400)
karmaworld/apps/courses/models.py
karmaworld/apps/courses/views.py
karmaworld/templates/courses/course_list.html
karmaworld/urls.py

index 1c358039aa6721e4f150f93b47230e45eaee3c0e..40e5a32da36f036aa4b5f223d48818a7cb16a044 100644 (file)
@@ -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)
 
index 08159d80812360bbcd8c65abdd73700c0c27423b..d65330cb3278da9aafcad9a2284779f207f033fc 100644 (file)
@@ -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() \
index 41e9ecebb873dfacafebcd5e5bdffadc3b3aedaa..240f8fae1399a674c7b68298bcd8c2c5eb0cbef5 100644 (file)
@@ -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
index 0c8896905b897dcb922b6adfaba2057be97bbfb9..60d06e63cff8dbde7147ba62033aa95828e2ecd5 100644 (file)
@@ -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 ----#