models.py 4.32 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
16
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
17
    # ordering
18
19
    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
20
21
22
23

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

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

    # needs to be associated with a student, may not belong here
    isCompleted = models.BooleanField(False)

34
35
36
37
38
39
    def isUpperClass:
      if courseNumber > 300:
          return True:
      else:
          return False

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

Daniel W Bond's avatar
Daniel W Bond committed
47
48
49
50
51
52
53
54
55
56
    # 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
57
58
59
# gen eds are coursecollections in programs
class CourseCollection(BaseModel):

60
61
    name = models.CharField(max_length = 150)

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

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

68
69
70
71
72
73
    # 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
74
    # if the course collection's numreq is met
75
    isCompleted = models.BooleanField(False)
Daniel W Bond's avatar
Daniel W Bond committed
76
77
78

class Program(BaseModel):

79
80
    name = models.CharField(max_length = 150)

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

    # major or minor or gened
Daniel W Bond's avatar
Daniel W Bond committed
85
    programType = models.CharField(max_length = 25)
Daniel W Bond's avatar
Daniel W Bond committed
86
87

    # is BA, BS, Honors
Daniel W Bond's avatar
Daniel W Bond committed
88
89
90
    # 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
91

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

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

    def __unicode__(self):
        return self.name

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

108
109
    user = models.OneToOneField(User)

Daniel W Bond's avatar
Daniel W Bond committed
110
    # all of the student's trajectories
111
    trajectory = models.ManyToManyField('Trajectory', null=True)
112
113

    # aka username, etc should all be here
Daniel W Bond's avatar
Daniel W Bond committed
114
115

    class Meta:
Daniel W Bond's avatar
Daniel W Bond committed
116
        ordering = ('user',)
Daniel W Bond's avatar
Daniel W Bond committed
117
118
119
120
121

    def __unicode__(self):
        return self.name

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

124
125
126
127
128
129
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Student.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

130
131
class Trajectory(BaseModel):

132
    name = models.CharField(max_length = 150)
133
134

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

Daniel W Bond's avatar
Daniel W Bond committed
137
138
139
140
    # the program(s) that this trajectory is completing
    # CHECK VIEWS, MAKE SURE I DIDN'T ALREADY SOMEHOW ACCOUNT FOR THIS
    forPrograms = models.ManyToManyField('Program',)

141
142
    # function returns if it is an end node on the tree
    
Daniel W Bond's avatar
Daniel W Bond committed
143
    # whether or not the trajectory can be seen by others
Daniel W Bond's avatar
Daniel W Bond committed
144
    isPublic = models.BooleanField()
145
146
147
148
149

    # this isn't exactly done correctly-- ideally courses should be elements
    # of a list, not one created for each and every semester
    semester = models.IntegerField()

150
151
152
153
    class Meta:
        ordering = ('name',)
        verbose_name_plural = "trajectories"

154
155
156
    def get_absolute_url(self):
        return 'my-trajectories/%s/' % self.slug

Daniel W Bond's avatar
Daniel W Bond committed
157
        return '/%s/' % self.slug