views.py 1.75 KB
Newer Older
1 2
from django.views.generic import DetailView, ListView, CreateView, UpdateView, DeleteView

3 4
from housing.models import Building, Room
from accounts.models import Student
5

6 7
from braces.views import LoginRequiredMixin

8 9 10 11 12
# a list of neighborhoods and their buildings
class ListBuildings(LoginRequiredMixin, ListView):
    model = Building
    login_url = '/'

Daniel W Bond's avatar
Daniel W Bond committed
13 14 15 16 17 18 19
    def get_context_data(self, **kwargs):
        context = super(ListBuildings, self).get_context_data(**kwargs)
        context['rappahannock'] = Building.objects.filter(neighbourhood='ra')
        context['shenandoah'] = Building.objects.filter(neighbourhood='sh')
        context['aquia'] = Building.objects.filter(neighbourhood='aq')
        return context

20 21 22
# building floors, other information
class DetailBuilding(LoginRequiredMixin, DetailView):
    model = Building
23
    context_object_name = 'building'
24 25 26 27
    template_name='detailBuilding.html'

    def get_context_data(self, **kwargs):
        context = super(DetailBuilding, self).get_context_data(**kwargs)
28
        context['floors'] = Floor.objects.filter(building__name=''+self.get_object().name_.order_by('-number')
29
        return context
30

31 32 33
    login_url = '/'

# this lists the rooms on the floor
34 35 36 37 38 39 40
class DetailFloor(LoginRequiredMixin, DetailView):
    model = Floor
    context_object_name = 'floor'
    template_name = detail_floor.html

    def get_context_data(self, **kwargs):
        context = super(DetailFloor, self):
41
        # perhaps change to get the students, and then list by rooms?
42 43 44
        context['rooms'] = Room.objects.filter(floor=self.get_object()).order_by('-number')
        return context

45 46
    login_url = '/'

47
# deleted 'DetailRoom' view-- inhabitants will be listed on the floor page
48

49
# deleted 'UpdateRoom' view-- that will be handled on the user's page