Commit d2f05419 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

moved the major-ordering code from the template into the view-- should be an...

moved the major-ordering code from the template into the view-- should be an performance improvement at the very least
parent 564c66ee
...@@ -16,17 +16,15 @@ ...@@ -16,17 +16,15 @@
{% load gravatar %} {% load gravatar %}
{% load accounts_extras %} {% load accounts_extras %}
{% regroup major_students by graduating_year as students %} {% for graduating_year, students in students_by_year.items %}
{% for graduating_year in students %}
<legend> <legend>
<a name="{{ graduating_year.grouper }}" href="#{{ graduating_year.grouper }}"> <a name="{{ graduating_year }}" href="#{{ graduating_year }}">
{{ graduating_year.grouper|bc }}</a> {{ graduating_year|bc }}</a>
</legend> </legend>
<div class="student-row"> <div class="student-row">
<div class="row"> <div class="row">
{% for student in graduating_year.list %} {% for student in students %}
<div class="col-sm-3 col-xs-6 text-center wordwrap"> <div class="col-sm-3 col-xs-6 text-center wordwrap">
<img class="img-circle img-responsive center center-block profile-image" <img class="img-circle img-responsive center center-block profile-image"
src="{{ student.profile_image_url }}" src="{{ student.profile_image_url }}"
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
import random import random
from distutils.util import strtobool from distutils.util import strtobool
from operator import attrgetter from collections import OrderedDict
from itertools import chain from itertools import groupby
import re import re
# core django imports # core django imports
from django.http import HttpResponseForbidden, HttpResponseRedirect, Http404 from django.http import HttpResponseForbidden, HttpResponseRedirect, Http404
...@@ -460,10 +460,17 @@ class DetailMajor(LoginRequiredMixin, DetailView): ...@@ -460,10 +460,17 @@ class DetailMajor(LoginRequiredMixin, DetailView):
context = super(DetailMajor, self).get_context_data(**kwargs) context = super(DetailMajor, self).get_context_data(**kwargs)
me = Student.objects.get(user=self.request.user) me = Student.objects.get(user=self.request.user)
# all students in the major # all students in the major-- needs to be ordered for groupby
major_students = Student.objects.filter(major__in=[self.get_object()]).order_by('-graduating_year') major_students = Student.objects.filter(major__in=[self.get_object()]).order_by('graduating_year')
context['major_students'] = shadowbanning(me, major_students) students_by_year = OrderedDict() # we're ordering from senior on down
for year, students in groupby(major_students, lambda student: student.graduating_year):
student_list = list(students) # students without the casting is an iterator
visible_students = shadowbanning(me, student_list) # remove blocked students
students_by_year[year] = visible_students # remembers insertion order
context['students_by_year'] = students_by_year
return context return context
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment