Project

General

Profile

Download (2.07 KB) Statistics
| Branch: | Tag: | Revision:

root / uauth / organization / models.py @ 64438aee

1
from django.db import models
2
from django.utils.translation import ugettext as _
3
from django.utils.timezone import make_aware, get_current_timezone
4

    
5
from datetime import datetime
6

    
7

    
8
HOTSPOT_CHOICES = (
9
    ('pfsense', 'pfSense'),
10
    ('meraki', 'Cisco Meraki')
11
)
12

    
13

    
14
class Organization(models.Model):
15
    name = models.CharField(_('Name'), max_length=128)
16
    slug = models.SlugField(max_length=128)
17
    hotspot_url = models.CharField(_('Hotspot url'), max_length=128,
18
                                   null=True, blank=True)
19
    hotspot_type = models.CharField(_('Hotspot type'),
20
                                    choices=HOTSPOT_CHOICES,
21
                                    max_length=32)
22

    
23
    def __unicode__(self):
24
        return self.name
25

    
26

    
27
class OrganizationMember(models.Model):
28
    customer = models.ForeignKey(Organization)
29
    epti = models.CharField(max_length=128)
30
    entity_id = models.CharField(max_length=256)
31

    
32

    
33
class LocalAccount(models.Model):
34
    organization = models.ForeignKey(Organization)
35
    username = models.CharField(_('Username'), max_length=128)
36
    first_name = models.CharField(_('First name'), max_length=64,
37
                        null=True, blank=True)
38
    last_name = models.CharField(_('Last name'), max_length=64,
39
                        null=True, blank=True)
40
    creation_date = models.DateTimeField(auto_now_add=True, blank=True)
41
    expiration_date = models.DateTimeField(null=True, blank=True)
42
    password = models.CharField(_('Password'), max_length=128, blank=True,
43
                                help_text=_('Leave empty to auto-generate'))
44
    description = models.TextField(_('Description'), null=True,
45
                        blank=True)
46
    active = models.BooleanField(_('Active'), default=True)
47

    
48
    class Meta:
49
        unique_together = ('organization', 'username')
50

    
51
    def expired(self):
52
        if self.expiration_date:
53
            return self.expiration_date < make_aware(datetime.now(),
54
                                        get_current_timezone())
55
        return False
56

    
57
    def get_fullname(self):
58
        return '%s %s' % (self.first_name, self.last_name)
(4-4/9)