models.py 4.48 KB
Newer Older
Daniel Warren Bond's avatar
Daniel Warren Bond committed
1
from django.db import models
2
from django.contrib.auth.models import User
Daniel Warren Bond's avatar
Daniel Warren Bond committed
3

4
5
from django.db.models.signals import post_save

Daniel W Bond's avatar
Daniel W Bond committed
6
class BaseModel(models.Model):
Daniel W Bond's avatar
Daniel W Bond committed
7
    created = models.DateTimeField('Created', auto_now_add=True, editable=False)
Daniel W Bond's avatar
Daniel W Bond committed
8
9
10
11
12
13
14
    last_modified = models.DateTimeField('Last Modified', auto_now=True)

    class Meta:
        abstract = True

class Course(BaseModel):

15
    name = models.CharField(max_length = 150)
Daniel W Bond's avatar
Daniel W Bond committed
16
    courseSlug = models.SlugField(max_length = 50, unique=True)
17

Daniel W Bond's avatar
Daniel W Bond committed
18
    # ordering
19
20
    prerequisites = models.ManyToManyField('Course', related_name = 'prereqField', null=True)
    corequisites = models.ManyToManyField('Course', related_name = 'coreqField', null=True)
Daniel W Bond's avatar
Daniel W Bond committed
21
22
23
24

    # basic course information
    department = models.CharField(max_length = 150)
    departmentAbbr = models.CharField(max_length = 5)
Daniel W Bond's avatar
Daniel W Bond committed
25
    courseNumber = models.CharField(max_length = 3)
26
27
    courseDescription = models.TextField()
    credits = models.IntegerField()
Daniel W Bond's avatar
Daniel W Bond committed
28

29
30
31
    # catalog year for the course
    catalogYear = models.DateField()

32
33
34
35
36
37
    def isUpperClass:
      if courseNumber > 300:
          return True:
      else:
          return False

Daniel W Bond's avatar
Daniel W Bond committed
38
39
40
    # available next semester?
    # CRN
    # section number
Daniel W Bond's avatar
Daniel W Bond committed
41
    # professor
Daniel W Bond's avatar
Daniel W Bond committed
42
    
Daniel W Bond's avatar
Daniel W Bond committed
43
    # Course may need program-specific information
44

Daniel W Bond's avatar
Daniel W Bond committed
45
46
47
48
49
50
51
52
53
54
    # default sorting order in admin
    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
        return '/courses/%s/' % self.slug

Daniel W Bond's avatar
Daniel W Bond committed
55
56
57
# gen eds are coursecollections in programs
class CourseCollection(BaseModel):

58
59
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
60
    # a number of courses
61
    courses = models.ManyToManyField('Course',)
Daniel W Bond's avatar
Daniel W Bond committed
62

Daniel W Bond's avatar
Daniel W Bond committed
63
    # how many of those are required
64
65
    numReq = models.IntegerField()

66
67
68
69
70
71
    # function to determine if there is a difference between this and last year
    # not everything changes-- should be able to multiple reference to one thing

    # catalog year for the coursecollection
    catalogYear = models.DateField()

Daniel W Bond's avatar
Daniel W Bond committed
72
    # if the course collection's numreq is met
73
    isCompleted = models.BooleanField(False)
Daniel W Bond's avatar
Daniel W Bond committed
74
75
76

class Program(BaseModel):

77
    name = models.CharField(max_length = 150)
Daniel W Bond's avatar
Daniel W Bond committed
78
    # programSlug = models.SlugField(max_length = 50, unique = True)
79

Daniel W Bond's avatar
Daniel W Bond committed
80
    # major or minor or gened
Daniel W Bond's avatar
Daniel W Bond committed
81
    programType = models.CharField(max_length = 25)
Daniel W Bond's avatar
Daniel W Bond committed
82

Daniel W Bond's avatar
Daniel W Bond committed
83
84
85
    # courseCollections
    courseReqs =  models.ManyToManyField('CourseCollection',)

Daniel W Bond's avatar
Daniel W Bond committed
86
    # is BA, BS, Honors
Daniel W Bond's avatar
Daniel W Bond committed
87
88
89
    # all majors must take a gened program, null for minors, geneds
    # CHECK VIEWS, MAKE SURE I DIDN'T ALREADY SOMEHOW ACCOUNT FOR THIS
    degreeType = models.ManyToManyField('Program', null=True)
Daniel W Bond's avatar
Daniel W Bond committed
90

91
92
93
    # catalog year for the Program
    catalogYear = models.DateField()
    
Daniel W Bond's avatar
Daniel W Bond committed
94
95
    # if all coursecollections' and gened requirements are satisfied, then the
    # program is completed
96
97
    isCompleted = models.BooleanField(False)

Daniel W Bond's avatar
Daniel W Bond committed
98
99
100
101
102
103
    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

104
105
106
    # def get_absolute_url(self):
        # return 'my-trajectories/%s/' % self.slug

Daniel W Bond's avatar
Daniel W Bond committed
107
# should inherit from the standard Django User Model
108
class Student(models.Model):
Daniel W Bond's avatar
Daniel W Bond committed
109

110
    user = models.OneToOneField(User)
Daniel W Bond's avatar
Daniel W Bond committed
111
    # does User have a slug field?
112

113
    alreadyTaken = models.ManyToManyField('Course', null=True)
114
    
Daniel W Bond's avatar
Daniel W Bond committed
115
    # all of the student's trajectories
116
    trajectory = models.ManyToManyField('Trajectory', null=True)
117

Daniel W Bond's avatar
Daniel W Bond committed
118
119
    completedCourses = models.ManyToManyField('Course', null=True)

120
    # aka username, etc should all be here
Daniel W Bond's avatar
Daniel W Bond committed
121
122

    class Meta:
Daniel W Bond's avatar
Daniel W Bond committed
123
        ordering = ('user',)
Daniel W Bond's avatar
Daniel W Bond committed
124
125
126
127
128

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
Daniel W Bond's avatar
Daniel W Bond committed
129
        return self.name
130

131
132
133
134
135
136
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Student.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

137
138
class Trajectory(BaseModel):

139
    name = models.CharField(max_length = 150)
Daniel W Bond's avatar
Daniel W Bond committed
140
    trajectorySlug = models.SlugField(max_length = 50, unique = True)
141
142

    # Takes courses
143
    previousCourses = models.ManyToManyField('Trajectory',)
Daniel W Bond's avatar
Daniel W Bond committed
144

145
146
147
    # def getPreviousTrajectory(Trajectory):
        # return Trajectory

Daniel W Bond's avatar
Daniel W Bond committed
148
    # the program(s) that this trajectory is completing
Daniel W Bond's avatar
Daniel W Bond committed
149
    whichPrograms = models.ManyToManyField('Program',)
Daniel W Bond's avatar
Daniel W Bond committed
150
151

    # whether or not the trajectory can be seen by others
Daniel W Bond's avatar
Daniel W Bond committed
152
    isPublic = models.BooleanField()
153

154
    # semesters since entering college
155
156
    semester = models.IntegerField()

157
158
159
160
    class Meta:
        ordering = ('name',)
        verbose_name_plural = "trajectories"

161
162
    def get_absolute_url(self):
        return 'my-trajectories/%s/' % self.slug