Project

General

Profile

Statistics
| Branch: | Revision:

root / crm / robocrm / models.py @ e680f143

History | View | Annotate | Download (4.32 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
# 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
class Event(models.Model):
102
  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
  project = models.ForeignKey('Project')
110
  matuse = models.TextField()
111
  
112
  def __unicode__(self):
113
    return u'%s %s %s' (self.type, self.user.username, self.succ)
114

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

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