# CCS CS Lab Main Models # # Douglas Thrift # # $Id$ from ccscslab.main import utils from datetime import datetime from django.conf import settings from django.contrib.auth.models import User from django.contrib.localflavor.us.models import PhoneNumberField from django.db import models import os.path class Person(models.Model): GENDER_CHOICES = (('m', 'male'), ('f', 'female')) name = models.CharField(max_length = 16, unique = True) uid = models.PositiveSmallIntegerField(unique = True) full_name = models.CharField(max_length = 50) shell = models.CharField(max_length = 8) plan = models.TextField(blank = True) project = models.TextField(blank = True) gender = models.CharField(choices = GENDER_CHOICES, default = 'm', max_length = 1) user = models.ForeignKey(User, blank = True, null = True, unique = True) class Meta: ordering = ('name',) verbose_name_plural = 'people' def __unicode__(self): return self.name def first_name(self): return self.full_name.split(' ', 1)[0] @models.permalink def get_absolute_url(self): return ('person_view', [self.name]) def get_facebook_url(self): from ccscslab.facebook.utils import root return root + self.get_absolute_url() def get_shell_url(self): while True: try: if self.shell in self.__shells: return 'http://en.wikipedia.org/wiki/' + self.__shells[self.shell] elif self.shell == '3sh': return 'http://svn.saurik.com/repos/menes/trunk/3sh' else: return except AttributeError: self.__shells = {'sh': 'Bourne_shell', 'csh': 'C_shell', 'tcsh': 'Tcsh', 'bash': 'Bash', 'ksh': 'Korn_shell', 'zsh': 'Zsh'} def is_default(self): return self.name == settings.CCSCSLAB_DEFAULT_PERSON def last_login(self): if self.user: return self.user.last_login def pronoun(self): return 'he' if self.gender == 'm' else 'she' def pronoun_possessive(self): return 'his' if self.gender == 'm' else 'her' def pronoun_reflexive(self): return self.pronoun_objective() + 'self' def pronoun_objective(self): return 'him' if self.gender == 'm' else 'her' class OperatingSystem(models.Model): name = models.CharField(max_length = 50, unique = True) image = models.FilePathField(blank = True, match = '^.*\.png$', path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'data', 'images', 'os'))) url = models.URLField(blank = True) class Meta: ordering = ('name',) def __unicode__(self): return self.name class Role(models.Model): name = models.CharField(max_length = 50, unique = True) full_name = models.CharField(max_length = 50, unique = True) class Meta: ordering = ('name',) def __unicode__(self): return self.name @models.permalink def get_absolute_url(self): return ('role_view', [self.name]) class Computer(models.Model): name = models.CharField(max_length = 16, unique = True) ip_address = models.IPAddressField(unique = True) online = models.BooleanField(default = False) sword = models.CharField(max_length = 16, unique = True) article = models.URLField() operating_system = models.ForeignKey(OperatingSystem) processor = models.CharField(max_length = 50) roles = models.ManyToManyField(Role) motd = models.TextField(blank = True) class Meta: ordering = ('-online', 'ip_address') def __unicode__(self): return self.name def full_name(self): return utils.full_name(self.name) @models.permalink def get_absolute_url(self): return ('computer_view', [self.name]) def get_facebook_url(self): from ccscslab.facebook.utils import root return root + self.get_absolute_url() def local(self): return self.login_set.filter(local = True) class Login(models.Model): person = models.ForeignKey(Person) computer = models.ForeignKey(Computer) local = models.BooleanField(default = False) class Meta: ordering = ('person', 'computer__name') unique_together = ('person', 'computer') def __unicode__(self): return self.person.name + '@' + self.computer.name class Request(models.Model): name = models.CharField(max_length = 16, unique = True) full_name = models.CharField(max_length = 50) temporary_password = models.CharField(max_length = 128) requested = models.DateTimeField(default = datetime.now) ip_address = models.IPAddressField() dns_name = models.CharField(blank = True, max_length = 255) email = models.EmailField(blank = True) facebook_user = models.BigIntegerField(blank = True, null = True) fullfilled = models.BooleanField(default = False) class Meta: ordering = ('-requested', 'name') def __unicode__(self): return self.name class UserProfile(models.Model): user = models.ForeignKey(User, unique = True) person = models.ForeignKey(Person, unique = True) phone = PhoneNumberField(blank = True) website = models.URLField(blank = True) class Meta: ordering = ('person',) def __unicode__(self): return self.person.name class ScreenName(models.Model): SERVICE_CHOICES = (('aim', 'AIM'), ('google', 'Google Talk'), ('irc', 'IRC'), ('msn', 'Windows Live (MSN)'), ('skype', 'Skype'), ('yahoo', 'Yahoo!')) user_profile = models.ForeignKey(UserProfile) name = models.CharField(max_length = 75) service = models.CharField(choices = SERVICE_CHOICES, max_length = 6) class Meta: ordering = ('user_profile', 'name', 'service') unique_together = ('user_profile', 'name', 'service') def __unicode__(self): return self.name def get_absolute_url(self): if self.service == 'aim': return 'aim:goim?screenname=' + self.name elif self.service == 'google': return 'gtalk:chat?jid=' + self.name elif self.service == 'msn': return 'msnim:chat?contact=' + self.name elif self.service == 'skype': return 'skype:' + self.name + '?chat' elif self.service == 'yahoo': return 'ymsgr:sendIM?' + self.name