Commit bfa76a06 authored by Daniel W Bond's avatar Daniel W Bond

added the shadowbanning filter to the housing pages and raising a 404 on the...

added the shadowbanning filter to the housing pages and raising a 404 on the detail student page, plus minor form updates; will need to fiddle with cacheing
parent 8083abd1
......@@ -6,7 +6,7 @@ from operator import attrgetter
from itertools import chain
# core django imports
from django.shortcuts import get_object_or_404
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.http import HttpResponseForbidden, HttpResponseRedirect, Http404
from django.views.generic import (CreateView, ListView, DetailView, UpdateView,
FormView, DeleteView)
from django.core.urlresolvers import reverse
......@@ -116,6 +116,17 @@ class DetailStudent(LoginRequiredMixin, DetailView):
login_url = 'login'
def get(self, request, *args, **kwargs):
current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3]
detailed_student = Student.objects.get(user__username=url_username)
if (detailed_student in self.request.user.student.blocked_kids.all()):
raise Http404
else:
return super(DetailStudent, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(DetailStudent, self).get_context_data(**kwargs)
......@@ -227,6 +238,7 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
'show_gender': me.show_gender,
'room': pk_or_none(me, me.room),
'privacy': me.privacy,
'blocked_kids': me.blocked_kids.all(),
'major': pk_or_none(me, me.major),
'graduating_year': me.graduating_year,
'on_campus': me.on_campus, })
......@@ -298,8 +310,8 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
me.gender = form.data.getlist('gender')
me.show_gender = strtobool(form.data.get('show_gender', 'False'))
me.privacy = form.data['privacy']
me.blocked_kids = form.data['blocked_kids']
me.graduating_year = form.data['graduating_year']
me.user.save()
me.save()
......
......@@ -9,6 +9,21 @@ from .models import Building, Floor, Room
from accounts.models import Student
# this should be written in cache, to be entirely honest
def shadowbanning(me, other_people):
# start with only students who are actually blocking anyone
blockers = [student for student in Student.objects.exclude(blocked_kids__exact='')]
# of those students, collect the ones that block *you*
blocks_me = [student
for student in blockers
if me in student.blocked_kids.all()]
if len(blocks_me):
student_safety = list(set(other_people) - set(blocks_me))
return student_safety
else:
return other_people
# a list of neighborhoods and their buildings
class ListBuildings(LoginRequiredMixin, ListView):
model = Building
......@@ -70,9 +85,13 @@ class DetailFloor(LoginRequiredMixin, DetailView):
requesting_student = Student.objects.get(user=self.request.user)
context['students'] = Student.objects.visible(requesting_student, self.get_object())
context['notOnFloor'] = not(requesting_student in self.get_object())
context['notInBuilding'] = not(requesting_student in self.get_object().building)
students = Student.objects.visible(requesting_student, self.get_object())
notOnFloor = not(requesting_student in self.get_object())
notInBuilding = not(requesting_student in self.get_object().building)
context['students'] = shadowbanning(requesting_student, students)
context['notOnFloor'] = shadowbanning(requesting_student, notOnFloor)
context['notInBuilding'] = shadowbanning(requesting_student, notInBuilding)
return context
......@@ -99,8 +118,11 @@ class DetailRoom(LoginRequiredMixin, DetailView):
requesting_student = Student.objects.get(user=self.request.user)
context['students'] = Student.objects.visible(requesting_student, self.get_object())
context['notOnFloor'] = not(requesting_student in self.get_object().floor)
context['notInBuilding'] = not(requesting_student in self.get_object().floor.building)
students = Student.objects.visible(requesting_student, self.get_object())
notOnFloor = not(requesting_student in self.get_object().floor)
notInBuilding = not(requesting_student in self.get_object().floor.building)
context['students'] = shadowbanning(requesting_student, students)
context['notOnFloor'] = shadowbanning(requesting_student, notOnFloor)
context['notInBuilding'] = shadowbanning(requesting_student, notInBuilding)
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