--- /dev/null
+from django import template
+
+register = template.Library()
+
+@register.filter(name='get')
+def get(obj, key):
+ """ Call getitem against the given key. """
+ return obj[key]
import json
+from django.db.models import Sum
from django.core import serializers
from django.core.exceptions import MultipleObjectsReturned
from django.core.exceptions import ObjectDoesNotExist
# Include "Add Course" button in header
context['display_add_course'] = True
+ # Include courses to number of total note thanks mapping
+ # See Course.get_popularity for a more detailed explanation.
+ thanks = Course.objects.values('id').annotate(sum=Sum('note__thanks'))
+ # Create a generator to convert the list of dicts into a dict.
+ context['course_thanks'] = dict((x['id'],x['sum'] or 0) for x in thanks)
+
return context
def get_success_url(self):
+{% load dict_filters %}
<tr>
<td class="no-display"><!-- this spot solely for the Sort By header --></td>
<td class="small-8 columns large-4 slim"><span>Updated {{ course.updated_at|date:"b d, o"|capfirst }}</span></td>
<td class="small-4 columns large-2 large-offset-2 slim"><span>{{ course.file_count }} Notes</span></td>
- <td class="small-4 columns large-2 large-offset-1 slim"><span>{{ course.get_popularity }} Thanks</span></td>
+ <td class="small-4 columns large-2 large-offset-1 slim"><span>{{ course_thanks|get:course.id }} Thanks</span></td>
<td class="small-12 large-5 columns">
<a href="{{ course.get_absolute_url }}">{% if course.department %}{{course.department.name}}: {% endif %}{{ course.name }}</a>