models.py 3.92 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
    def isUpperClass:
      if courseNumber > 300:
          return True:
      else:
          return False

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

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

54
55
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
56
    # a number of courses
57
    courses = models.ManyToManyField('Course',)
Daniel W Bond's avatar
Daniel W Bond committed
58

Daniel W Bond's avatar
Daniel W Bond committed
59
    # how many of those are required
60
61
    numReq = models.IntegerField()

Daniel W Bond's avatar
Daniel W Bond committed
62
    # if the course collection's numreq is met
63
    isCompleted = models.BooleanField(False)
Daniel W Bond's avatar
Daniel W Bond committed
64
65
66

class Program(BaseModel):

67
68
    name = models.CharField(max_length = 150)

Daniel W Bond's avatar
Daniel W Bond committed
69
    # courseCollections
70
    courseReqs =  models.ManyToManyField('CourseCollection',)
Daniel W Bond's avatar
Daniel W Bond committed
71
72

    # major or minor or gened
Daniel W Bond's avatar
Daniel W Bond committed
73
    programType = models.CharField(max_length = 25)
Daniel W Bond's avatar
Daniel W Bond committed
74
75

    # is BA, BS, Honors
Daniel W Bond's avatar
Daniel W Bond committed
76
77
78
    # 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
79

Daniel W Bond's avatar
Daniel W Bond committed
80
81
    # if all coursecollections' and gened requirements are satisfied, then the
    # program is completed
82
83
    isCompleted = models.BooleanField(False)

Daniel W Bond's avatar
Daniel W Bond committed
84
85
86
87
88
89
    class Meta:
        ordering = ('name',)

    def __unicode__(self):
        return self.name

Daniel W Bond's avatar
Daniel W Bond committed
90
# should inherit from the standard Django User Model
91
class Student(models.Model):
Daniel W Bond's avatar
Daniel W Bond committed
92

93
94
    user = models.OneToOneField(User)

Daniel W Bond's avatar
Daniel W Bond committed
95
    # the student's already-completed classes, the root of the trajectory tree
96
    alreadyTaken = models.ManyToManyField('Course', null=True)
97
    
Daniel W Bond's avatar
Daniel W Bond committed
98
    # all of the student's trajectories
99
    trajectory = models.ManyToManyField('Trajectory', null=True)
100
101

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

    class Meta:
Daniel W Bond's avatar
Daniel W Bond committed
104
        ordering = ('user',)
Daniel W Bond's avatar
Daniel W Bond committed
105
106
107
108
109

    def __unicode__(self):
        return self.name

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

112
113
114
115
116
117
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        Student.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

118
119
class Trajectory(BaseModel):

120
    name = models.CharField(max_length = 150)
121
122

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

Daniel W Bond's avatar
Daniel W Bond committed
125
126
127
128
129
    # 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
130
    isPublic = models.BooleanField()
131
132
133
134
135

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

136
137
138
139
    class Meta:
        ordering = ('name',)
        verbose_name_plural = "trajectories"

140
141
142
    def get_absolute_url(self):
        return 'my-trajectories/%s/' % self.slug

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