Statistics
| Branch: | Revision:

root / crm / robocrm / models.py @ bb0c65c6

History | View | Annotate | Download (4.12 KB)

1
from django.db import models
2
from django.contrib.auth.models import User
3
from django.db.models.signals import post_save
4

    
5
# Machine Model
6
class Machine(models.Model):
7
  type = models.CharField(max_length=20)
8
  id = models.CharField(max_length=10, primary_key=True)
9
  maint = models.BooleanField(default=False)
10
  dstart = models.DateTimeField()
11
  dend = models.DateTimeField()
12
  
13
  def __unicode__(self):
14
    return u'%s %s' % (self.type, self.id)
15

    
16
# User Model
17
class RoboUser(models.Model):
18
  # Field is required when using profiles 
19
  user = models.OneToOneField(User)
20

    
21
  # Roboclub RFID Card number
22
  rfid = models.DecimalField(max_digits=10, decimal_places=0)
23
  
24
  # Roboclub Shop Access Permissions
25
  machines = models.ManyToManyField(Machine)
26

    
27
  # Cell Phone
28
  cell = models.DecimalField(max_digits=10, decimal_places=0)
29

    
30
  # Class Level
31
  FRESHMAN = 'FR'
32
  SOPHOMORE = 'SO'
33
  JUNIOR = 'JR'
34
  SENIOR = 'SR'
35
  MASTERS = 'MS'
36
  DOCTORAL = 'DR'
37
  CLASS_LEVEL_CHOICES = (
38
      (FRESHMAN, 'Freshman'),
39
      (SOPHOMORE, 'Sophomore'),
40
      (JUNIOR, 'Junior'),
41
      (SENIOR, 'Senior'),
42
      (MASTERS, 'Masters'),
43
      (DOCTORAL, 'Doctoral'),
44
  )
45
  class_level = models.CharField(max_length=2, 
46
                                 choices=CLASS_LEVEL_CHOICES,
47
                                 default=FRESHMAN)
48

    
49
  # Graduation Year
50
  grad_year = models.DecimalField(max_digits=4, decimal_places=0)
51

    
52
  # Primary and Secondary Major/Minors
53
  major = models.CharField(max_length=20)
54
  sec_major_one = models.CharField(max_length=20)
55
  sec_major_two = models.CharField(max_length=20)
56

    
57
  #Club Rank
58
  JUNIOR_MEM = 'JM'
59
  SENIOR_MEM = 'SM'
60
  OFFICER = 'OM'
61
  CLUB_RANK_CHOICES = (
62
      (JUNIOR_MEM, 'Junior Member'),
63
      (SENIOR_MEM, 'Senior Member'),
64
      (OFFICER, 'Officer'),
65
  )
66
  club_rank = models.CharField(max_length=2, 
67
                               choices=CLUB_RANK_CHOICES,
68
                               default=JUNIOR_MEM)
69
  
70
  # Roboclub Transaction Info
71
  dues_paid = models.DateField()
72
  tshirt_rec = models.BooleanField(default=False)
73
  
74
  # Shop and E-Bench Status
75
  GOOD = 'GD'
76
  FIRST_WARN = 'FS'
77
  SECOND_WARN = 'SD'
78
  SEM_BAN = 'SB'
79
  CLUB_BAN = 'CB'
80
  STATUS_CHOICES = (
81
      (GOOD, 'Good Standing'),
82
      (FIRST_WARN, 'First Warning Recieved'),
83
      (SECOND_WARN, 'Second Warning Recieved'),
84
      (SEM_BAN, 'Semester Ban'),
85
      (CLUB_BAN, 'Club Ban')
86
  )
87
  bench_status = models.CharField(max_length=2,
88
                                  choices=STATUS_CHOICES,
89
                                  default=GOOD)
90
  shop_status = models.CharField(max_length=2,
91
                                  choices=STATUS_CHOICES,
92
                                  default=GOOD)
93
  def __unicode__(self):
94
    return self.user.username;
95

    
96
# needed for Django Auth model
97
def create_roboclub_user(sender, instance, created, **kwargs):
98
  if created:
99
      RoboUser.objects.create(user=instance)
100
post_save.connect(create_roboclub_user, sender=User)
101

    
102

    
103
# Event Model
104
class Event(models.Model):
105
  type = models.CharField(max_length=30)
106
  tstart = models.DateTimeField()
107
  tend = models.DateTimeField()
108
  user = models.ForeignKey('RoboUser')
109
  succ = models.BooleanField(default=False)
110
  imgurl = models.URLField()
111
  machine = models.ForeignKey('Machine')
112
  project = models.ForeignKey('Project')
113
  matuse = models.TextField()
114
  
115
  def __unicode__(self):
116
    return u'%s %s %s' (self.type, self.user.username, self.succ)
117

    
118
# Project Model
119
class Project(models.Model):
120
  name = models.CharField(max_length=30)
121
  primuser = models.ForeignKey('RoboUser', related_name='pri+')
122
  users = models.ManyToManyField('RoboUser', related_name='u+')
123
  charge = models.BooleanField(default=False)
124
  def __unicode__(self):
125
    return self.name
126

    
127
# Roboclub Resources Model
128
class RoboResource(models.Model):
129
  type = models.CharField(max_length=30)
130
  id = models.CharField(max_length=20, primary_key=True)
131
  checked_out = models.BooleanField(default=False)
132
  user = models.ForeignKey('RoboUser', related_name='u+')
133
  time_out = models.DateTimeField()
134
  time_due = models.DateTimeField()
135
  officer = models.ForeignKey('RoboUser', related_name='o+')
136
  def __unicode__(self):
137
    return u'%s %s %s' (self.type, self.id, self.checked_out)
138