Statistics
| Branch: | Revision:

root / crm / robocrm / models.py @ e0657267

History | View | Annotate | Download (4.33 KB)

1 988e217a Julian Binder
from django.db import models
2 03f9c52d Julian Binder
from django.contrib.auth.models import User
3
from django.db.models.signals import post_save
4
5 b2863bff Julian Binder
# 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 7976b167 Julian Binder
  dstart = models.DateTimeField(blank=True, null=True)
11
  dend = models.DateTimeField(blank=True, null=True)
12 bb0c65c6 Julian Binder
  
13
  def __unicode__(self):
14
    return u'%s %s' % (self.type, self.id)
15 988e217a Julian Binder
16
# User Model
17 03f9c52d Julian Binder
class RoboUser(models.Model):
18
  # Field is required when using profiles 
19
  user = models.OneToOneField(User)
20
21
  # Roboclub RFID Card number
22 75228955 Julian Binder
  rfid = models.CharField(max_length=10, blank=True, default=0)
23 cd771306 Julian Binder
  
24 03f9c52d Julian Binder
  # Roboclub Shop Access Permissions
25 75228955 Julian Binder
  machines = models.ManyToManyField(Machine, blank=True, null=True)
26 03f9c52d Julian Binder
27
  # Cell Phone
28 7976b167 Julian Binder
  cell = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
29 cd771306 Julian Binder
30 03f9c52d Julian Binder
  # Class Level
31 63244bd1 Julian Binder
  UNDERGRAD = 'UG'
32
  GRADUATE = 'GR'
33
  AFFILIATE = 'AF'
34
  OTHER = 'OH'
35 03f9c52d Julian Binder
  CLASS_LEVEL_CHOICES = (
36 63244bd1 Julian Binder
        (UNDERGRAD, 'Undergraduate'),
37
        (GRADUATE, 'Graduate Student'),
38
        (AFFILIATE, 'Non-Student CMU Affiliate'),
39
        (OTHER, 'Other User'),
40 03f9c52d Julian Binder
  )
41
  class_level = models.CharField(max_length=2, 
42
                                 choices=CLASS_LEVEL_CHOICES,
43 63244bd1 Julian Binder
                                 default=UNDERGRAD)
44 cd771306 Julian Binder
45 03f9c52d Julian Binder
  # Graduation Year
46 63244bd1 Julian Binder
  #grad_year = models.DecimalField(max_digits=4, decimal_places=0)
47
  grad_year = models.IntegerField(blank=True, null=True)
48 cd771306 Julian Binder
49 03f9c52d Julian Binder
  # Primary and Secondary Major/Minors
50
  major = models.CharField(max_length=20)
51 7976b167 Julian Binder
  sec_major_one = models.CharField(max_length=20, blank=True, null=True)
52
  sec_major_two = models.CharField(max_length=20, blank=True, null=True)
53 03f9c52d Julian Binder
54
  #Club Rank
55
  JUNIOR_MEM = 'JM'
56
  SENIOR_MEM = 'SM'
57
  OFFICER = 'OM'
58
  CLUB_RANK_CHOICES = (
59
      (JUNIOR_MEM, 'Junior Member'),
60
      (SENIOR_MEM, 'Senior Member'),
61
      (OFFICER, 'Officer'),
62
  )
63
  club_rank = models.CharField(max_length=2, 
64
                               choices=CLUB_RANK_CHOICES,
65
                               default=JUNIOR_MEM)
66
  
67
  # Roboclub Transaction Info
68 63244bd1 Julian Binder
  dues_paid = models.DateField(blank=True, null=True)
69 03f9c52d Julian Binder
  tshirt_rec = models.BooleanField(default=False)
70 988e217a Julian Binder
  
71 03f9c52d Julian Binder
  # Shop and E-Bench Status
72
  GOOD = 'GD'
73
  FIRST_WARN = 'FS'
74
  SECOND_WARN = 'SD'
75
  SEM_BAN = 'SB'
76
  CLUB_BAN = 'CB'
77
  STATUS_CHOICES = (
78
      (GOOD, 'Good Standing'),
79
      (FIRST_WARN, 'First Warning Recieved'),
80
      (SECOND_WARN, 'Second Warning Recieved'),
81
      (SEM_BAN, 'Semester Ban'),
82
      (CLUB_BAN, 'Club Ban')
83
  )
84
  bench_status = models.CharField(max_length=2,
85
                                  choices=STATUS_CHOICES,
86
                                  default=GOOD)
87
  shop_status = models.CharField(max_length=2,
88
                                  choices=STATUS_CHOICES,
89
                                  default=GOOD)
90 bb0c65c6 Julian Binder
  def __unicode__(self):
91 e0657267 Tom Mullins
    return self.user.username
92 bb0c65c6 Julian Binder
93 03f9c52d Julian Binder
# needed for Django Auth model
94
def create_roboclub_user(sender, instance, created, **kwargs):
95
  if created:
96
      RoboUser.objects.create(user=instance)
97
post_save.connect(create_roboclub_user, sender=User)
98
99
100
# Event Model
101 b2863bff Julian Binder
class Event(models.Model):
102 03f9c52d Julian Binder
  type = models.CharField(max_length=30)
103
  tstart = models.DateTimeField()
104
  tend = models.DateTimeField()
105
  user = models.ForeignKey('RoboUser')
106
  succ = models.BooleanField(default=False)
107
  imgurl = models.URLField()
108
  machine = models.ForeignKey('Machine')
109 e0657267 Tom Mullins
  project = models.ForeignKey('Project', null=True)
110 03f9c52d Julian Binder
  matuse = models.TextField()
111 bb0c65c6 Julian Binder
  
112
  def __unicode__(self):
113 e0657267 Tom Mullins
    return u'%s %s %s'%(self.type, self.user.user.username, self.succ)
114 03f9c52d Julian Binder
115
# Project Model
116 b2863bff Julian Binder
class Project(models.Model):
117 03f9c52d Julian Binder
  name = models.CharField(max_length=30)
118 b2863bff Julian Binder
  primuser = models.ForeignKey('RoboUser', related_name='pri+')
119
  users = models.ManyToManyField('RoboUser', related_name='u+')
120 03f9c52d Julian Binder
  charge = models.BooleanField(default=False)
121 bb0c65c6 Julian Binder
  def __unicode__(self):
122
    return self.name
123 03f9c52d Julian Binder
124
# Roboclub Resources Model
125 b2863bff Julian Binder
class RoboResource(models.Model):
126 03f9c52d Julian Binder
  type = models.CharField(max_length=30)
127 b2863bff Julian Binder
  id = models.CharField(max_length=20, primary_key=True)
128 03f9c52d Julian Binder
  checked_out = models.BooleanField(default=False)
129 a048cd77 Julian Binder
  user = models.ForeignKey('RoboUser', related_name='u+', blank=True)
130 7976b167 Julian Binder
  time_out = models.DateTimeField(blank=True,null=True)
131
  time_due = models.DateTimeField(blank=True,null=True)
132 a048cd77 Julian Binder
  officer = models.ForeignKey('RoboUser', related_name='o+', blank=True)
133 bb0c65c6 Julian Binder
  def __unicode__(self):
134
    return u'%s %s %s' (self.type, self.id, self.checked_out)