views.py 2.64 KB
Newer Older
1
from django.shortcuts import render, get_object_or_404
Jason D Yeomans's avatar
Jason D Yeomans committed
2

Daniel W Bond's avatar
Daniel W Bond committed
3
from django.views.generic import DetailView, ListView, UpdateView, UpdateView, DeleteView
4

5
from accounts.models import Student
6
7
8

from braces.views import LoginRequiredMixin

Daniel W Bond's avatar
Daniel W Bond committed
9
10
# update a student (students are *created* on first login via CAS)
class UpdateStudent(LoginRequiredMixin, UpdateView):
Daniel W Bond's avatar
Daniel W Bond committed
11
    model = Student
Daniel W Bond's avatar
Daniel W Bond committed
12
13
    fields = ['room', 'privacy',]

Daniel W Bond's avatar
Daniel W Bond committed
14
15
    login_url = '/'

Daniel W Bond's avatar
Daniel W Bond committed
16
17
18
19
    # copied from below
    def get_object(self):
        return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])

20
21
22
# details about the student
class DetailStudent(LoginRequiredMixin, DetailView):
    model = Student
Daniel W Bond's avatar
Daniel W Bond committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

    def get_context_data(self, **kwargs):
        context = super(DetailStudent, self).get_context_data(**kwargs)

        # requesting_student = Student.objects.get(user=self.request.user)
        requesting_student_filter = Student.objects.filter(user=self.request.user)
        requesting_student = requesting_student_filter[0]

        def onFloor():
            floor_status = False
            if requesting_student.get_floor() == self.get_object().get_floor():
                floor_status = True
            return floor_status

        def inBuilding():
            floor_status = False
            if requesting_student.get_building() == self.get_object().get_building():
                floor_status = True
            return floor_status

        def shares():
            student_shares = False
            # if the student's privacy is floor and the requesting user is on their floor
            if(self.get_object().privacy == 'floor') and onFloor():
                student_shares = True
            # if the student's privacy is building and the requesting users is on their floor or in their building
            elif(self.get_object().privacy == 'building') and inBuilding():
                student_shares = True
            # if the student's privacy is set to 'student'
            elif(self.get_object().privacy == 'students'):
                student_shares = True
            return student_shares
           
        context['shares'] = shares()
        return context

    login_url = '/'
60
61
62
63

# changeable student settings
class DetailStudentSettings(LoginRequiredMixin, DetailView):
    model = Student
Daniel W Bond's avatar
Daniel W Bond committed
64
    login_url = '/'
65
66
67
68
69
70
71
72
73
74
75
76
77
78

class DetailCurrentStudent(LoginRequiredMixin, DetailView):

    #model = Student

    def get_object(self):
        return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])

class DetailCurrentStudentSettings(LoginRequiredMixin, DetailView):

    #model = Student

    def get_object(self):
        return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])