Statistics
| Branch: | Revision:

root / crm / robocrm / models.py @ 3e2fcd4e

History | View | Annotate | Download (4.18 KB)

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

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

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

    
22
  # Roboclub RFID Card number
23
  rfid = models.CharField(max_length=10, blank=True, null=True)
24
  
25
  # Roboclub Shop Access Permissions
26
  machines = models.ManyToManyField(Machine, blank=True, null=True)
27

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

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

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

    
50
  # Primary and Secondary Major/Minors
51
  major = models.CharField(max_length=20)
52
  sec_major_one = models.CharField(max_length=20, blank=True, null=True)
53
  sec_major_two = models.CharField(max_length=20, blank=True, null=True)
54

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

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

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

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