Commit 7b225fa2 authored by Ben Waters's avatar Ben Waters

added utils file

parent 22000642
from django.shortcuts import render, get_object_or_404
from django.db.models import Max
from django.views.generic import *
from trajectories.models import Course, CourseCollection, Program, Student, Trajectory
from trajecgtories.utils import *
from braces.views import LoginRequiredMixin
# processing functions
# run on each coursecollection
def remainingReqCourses(requiredCourses, coursesTaken):
""" returns remaining courses for program """
remainingReqCourses = []
for course in requiredCourses:
if course not in coursesTaken:
def allPrereqCoreq(course, remainingReqCourses):
""" returns required courses that have course as a prereq or coreq """
allPrereqCoreq = []
for requiredCourse in remainingReqCourses:
for prereq in course.prereqs:
if prereq is requiredCourse:
for coreq in course.coreqs:
if coreq is requiredCourse:
return allPreqCoreq
# run on each coursecollection
def nextCourses(coursesTaken, remainingReqCourses):
""" returns the courses student can take given what's been taken """
nextCourses = []
for course in remainingReqCourses:
if course.prereqs not in coursesTaken:
# you have to take the prereqs for something first
elif course.coreq not in coursesTaken:
possibility = allPrereqCoreq(course, remainingReqCourses)
return nextCourses
# this algorithm sucks because if there's a change to the number of allowed
# majors then this will break
def getGenEds(programs, isHonors):
""" returns the gen eds a student has to take based on their selected
programs """
genEdList = []
if isHonors:
# will require a program in the database called "Honors"
return genEdList
firstMajorType = program[0].degreeType
secondMajor = program[1].degreeType
if firstMajorType is secondMajorType:
return genEdList
return genEdList
def maxProgramsAllowed(programList, maxProgramNumber):
""" called to ensure student can't sign up for more than 2 majors, etc """
if (len(programList) + 1) > maxProgramNumer:
return False
return True
def fulfilledReq(coursesTaken, courseCollection, numReq):
""" makes CourseCollection.isCompleted True if completed
should only use where isCompleted is False
can also be used for Program.isCompleted """
finished = 0
for reqCourse in courseCollection:
if reqCourse in coursesTaken:
finished += 1
if finished >= numReq:
courseCollection.isCompleted = True
def topTrajectories(trajectories):
""" Only shows the uppermost level of trajectories--
there's no reason that *all* of the previously loaded classes
need be gone through; furthermore, students only need to see
the top level of each of their trajectories on their homepage """
names = set()
for trajectory in trajectories:
topTrajectories = []
for name in names:
namedTrajectories = trajectories.filter(name = name)
topNamedTrajectory = namedTrajectories.aggregate(Max('semester'))
return topTrajectories
def enoughCourses(coursesTaken, degreeCreditsReqNum):
""" required credits for degree program """
if len(coursesTaken) > degreeCreditsReqNum: #120
return True
return False
#def enoughUpperLevelCourses(coursesTaken, upperLevelReqNum):
# """ required upper level courses for program """
# upperLevelCourses = []
# for course in coursesTaken:
# if course.isUpperClass:
# course.append(upperLevelCourses)
# if len(upperLevelCourses > upperLevelNum):
# return True
# else:
# return False
# note: coreq requirements are fulfilled through onpage javascript, not here
# page render functions
# a page for creating new trajectories
# @login_required
def create_trajectory(LoginRequiredMixin, CreateView):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment