views.py 4.87 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.models import User
Ben Waters's avatar
Ben Waters committed
4
from django.contrib.auth.decorators import login_required
Ben Waters's avatar
Ben Waters committed
5 6
from django.views.generic import (CreateView, ListView, DetailView, DeleteView,
UpdateView, FormView)
Ben Waters's avatar
Ben Waters committed
7

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

Ben Waters's avatar
Ben Waters committed
11
from mainapp.serializers import (ProgramSerializer, CourseSerializer,
Ben Waters's avatar
Ben Waters committed
12
CourseGroupSerializer, TrajectorySerializer, SemesterSerializer,
Ben Waters's avatar
Ben Waters committed
13
BuildResponseSerializer, RequirementSerializer)
Ben Waters's avatar
Ben Waters committed
14
from mainapp.models import (Trajectory, Program, Major, Minor, GenEd,
Ben Waters's avatar
Ben Waters committed
15
Concentration, MetaCourse, Course, CourseGroup, Semester, BuildResponse,
Ben Waters's avatar
Ben Waters committed
16
Student, Requirement)
Ben Waters's avatar
Ben Waters committed
17
from mainapp.forms import StartTrajectoryForm, StudentForm
Ben Waters's avatar
Ben Waters committed
18
from mainapp.utils import genTrajectories
Daniel W Bond's avatar
Daniel W Bond committed
19
# Create your views here.
Ben Waters's avatar
Ben Waters committed
20 21
#FBV's
# Generic Views
Ben Waters's avatar
Ben Waters committed
22
@login_required
Ben Waters's avatar
Ben Waters committed
23
def build_trajectory(request):
Ben Waters's avatar
Ben Waters committed
24
    #process
Ben Waters's avatar
Ben Waters committed
25 26
    if request.method == "POST":
        form = StartTrajectoryForm(request.POST)
Ben Waters's avatar
Ben Waters committed
27 28 29
        #only lets you do one
        major = form['majors'].value() 
        minor = form['minors'].value()
Ben Waters's avatar
Ben Waters committed
30 31
        to_search_major = Major.objects.get(pk=major[0])
        to_search_minor = Minor.objects.get(pk=minor[0])
Ben Waters's avatar
Ben Waters committed
32 33 34
        cs101 = Course.objects.get(pk=737)
        taken = []
        taken.append(cs101)
Ben Waters's avatar
Ben Waters committed
35
        programs = []
Ben Waters's avatar
praying  
Ben Waters committed
36 37
        programs.append(to_search_major)
        programs.append(to_search_minor)
Ben Waters's avatar
Ben Waters committed
38
        user_in = Student.objects.get(user__username=request.user.username)
Ben Waters's avatar
Ben Waters committed
39
        trac = genTrajectories(taken=taken,programs=programs,user=user_in)
Ben Waters's avatar
Ben Waters committed
40
        #majors = form.fie
Ben Waters's avatar
Ben Waters committed
41
    return render_to_response('build.html', {
Ben Waters's avatar
Ben Waters committed
42
        'trac' : trac,
Ben Waters's avatar
Ben Waters committed
43
    })
Ben Waters's avatar
Ben Waters committed
44 45 46
class StartTrajectoryView(FormView):
    template_name = 'new.html'
    form_class = StartTrajectoryForm
Ben Waters's avatar
Ben Waters committed
47

Daniel W Bond's avatar
Daniel W Bond committed
48 49 50 51 52
# BEN MAKE THIS A CBV OR SOMETHING IDK
def search(request):
    return render_to_response('search.html', {
    })

Ben Waters's avatar
Ben Waters committed
53
#API SHIT
Ben Waters's avatar
Ben Waters committed
54
@login_required
Ben Waters's avatar
Ben Waters committed
55
def profile(request):
Ben Waters's avatar
Ben Waters committed
56
    current_user = get_object_or_404(Student,user__username=request.user.username)
Ben Waters's avatar
Ben Waters committed
57
    return render_to_response('profile.html', {
Ben Waters's avatar
idk  
Ben Waters committed
58
            "current_user" : current_user,
Ben Waters's avatar
Ben Waters committed
59
            "firstname" : current_user.user.first_name,
Ben Waters's avatar
work  
Ben Waters committed
60
            "advisorname" : current_user.advisorname,
Ben Waters's avatar
Ben Waters committed
61
    })
Ben Waters's avatar
Ben Waters committed
62 63 64 65
class RequirementViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Requirement.objects.all()
    serializer_class = RequirementSerializer

Ben Waters's avatar
Ben Waters committed
66 67 68 69
class ProgramViewSet(viewsets.ReadOnlyModelViewSet):
    queryset = Program.objects.all()
    serializer_class = ProgramSerializer

Ben Waters's avatar
Ben Waters committed
70
class CourseViewSet(viewsets.ReadOnlyModelViewSet):
Ben Waters's avatar
Ben Waters committed
71 72 73
    queryset = Course.objects.all()
    serializer_class = CourseSerializer

Ben Waters's avatar
Ben Waters committed
74
class CourseGroupViewSet(viewsets.ReadOnlyModelViewSet):
Ben Waters's avatar
Ben Waters committed
75 76 77
    queryset = CourseGroup.objects.all()
    serializer_class = CourseGroupSerializer

Ben Waters's avatar
Ben Waters committed
78
class TrajectoryViewSet(viewsets.ModelViewSet):
Ben Waters's avatar
Ben Waters committed
79 80 81
    queryset = Trajectory.objects.all()
    serializer_class = TrajectorySerializer

Ben Waters's avatar
Ben Waters committed
82 83 84
class SemesterViewSet(viewsets.ModelViewSet):
    queryset = Semester.objects.all()
    serializer_class = SemesterSerializer
Ben Waters's avatar
Ben Waters committed
85 86 87
class BuildResponseViewSet(viewsets.ModelViewSet):
    queryset = BuildResponse.objects.all()
    serializer_class = BuildResponseSerializer
Ben Waters's avatar
Ben Waters committed
88
#FORM CBV's
89

Ben Waters's avatar
Ben Waters committed
90
#Trajectory CBVS
Ben Waters's avatar
Ben Waters committed
91 92 93 94
class DetailBuildResponse(DetailView):
    model = BuildResponse
    template_name = 'build.html'

Ben Waters's avatar
Ben Waters committed
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 154 155 156 157 158 159 160 161 162 163 164 165
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
166 167 168 169 170 171 172 173
class DetailStudent(DetailView):
    model = Student
    template_name = 'student.html'

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