Statistics
| Branch: | Revision:

root / crm / robocrm / models.py @ 049ebb6e

History | View | Annotate | Download (4.15 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(blank=True, null=True)
11
  dend = models.DateTimeField(blank=True, null=True)
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.CharField(max_length=10, blank=True, default=0)
23
  
24
  # Roboclub Shop Access Permissions
25
  machines = models.ManyToManyField(Machine, blank=True, null=True)
26

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

    
30
  # Class Level
31
  UNDERGRAD = 'UG'
32
  GRADUATE = 'GR'
33
  AFFILIATE = 'AF'
34
  OTHER = 'OH'
35
  CLASS_LEVEL_CHOICES = (
36
      (UNDERGRAD, 'Undergraduate'),
37
      (GRADUATE, 'Graduate Student'),
38
      (AFFILIATE, 'Non-Student CMU Affiliate'),
39
      (OTHER, 'Other User'),
40
  )
41
  class_level = models.CharField(max_length=2, 
42
                                 choices=CLASS_LEVEL_CHOICES,
43
                                 default=UNDERGRAD)
44

    
45
  # Graduation Year
46
  #grad_year = models.DecimalField(max_digits=4, decimal_places=0)
47
  grad_year = models.IntegerField(blank=True, null=True)
48

    
49
  # Primary and Secondary Major/Minors
50
  major = models.CharField(max_length=20)
51
  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

    
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
  dues_paid = models.DateField(blank=True, null=True)
69
  tshirt_rec = models.BooleanField(default=False)
70
  
71
  # 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
  def __unicode__(self):
91
    return self.user.username
92

    
93
# Event Model
94
class Event(models.Model):
95
  type = models.CharField(max_length=30)
96
  tstart = models.DateTimeField()
97
  tend = models.DateTimeField()
98
  user = models.ForeignKey('RoboUser')
99
  succ = models.BooleanField(default=False)
100
  imgurl = models.URLField()
101
  machine = models.ForeignKey('Machine')
102
  project = models.ForeignKey('Project', null=True)
103
  matuse = models.TextField()
104
  
105
  def __unicode__(self):
106
    return u'%s %s %s'%(self.type, self.user.user.username, self.succ)
107

    
108
# Project Model
109
class Project(models.Model):
110
  name = models.CharField(max_length=30)
111
  primuser = models.ForeignKey('RoboUser', related_name='pri+')
112
  users = models.ManyToManyField('RoboUser', related_name='u+')
113
  charge = models.BooleanField(default=False)
114
  def __unicode__(self):
115
    return self.name
116

    
117
# Roboclub Resources Model
118
class RoboResource(models.Model):
119
  type = models.CharField(max_length=30)
120
  id = models.CharField(max_length=20, primary_key=True)
121
  checked_out = models.BooleanField(default=False)
122
  user = models.ForeignKey('RoboUser', related_name='u+', blank=True)
123
  time_out = models.DateTimeField(blank=True,null=True)
124
  time_due = models.DateTimeField(blank=True,null=True)
125
  officer = models.ForeignKey('RoboUser', related_name='o+', blank=True)
126
  def __unicode__(self):
127
    return u'%s %s %s' (self.type, self.id, self.checked_out)
128