views.py 2.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
# standard library imports
from __future__ import absolute_import, print_function
# core django imports
from django.shortcuts import render
from django.views.generic import (View, DetailView, TemplateView)
# third party imports
from braces.views import LoginRequiredMixin
from cas.views import login as cas_login
from accounts.models import Student
10
11
# imports from your apps
from housing.views import shadowbanning
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

class HomePageView(View):
    def get(self, request, *args, **kwargs):
        if self.request.user.is_authenticated():
            view = LandingPage.as_view()
            return view(request, *args, **kwargs)
        else:
            view = LandingPageNoAuth.as_view()
            return view(request, *args, **kwargs)

class LandingPage(LoginRequiredMixin, TemplateView):
    template_name = 'landing.html'
    def get_context_data(self, **kwargs):
        context = super(LandingPage, self).get_context_data(**kwargs)
        me = Student.objects.get(user=self.request.user)
Daniel W Bond's avatar
Daniel W Bond committed
27
        context['me'] = me
28
29

        # Create Dictionaries to store Students that meet criteria
30
31
32
        roomies = Student.objects.filter(room=me.room).exclude(user__username=me)
        floories = Student.objects.filter(room__floor=me.get_floor()).exclude(user__username=me).exclude(room=me.room).order_by('room')
        majormates = Student.objects.filter(major=me.major).exclude(user__username=me).order_by('?')[:8]
33

34
35
36
        context["roomies"] = shadowbanning(me, roomies)
        context["floories"] = shadowbanning(me, floories)
        context["majormates"] = shadowbanning(me, majormates)
37
        # Hack to Correctly Display Building plus Floor
Daniel W Bond's avatar
Daniel W Bond committed
38
39
40
41
42
43
44
        #floor = str(me.get_floor())
        #if floor[len(floor)-1:len(floor)] == "1":
        #    context["home"] = "%s %s" %(me.get_building(), 'First')
        #elif floor[len(floor)-1:len(floor)] == "2":
        #    context["home"] = "%s %s" %(me.get_building(), 'Second')
        #else:
        #    context["home"] = "%s %s" %(me.get_building(), 'Third')
45
46
47
48
49
50
51

        return context

class LandingPageNoAuth(DetailView):
    template_name = 'index.html'
    def get(self, request, *args, **kwargs):
        return render(request, self.template_name)