improve osusers model classes
- add __str__ methods - add verbose names and help texts
This commit is contained in:
parent
9d447cac0b
commit
a85ad4e420
1 changed files with 77 additions and 19 deletions
|
@ -1,46 +1,104 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from model_utils.models import TimeStampedModel
|
from model_utils.models import TimeStampedModel
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class Group(TimeStampedModel, models.Model):
|
class Group(TimeStampedModel, models.Model):
|
||||||
groupname = models.CharField(max_length=16, unique=True)
|
groupname = models.CharField(
|
||||||
gid = models.PositiveSmallIntegerField(unique=True, primary_key=True)
|
_('Group name'), max_length=16, unique=True)
|
||||||
descr = models.TextField(blank=True)
|
gid = models.PositiveSmallIntegerField(
|
||||||
passwd = models.CharField(max_length=128, blank=True)
|
_('Group ID'), unique=True, primary_key=True)
|
||||||
|
descr = models.TextField(_('Description'), blank=True)
|
||||||
|
passwd = models.CharField(
|
||||||
|
_('Group password'), max_length=128, blank=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('Group')
|
||||||
|
verbose_name_plural = _('Groups')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{0} ({1})'.format(self.groupname, self.gid)
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class User(TimeStampedModel, models.Model):
|
class User(TimeStampedModel, models.Model):
|
||||||
username = models.CharField(max_length=64, unique=True)
|
username = models.CharField(
|
||||||
uid = models.PositiveSmallIntegerField(unique=True, primary_key=True)
|
_('User name'), max_length=64, unique=True)
|
||||||
group = models.ForeignKey(Group)
|
uid = models.PositiveSmallIntegerField(
|
||||||
gecos = models.CharField(max_length=128, blank=True)
|
_('User ID'), unique=True, primary_key=True)
|
||||||
homedir = models.CharField(max_length=256)
|
group = models.ForeignKey(Group, verbose_name=_('Group'))
|
||||||
shell = models.CharField(max_length=64)
|
gecos = models.CharField(_('Gecos field'), max_length=128, blank=True)
|
||||||
|
homedir = models.CharField(_('Home directory'), max_length=256)
|
||||||
|
shell = models.CharField(_('Login shell'), max_length=64)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('User')
|
||||||
|
verbose_name_plural = _('Users')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{0} ({1})'.format(self.username, self.uid)
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class Shadow(TimeStampedModel, models.Model):
|
class Shadow(TimeStampedModel, models.Model):
|
||||||
user = models.OneToOneField(User, primary_key=True)
|
user = models.OneToOneField(User, primary_key=True, verbose_name=_('User'))
|
||||||
passwd = models.CharField(max_length=128)
|
passwd = models.CharField(_('Encrypted password'), max_length=128)
|
||||||
changedays = models.PositiveSmallIntegerField(blank=True, null=True)
|
changedays = models.PositiveSmallIntegerField(
|
||||||
minage = models.PositiveSmallIntegerField(blank=True, null=True)
|
_('Date of last change'),
|
||||||
maxage = models.PositiveSmallIntegerField(blank=True, null=True)
|
help_text=_('This is expressed in days since Jan 1, 1970'),
|
||||||
gracedays = models.PositiveSmallIntegerField(blank=True, null=True)
|
blank=True, null=True)
|
||||||
inactdays = models.PositiveSmallIntegerField(blank=True, null=True)
|
minage = models.PositiveSmallIntegerField(
|
||||||
expiredays = models.PositiveSmallIntegerField(blank=True, null=True,
|
_('Minimum age'),
|
||||||
default=None)
|
help_text=_('Minimum number of days before the password can be'
|
||||||
|
' changed'),
|
||||||
|
blank=True, null=True)
|
||||||
|
maxage = models.PositiveSmallIntegerField(
|
||||||
|
_('Maximum age'),
|
||||||
|
help_text=_('Maximum number of days after which the password has to'
|
||||||
|
' be changed'),
|
||||||
|
blank=True, null=True)
|
||||||
|
gracedays = models.PositiveSmallIntegerField(
|
||||||
|
_('Grace period'),
|
||||||
|
help_text=_('The number of days before the password is going to'
|
||||||
|
' expire'),
|
||||||
|
blank=True, null=True)
|
||||||
|
inactdays = models.PositiveSmallIntegerField(
|
||||||
|
_('Inactivity period'),
|
||||||
|
help_text=_('The number of days after the password has expired during'
|
||||||
|
' which the password should still be accepted'),
|
||||||
|
blank=True, null=True)
|
||||||
|
expiredays = models.PositiveSmallIntegerField(
|
||||||
|
_('Account expiration date'),
|
||||||
|
help_text=_('The date of expiration of the account, expressed as'
|
||||||
|
' number of days since Jan 1, 1970'),
|
||||||
|
blank=True, null=True, default=None)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('Shadow password')
|
||||||
|
verbose_name_plural = _('Shadow passwords')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'for user {0}'.format(self.user)
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class AdditionalGroup(TimeStampedModel, models.Model):
|
class AdditionalGroup(TimeStampedModel, models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
group = models.ForeignKey(Group)
|
group = models.ForeignKey(Group)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('user', 'group')
|
unique_together = ('user', 'group')
|
||||||
|
verbose_name = _('Additional group')
|
||||||
|
verbose_name_plural = _('Additional groups')
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.user.group == self.group:
|
if self.user.group == self.group:
|
||||||
raise ValidationError(_(
|
raise ValidationError(_(
|
||||||
"You can not use a user's primary group."))
|
"You can not use a user's primary group."))
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '{0} in {1}'.format(self.user, self.group)
|
||||||
|
|
Loading…
Reference in a new issue