models.py 4.22 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
    # catalog year for the course
    catalogYear = models.DateField()

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

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

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

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

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

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

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

class Program(BaseModel):

76
77
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
78
    # courseCollections
79
    courseReqs =  models.ManyToManyField('CourseCollection',)
Daniel W Bond's avatar
Daniel W Bond committed
80
81

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

    # is BA, BS, Honors
Daniel W Bond's avatar
Daniel W Bond committed
85
86
87
    # 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
88

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

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

    def __unicode__(self):
        return self.name

Daniel W Bond's avatar
Daniel W Bond committed
102
# should inherit from the standard Django User Model
103
class Student(models.Model):
Daniel W Bond's avatar
Daniel W Bond committed
104

105
106
    user = models.OneToOneField(User)

Daniel W Bond's avatar
Daniel W Bond committed
107
    # all of the student's trajectories
108
    trajectory = models.ManyToManyField('Trajectory', null=True)
109

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

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

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

    def __unicode__(self):
        return self.name

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

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

post_save.connect(create_user_profile, sender=User)

129
130
class Trajectory(BaseModel):

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

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

Daniel W Bond's avatar
Daniel W Bond committed
136
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',)

    # whether or not the trajectory can be seen by others
Daniel W Bond's avatar
Daniel W Bond committed
141
    isPublic = models.BooleanField()
142
143
144
145
146

    # 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()

147
148
149
150
    class Meta:
        ordering = ('name',)
        verbose_name_plural = "trajectories"

151
152
153
    def get_absolute_url(self):
        return 'my-trajectories/%s/' % self.slug

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