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

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

Ben Waters's avatar
Ben Waters committed
10
from mainapp.serializers import (ProgramSerializer, CourseSerializer,
Ben Waters's avatar
Ben Waters committed
11
CourseGroupSerializer, TrajectorySerializer, SemesterSerializer,
Ben Waters's avatar
Ben Waters committed
12
BuildResponseSerializer, RequirementSerializer)
Ben Waters's avatar
Ben Waters committed
13
from mainapp.models import (Trajectory, Program, Major, Minor, GenEd,
Ben Waters's avatar
Ben Waters committed
14
Concentration, MetaCourse, Course, CourseGroup, Semester, BuildResponse,
Ben Waters's avatar
Ben Waters committed
15
Student, Requirement)
Ben Waters's avatar
Ben Waters committed
16
from mainapp.forms import StartTrajectoryForm, StudentForm
Daniel W Bond's avatar
Daniel W Bond committed
17
# Create your views here.
Ben Waters's avatar
Ben Waters committed
18 19
#FBV's
# Generic Views
Ben Waters's avatar
Ben Waters committed
20
def build_trajectory(request):
Ben Waters's avatar
Ben Waters committed
21
    #process
Ben Waters's avatar
Ben Waters committed
22
    semester_key = 1
Ben Waters's avatar
Ben Waters committed
23
    return HttpResponse(semester_key)
Ben Waters's avatar
Ben Waters committed
24 25 26 27 28 29 30 31 32 33 34 35 36
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
37
            return build_trajectory(request)
Ben Waters's avatar
Ben Waters committed
38

Ben Waters's avatar
Ben Waters committed
39
#API SHIT
Ben Waters's avatar
Ben Waters committed
40
@login_required
Ben Waters's avatar
Ben Waters committed
41
def profile(request):
Ben Waters's avatar
Ben Waters committed
42
    current_user = get_object_or_404(Student,user__username=request.user.username)
Ben Waters's avatar
Ben Waters committed
43
    return render_to_response('profile.html', {
Ben Waters's avatar
idk  
Ben Waters committed
44
            "current_user" : current_user,
Ben Waters's avatar
Ben Waters committed
45
            "firstname" : current_user.user.first_name,
Ben Waters's avatar
work  
Ben Waters committed
46
            "advisorname" : current_user.advisorname,
Ben Waters's avatar
Ben Waters committed
47
    })
Ben Waters's avatar
maybe  
Ben Waters committed
48
    
Ben Waters's avatar
Ben Waters committed
49

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

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

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

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

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

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

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

Ben Waters's avatar
Ben Waters committed
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 153
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
154 155 156 157 158 159 160 161
class DetailStudent(DetailView):
    model = Student
    template_name = 'student.html'

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