views.py 4.22 KB
Newer Older
Ben Waters's avatar
Ben Waters committed
1
2
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
Ben Waters's avatar
Ben Waters committed
3
4
from django.views.generic import (CreateView, ListView, DetailView, DeleteView,
UpdateView, FormView)
Ben Waters's avatar
Ben Waters committed
5

Ben Waters's avatar
Ben Waters committed
6
from rest_framework import viewsets
Ben Waters's avatar
Ben Waters committed
7
from braces.views import LoginRequiredMixin
Ben Waters's avatar
Ben Waters committed
8

Ben Waters's avatar
Ben Waters committed
9
from mainapp.serializers import (ProgramSerializer, CourseSerializer,
Ben Waters's avatar
Ben Waters committed
10
CourseGroupSerializer, TrajectorySerializer, SemesterSerializer,
Ben Waters's avatar
Ben Waters committed
11
BuildResponseSerializer, RequirementSerializer)
Ben Waters's avatar
Ben Waters committed
12
from mainapp.models import (Trajectory, Program, Major, Minor, GenEd,
Ben Waters's avatar
Ben Waters committed
13
Concentration, MetaCourse, Course, CourseGroup, Semester, BuildResponse,
Ben Waters's avatar
Ben Waters committed
14
Student, Requirement)
Ben Waters's avatar
Ben Waters committed
15
from mainapp.forms import StartTrajectoryForm, StudentForm
Daniel W Bond's avatar
Daniel W Bond committed
16
# Create your views here.
Ben Waters's avatar
Ben Waters committed
17
18
#FBV's
# Generic Views
Ben Waters's avatar
Ben Waters committed
19
def build_trajectory(request):
Ben Waters's avatar
Ben Waters committed
20
    #process
Ben Waters's avatar
Ben Waters committed
21
    semester_key = 1
Ben Waters's avatar
Ben Waters committed
22
    return HttpResponse(semester_key)
Ben Waters's avatar
Ben Waters committed
23
24
25
26
27
28
29
30
31
32
33
34
35
def searchMajorMinor(request):
    #query
    if request.method == 'POST':
        form = StartTrajectoryForm(request.POST)
        if form.is_valid():
            #Queryset
            major = Major.objects.filter(name=form['major'])
            minor = Minor.objects.filter(name=form['minor'])
            #Check to seee if empty
            if major is None:
                msg = "Something Went Wrong"
            else:
                msg = "Found Object"
Ben Waters's avatar
Ben Waters committed
36
            return build_trajectory(request)
Ben Waters's avatar
Ben Waters committed
37

Ben Waters's avatar
Ben Waters committed
38
#API SHIT
Ben Waters's avatar
Ben Waters committed
39
@login_required
Ben Waters's avatar
Ben Waters committed
40
41
42
43
44
45
46
47
def profile(request):
    current_user = Student.objects.get(user__username=request.user.username)

    return render_to_response('profile.html', {
            "user" : current_user,
    },
    context_instance = RequestContext(request),
    )
Ben Waters's avatar
Ben Waters committed
48

Ben Waters's avatar
Ben Waters committed
49
50
51
52
class RequirementViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Requirement.objects.all()
    serializer_class = RequirementSerializer

Ben Waters's avatar
Ben Waters committed
53
54
55
56
class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Program.objects.all()
    serializer_class = ProgramSerializer

Ben Waters's avatar
Ben Waters committed
57
class CourseViewSet(viewsets.ReadOnlyModelViewSet):
Ben Waters's avatar
Ben Waters committed
58
59
60
    queryset = Course.objects.all()
    serializer_class = CourseSerializer

Ben Waters's avatar
Ben Waters committed
61
class CourseGroupViewSet(viewsets.ReadOnlyModelViewSet):
Ben Waters's avatar
Ben Waters committed
62
63
64
    queryset = CourseGroup.objects.all()
    serializer_class = CourseGroupSerializer

Ben Waters's avatar
Ben Waters committed
65
class TrajectoryViewSet(viewsets.ModelViewSet):
Ben Waters's avatar
Ben Waters committed
66
67
68
    queryset = Trajectory.objects.all()
    serializer_class = TrajectorySerializer

Ben Waters's avatar
Ben Waters committed
69
70
71
class SemesterViewSet(viewsets.ModelViewSet):
    queryset = Semester.objects.all()
    serializer_class = SemesterSerializer
Ben Waters's avatar
Ben Waters committed
72
73
74
class BuildResponseViewSet(viewsets.ModelViewSet):
    queryset = BuildResponse.objects.all()
    serializer_class = BuildResponseSerializer
Ben Waters's avatar
Ben Waters committed
75
#FORM CBV's
76

Ben Waters's avatar
Ben Waters committed
77
#Trajectory CBVS
Ben Waters's avatar
Ben Waters committed
78
79
80
81
class DetailBuildResponse(DetailView):
    model = BuildResponse
    template_name = 'build.html'

Ben Waters's avatar
Ben Waters committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class CreateTrajectory(CreateView):
    model = Trajectory
#To Impement
'''
class ListTrajectory(ListView):
    pass
'''
class DetailTrajectory(DetailView):
    model = Trajectory

class DeleteTrajectory(DeleteView):
    model = Trajectory

class UpdateTrajectory(UpdateView):
    model = Trajectory

#Program CBVS
class CreateProgram(CreateView):
    model = Program

class ListProgram(ListView):
    model = Program

class DetailProgram(DetailView):
    model = Program

class DeleteProgram(DeleteView):
    model = Program

class UpdateProgram(UpdateView):
    model = Program

#Major CBVs
class ListMajor(ListView):
    model = Major

class DetailMajor(DetailView):
    model = Major

#Minor CBVs
class ListMinor(ListView):
    model = Minor

class DetailMinor(DetailView):
    model = Minor
#GenEd CBV
class ListGenEd(ListView):
    model = GenEd
class DetailGenEd(DetailView):
    model = GenEd
#Concentration CBV
class ListConcentration(ListView):
    model = Concentration

class DetailConcentration(DetailView):
    model = Concentration
#MetaCourse CBV
class ListMetaCourse(ListView):
    model = MetaCourse
class DetailMetaCourse(DetailView):
    model = MetaCourse
#Course CBV
class ListCourse(ListView):
    model = Course
class DetailCourse(DetailView):
    model = Course
#CourseGroup CBV
class ListCourseGroup(ListView):
    model = CourseGroup
class DetailCourseGroup(DetailView):
    model = CourseGroup
Ben Waters's avatar
Ben Waters committed
153
154
155
156
157
158
159
160
class DetailStudent(DetailView):
    model = Student
    template_name = 'student.html'

class CoursesTaken(UpdateView):
    model = Student
    template_name = 'student_form.html'
    form_class = StudentForm