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

detail_major now sorts students in a major by graduating year

parent ad63dc10
...@@ -15,108 +15,37 @@ ...@@ -15,108 +15,37 @@
{% load gravatar %} {% load gravatar %}
{% comment %} Sigh... three sections of largely duplicated code. {% endcomment %} {% regroup major_students by graduating_year as students %}
<legend><strong><a href="{% url 'list_buildings' %}#Aquia">Aquia</a></strong></legend> {% for graduating_year in students %}
<legend>{{ graduating_year.grouper }}</legend>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="row"> <div class="row">
{% for student in aq_location_visible %} {% for student in graduating_year.list %}
{% if not student in request.user.student.blocked_kids.all %} <div class="col-sm-3 text-center">
<div class="col-sm-3 text-center"> <img class="img-circle img-responsive center center-block" src="{{ student.profile_image_url }}" alt="{{ student.get_first_name_or_uname }} profile picture">
<img class="img-circle img-responsive center center-block" src="{{ student.profile_image_url }}" alt="{{ student.get_first_name_or_uname }} profile picture"> <h4><a href="{{ student.get_absolute_url }}"><strong>{{ student.get_full_name_or_uname }}</strong></a></h4>
<h4><a href="{{ student.get_absolute_url }}"><strong>{{ student.get_full_name_or_uname }}</strong></a></h4> {% if student.get_flag_count > 4 %}
<h5>{{ student.graduating_year }}</h5> <p><em>* a number of other floormates say this info is incorrect</em></p>
{% if student.get_flag_count > 4 %} {% endif %}
<p><em>* a number of other floormates say this info is incorrect</em></p> </div>
{% endif %} {% if forloop.counter|divisibleby:4 %}
</div>
{% endif %}
{% empty %}
<div class="col-md-12">
<p>No visible students.</p>
</div> </div>
{% endfor %} <br />
</div> <div class="row">
</div>
</div>
<br />
<legend><strong><a href="{% url 'list_buildings' %}#Rappahannock">Rappahannock</a></strong></legend>
<div class="row">
<div class="col-md-12">
<div class="row">
{% for student in ra_location_visible %}
{% if not student in request.user.student.blocked_kids.all %}
<div class="col-sm-3 text-center">
<img class="img-circle img-responsive center center-block" src="{{ student.profile_image_url }}" alt="{{ student.get_first_name_or_uname }} profile picture">
<h4><a href="{{ student.get_absolute_url }}"><strong>{{ student.get_full_name_or_uname }}</strong></a></h4>
<h5>{{ student.graduating_year }}</h5>
{% if student.get_flag_count > 4 %}
<p><em>* a number of other floormates say this info is incorrect</em></p>
{% endif %}
</div>
{% endif %} {% endif %}
{% empty %} {% empty %}
<div class="col-md-12"> <div class="col-md-12">
<p>No visible students.</p> <p>No visible students.</p>
</div>
{% endfor %}
</div>
</div>
</div>
<br />
<legend><strong><a href="{% url 'list_buildings' %}#Shenandoah">Shenandoah</a></strong></legend>
<div class="row">
<div class="col-md-12">
<div class="row">
{% for student in sh_location_visible %}
{% if not student in request.user.student.blocked_kids.all %}
<div class="col-sm-3 text-center">
<img class="img-circle img-responsive center center-block" src="{{ student.profile_image_url }}" alt="{{ student.get_first_name_or_uname }} profile picture">
<h4><a href="{{ student.get_absolute_url }}"><strong>{{ student.get_full_name_or_uname }}</strong></a></h4>
<h5>{{ student.graduating_year }}</h5>
{% if student.get_flag_count > 4 %}
<p><em>* a number of other floormates say this info is incorrect</em></p>
{% endif %}
</div> </div>
{% endif %} {% endfor %}
{% empty %}
<div class="col-md-12">
<p>No visible students.</p>
</div> </div>
{% endfor %}
</div>
</div>
</div>
<br />
{% if location_hidden %}
<legend class="text-center">Off-campus/Location not visible because of student <a href="{% url 'update_student' request.user.username %}">privacy settings</a></legend>
<div class="row">
<div class="col-md-12">
{% for student in location_hidden %}
{% if not student in request.user.student.blocked_kids.all %}
<div class="col-sm-3 text-center">
<img class="img-circle img-responsive center center-block" src="{{ student.profile_image_url }}" alt="{{ student.get_first_name_or_uname }} profile picture">
<h4><a href="{{ student.get_absolute_url }}"><strong>{{ student.get_full_name_or_uname }}</strong></a></h4>
<h5>{{ student.graduating_year }}</h5>
</div>
{% endif %}
{% endfor %}
</div> </div>
</div> </div>
{% endif %} {% endfor %}
<br /> <hr />
<legend></legend>
{% include 'disclaimer.html' %} {% include 'disclaimer.html' %}
{% endcache %} {% endcache %}
......
...@@ -17,9 +17,9 @@ from cas.views import login as cas_login ...@@ -17,9 +17,9 @@ from cas.views import login as cas_login
from ratelimit.decorators import ratelimit from ratelimit.decorators import ratelimit
# imports from your apps # imports from your apps
from .models import Student, Major, Confirmation from .models import Student, Major, Confirmation
from housing.models import Building
from .forms import StudentUpdateForm from .forms import StudentUpdateForm
from .student_messages import return_messages from .student_messages import return_messages
from housing.views import shadowbanning
def custom_cas_login(request, *args, **kwargs): def custom_cas_login(request, *args, **kwargs):
...@@ -318,46 +318,12 @@ class DetailMajor(LoginRequiredMixin, DetailView): ...@@ -318,46 +318,12 @@ class DetailMajor(LoginRequiredMixin, DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(DetailMajor, self).get_context_data(**kwargs) context = super(DetailMajor, self).get_context_data(**kwargs)
requesting_student = 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
major_students = Student.objects.filter(major__in=[self.get_object()]).order_by('user__username') major_students = Student.objects.filter(major__in=[self.get_object()]).order_by('-graduating_year')
neighbourhoods = ("aq", "ra", "sh") context['major_students'] = shadowbanning(me, major_students)
visible_by_neighbourhood = {}
for neighbourhood in neighbourhoods:
# print(neighbourhood)
# grab all buildings in each neighborhood
buildings_by_neighbourhood = Building.objects.filter(neighbourhood=neighbourhood)
# print(buildings_by_neighbourhood)
# identify if the student(s) in that room are visible to the requesting student
# go building by building and assess if the students in that building
# with the current major are visible to the requesting student
# chain is a function that flattens arrays, and is neccesary when combining
# students from each building
# we sort each of the lists of students by their username
# as elsewhere, this is imperfect if a student changes their display name
# this is necessary as a separate step because .visible returns a list type
# note we're using '.' instead of '__', because who likes syntactical consistency
visible_by_neighbourhood[neighbourhood] = sorted(list(chain(*[
major_students.visible(requesting_student, building)
for building in buildings_by_neighbourhood
])), key=attrgetter('user.username'))
# see what students are left over (aren't visible)
hidden = set(major_students)
for visible in visible_by_neighbourhood.values():
# print('visible', visible)
hidden = hidden.difference(set(visible))
# print(hidden)
for neighbourhood, visible in visible_by_neighbourhood.iteritems():
context['%s_location_visible' % neighbourhood] = visible
context['location_hidden'] = hidden
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