Project

General

Profile

Revision 03f9c52d

ID03f9c52d18721a3119e9056154e19113ee50963d
Parent cd771306
Child b2863bff

Added by Julian Binder over 11 years ago

Finished defining models. Also added function to create RoboUser
instances. Also modified settings to look for RoboUser as the default
user class.

View differences:

crm/crm/settings.py
3 3
DEBUG = True
4 4
TEMPLATE_DEBUG = DEBUG
5 5

  
6
AUTH_PROFILE_MODULE = 'robocrm.RoboUser'
7

  
6 8
ADMINS = (
7 9
    ('Julian Binder', 'jabinder@andrew.cmu.edu'),
8 10
)
crm/robocrm/models.py
1 1
from django.db import models
2
from django.contrib.auth.models import User
3
from django.db.models.signals import post_save
4

  
2 5

  
3 6
# User Model
4
class RoboUser(AbstractBaseUser):
5
  andrewID = models.CharField(max_length=8, unique=True, db_index=True)
7
class RoboUser(models.Model):
8
  # Field is required when using profiles 
9
  user = models.OneToOneField(User)
10

  
11
  # Roboclub RFID Card number
12
  rfid = models.DecimalField(max_digits=10, decimal_places=0)
6 13
  
14
  # Roboclub Shop Access Permissions
15
  machines = models.ManyToManyField(Machine)
16

  
17
  # Cell Phone
18
  cell = models.DecimalField(max_digits=10, decimal_places=0)
7 19

  
20
  # Class Level
21
  FRESHMAN = 'FR'
22
  SOPHOMORE = 'SO'
23
  JUNIOR = 'JR'
24
  SENIOR = 'SR'
25
  MASTERS = 'MS'
26
  DOCTORAL = 'DR'
27
  CLASS_LEVEL_CHOICES = (
28
      (FRESHMAN, 'Freshman'),
29
      (SOPHOMORE, 'Sophomore'),
30
      (JUNIOR, 'Junior'),
31
      (SENIOR, 'Senior'),
32
      (MASTERs, 'Masters'),
33
      (DOCTORAL, 'Doctoral'),
34
  )
35
  class_level = models.CharField(max_length=2, 
36
                                 choices=CLASS_LEVEL_CHOICES,
37
                                 default=FRESHMAN)
8 38

  
39
  # Graduation Year
40
  grad_year = models.DecimalField(max_digits=4, decimal_places=0)
9 41

  
10
  USERNAME_FIELD = 'andrewID'
42
  # Primary and Secondary Major/Minors
43
  major = models.CharField(max_length=20)
44
  sec_major_one = models.CharField(max_length=20)
45
  sec_major_two = models.CharField(max_lenght=20)
46

  
47
  #Club Rank
48
  JUNIOR_MEM = 'JM'
49
  SENIOR_MEM = 'SM'
50
  OFFICER = 'OM'
51
  CLUB_RANK_CHOICES = (
52
      (JUNIOR_MEM, 'Junior Member'),
53
      (SENIOR_MEM, 'Senior Member'),
54
      (OFFICER, 'Officer'),
55
  )
56
  club_rank = models.CharField(max_length=2, 
57
                               choices=CLUB_RANK_CHOICES,
58
                               default=JUNIOR_MEM)
59
  
60
  # Roboclub Transaction Info
61
  dues_paid = models.DateField()
62
  tshirt_rec = models.BooleanField(default=False)
11 63
  
64
  # Shop and E-Bench Status
65
  GOOD = 'GD'
66
  FIRST_WARN = 'FS'
67
  SECOND_WARN = 'SD'
68
  SEM_BAN = 'SB'
69
  CLUB_BAN = 'CB'
70
  STATUS_CHOICES = (
71
      (GOOD, 'Good Standing'),
72
      (FIRST_WARN, 'First Warning Recieved'),
73
      (SECOND_WARN, 'Second Warning Recieved'),
74
      (SEM_BAN, 'Semester Ban'),
75
      (CLUB_BAN, 'Club Ban')
76
  )
77
  bench_status = models.CharField(max_length=2,
78
                                  choices=STATUS_CHOICES,
79
                                  default=GOOD)
80
  shop_status = models.CharField(max_length=2,
81
                                  choices=STATUS_CHOICES,
82
                                  default=GOOD)
83
# needed for Django Auth model
84
def create_roboclub_user(sender, instance, created, **kwargs):
85
  if created:
86
      RoboUser.objects.create(user=instance)
87
post_save.connect(create_roboclub_user, sender=User)
88

  
89

  
90
# Machine Model
91
class Machine(models.Model)
92
  type = models.CharField(max_length=20)
93
  id = models.CharField(max_length=10, unique=True)
94
  maint = models.BooleanField(default=False)
95
  dstart = models.DateTimeField()
96
  dend = models.DateTimeField()
97

  
98
# Event Model
99
class Event(models.Model)
100
  type = models.CharField(max_length=30)
101
  tstart = models.DateTimeField()
102
  tend = models.DateTimeField()
103
  user = models.ForeignKey('RoboUser')
104
  succ = models.BooleanField(default=False)
105
  imgurl = models.URLField()
106
  machine = models.ForeignKey('Machine')
107
  project = models.ForeignKey('Project')
108
  matuse = models.TextField()
109

  
110
# Project Model
111
class Project(models.Model)
112
  name = models.CharField(max_length=30)
113
  primuser = models.Foreignkey('RoboUser')
114
  users = models.ManyToManyField('RoboUser')
115
  charge = models.BooleanField(default=False)
116

  
117
# Roboclub Resources Model
118
class RoboResource
119
  type = models.CharField(max_length=30)
120
  id = models.CharField(max_length=20, unique=True)
121
  checked_out = models.BooleanField(default=False)
122
  user = models.ForeignKey('RoboUser')
123
  time_out = models.DateTimeField()
124
  time_due = models.DateTimeField()
125
  officer = models.ForeignKey('RoboUser')
126

  
127

  

Also available in: Unified diff