views.py 1.79 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 28 29
    template_name='detailBuilding.html'

    def get_context_data(self, **kwargs):
        context = super(DetailBuilding, self).get_context_data(**kwargs)
        context['room_list'] = Room.objects.filter(building__name=''+self.get_object().name).order_by('number')
        return context
30 31 32 33 34 35 36 37 38 39 40 41
    login_url = '/'

# this lists the rooms on the floor
class ListRooms(LoginRequiredMixin, ListView):
    model = Room
    login_url = '/'

# this lists students in a room
class DetailRoom(LoginRequiredMixin, ListView):
    model = Room
    login_url = '/'

42
# update a student
43 44 45 46 47 48
#class UpdateStudent(LoginRequiredMixin, UpdateView):
#    model = Student
#    form_class = '/'
#    success_url = '/' # change the success url to something more interesting

#    login_url = '/'
49 50

# update a room
51 52 53 54
#class updateroom(loginrequiredmixin, updateview):
#    model = room
#    form_class =
#    success_url = '/' # change the success url to something more interesting
55

56
#    login_url = '/'