add support for additional groups
This commit is contained in:
parent
01b05c5823
commit
9edbe6c898
3 changed files with 114 additions and 1 deletions
|
@ -1,3 +1,24 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
from .models import (
|
||||||
|
AdditionalGroup,
|
||||||
|
Group,
|
||||||
|
Shadow,
|
||||||
|
User,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AdditionalGroupInline(admin.TabularInline):
|
||||||
|
model = AdditionalGroup
|
||||||
|
|
||||||
|
|
||||||
|
class ShadowInline(admin.TabularInline):
|
||||||
|
model = Shadow
|
||||||
|
|
||||||
|
|
||||||
|
class UserAdmin(admin.ModelAdmin):
|
||||||
|
inlines = [AdditionalGroupInline, ShadowInline]
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Group)
|
||||||
|
admin.site.register(User, UserAdmin)
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from south.utils import datetime_utils as datetime
|
||||||
|
from south.db import db
|
||||||
|
from south.v2 import SchemaMigration
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(SchemaMigration):
|
||||||
|
|
||||||
|
def forwards(self, orm):
|
||||||
|
# Adding model 'AdditionalGroup'
|
||||||
|
db.create_table(u'osusers_additionalgroup', (
|
||||||
|
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||||
|
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
|
||||||
|
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
|
||||||
|
('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['osusers.User'])),
|
||||||
|
('group', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['osusers.Group'])),
|
||||||
|
))
|
||||||
|
db.send_create_signal(u'osusers', ['AdditionalGroup'])
|
||||||
|
|
||||||
|
# Adding unique constraint on 'AdditionalGroup', fields ['user', 'group']
|
||||||
|
db.create_unique(u'osusers_additionalgroup', ['user_id', 'group_id'])
|
||||||
|
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
# Removing unique constraint on 'AdditionalGroup', fields ['user', 'group']
|
||||||
|
db.delete_unique(u'osusers_additionalgroup', ['user_id', 'group_id'])
|
||||||
|
|
||||||
|
# Deleting model 'AdditionalGroup'
|
||||||
|
db.delete_table(u'osusers_additionalgroup')
|
||||||
|
|
||||||
|
|
||||||
|
models = {
|
||||||
|
u'osusers.additionalgroup': {
|
||||||
|
'Meta': {'unique_together': "(('user', 'group'),)", 'object_name': 'AdditionalGroup'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.User']"})
|
||||||
|
},
|
||||||
|
u'osusers.group': {
|
||||||
|
'Meta': {'object_name': 'Group'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'descr': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'gid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'groupname': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'passwd': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'})
|
||||||
|
},
|
||||||
|
u'osusers.shadow': {
|
||||||
|
'Meta': {'object_name': 'Shadow'},
|
||||||
|
'changedays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'expiredays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'gracedays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'inactdays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'maxage': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'minage': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'passwd': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||||
|
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['osusers.User']", 'unique': 'True', 'primary_key': 'True'})
|
||||||
|
},
|
||||||
|
u'osusers.user': {
|
||||||
|
'Meta': {'object_name': 'User'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'gecos': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
|
||||||
|
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||||
|
'homedir': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'shell': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
|
||||||
|
'uid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['osusers']
|
|
@ -1,4 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from model_utils.models import TimeStampedModel
|
from model_utils.models import TimeStampedModel
|
||||||
|
|
||||||
|
@ -29,3 +31,16 @@ class Shadow(TimeStampedModel, models.Model):
|
||||||
inactdays = models.PositiveSmallIntegerField(blank=True, null=True)
|
inactdays = models.PositiveSmallIntegerField(blank=True, null=True)
|
||||||
expiredays = models.PositiveSmallIntegerField(blank=True, null=True,
|
expiredays = models.PositiveSmallIntegerField(blank=True, null=True,
|
||||||
default=None)
|
default=None)
|
||||||
|
|
||||||
|
|
||||||
|
class AdditionalGroup(TimeStampedModel, models.Model):
|
||||||
|
user = models.ForeignKey(User)
|
||||||
|
group = models.ForeignKey(Group)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('user', 'group')
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
if self.user.group == self.group:
|
||||||
|
raise ValidationError(_(
|
||||||
|
"You can not use a user's primary group."))
|
||||||
|
|
Loading…
Reference in a new issue