2015-09-15 15:38:06 +00:00
|
|
|
|
# coding: utf-8
|
2015-08-20 15:42:27 +00:00
|
|
|
|
|
2015-04-20 02:12:11 +00:00
|
|
|
|
from django.db import models
|
2015-10-07 04:17:20 +00:00
|
|
|
|
from django.contrib.auth.models import AbstractUser
|
2015-11-06 14:26:19 +00:00
|
|
|
|
import time
|
2015-11-16 06:30:10 +00:00
|
|
|
|
# from jasset.models import Asset, AssetGroup
|
2015-10-06 15:47:53 +00:00
|
|
|
|
|
2015-04-20 02:12:11 +00:00
|
|
|
|
|
|
|
|
|
class UserGroup(models.Model):
|
|
|
|
|
name = models.CharField(max_length=80, unique=True)
|
|
|
|
|
comment = models.CharField(max_length=160, blank=True, null=True)
|
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
2015-10-03 16:53:01 +00:00
|
|
|
|
class User(AbstractUser):
|
2015-04-20 02:12:11 +00:00
|
|
|
|
USER_ROLE_CHOICES = (
|
|
|
|
|
('SU', 'SuperUser'),
|
2015-08-26 16:08:20 +00:00
|
|
|
|
('GA', 'GroupAdmin'),
|
2015-04-20 02:12:11 +00:00
|
|
|
|
('CU', 'CommonUser'),
|
|
|
|
|
)
|
|
|
|
|
name = models.CharField(max_length=80)
|
2015-08-31 15:04:53 +00:00
|
|
|
|
uuid = models.CharField(max_length=100)
|
2015-09-15 15:38:06 +00:00
|
|
|
|
role = models.CharField(max_length=2, choices=USER_ROLE_CHOICES, default='CU')
|
2015-04-20 02:12:11 +00:00
|
|
|
|
group = models.ManyToManyField(UserGroup)
|
2015-08-20 15:42:27 +00:00
|
|
|
|
ssh_key_pwd = models.CharField(max_length=200)
|
2015-11-14 15:17:05 +00:00
|
|
|
|
# is_active = models.BooleanField(default=True)
|
|
|
|
|
# last_login = models.DateTimeField(null=True)
|
|
|
|
|
# date_joined = models.DateTimeField(null=True)
|
2015-04-20 02:12:11 +00:00
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return self.username
|
2015-08-20 15:42:27 +00:00
|
|
|
|
|
2015-08-28 16:09:36 +00:00
|
|
|
|
|
|
|
|
|
class AdminGroup(models.Model):
|
|
|
|
|
"""
|
|
|
|
|
under the user control group
|
|
|
|
|
用户可以管理的用户组,或组的管理员是该用户
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
user = models.ForeignKey(User)
|
2015-08-31 15:04:53 +00:00
|
|
|
|
group = models.ForeignKey(UserGroup)
|
|
|
|
|
|
2015-09-02 13:42:31 +00:00
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return '%s: %s' % (self.user.username, self.group.name)
|
2015-11-05 16:56:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Document(models.Model):
|
2015-11-06 14:26:19 +00:00
|
|
|
|
def upload_to(self, filename):
|
|
|
|
|
return 'upload/'+str(self.user.id)+time.strftime('/%Y/%m/%d/', time.localtime())+filename
|
|
|
|
|
|
|
|
|
|
docfile = models.FileField(upload_to=upload_to)
|
2015-11-05 16:56:16 +00:00
|
|
|
|
user = models.ForeignKey(User)
|