implement classes for tracking task status
This commit is contained in:
parent
865f54ab67
commit
59783e986d
4 changed files with 455 additions and 17 deletions
|
@ -4,9 +4,12 @@ from django.contrib import admin
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
AdditionalGroup,
|
AdditionalGroup,
|
||||||
|
DeleteTaskResult,
|
||||||
Group,
|
Group,
|
||||||
|
GroupTaskResult,
|
||||||
Shadow,
|
Shadow,
|
||||||
User,
|
User,
|
||||||
|
UserTaskResult,
|
||||||
)
|
)
|
||||||
|
|
||||||
PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
|
PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
|
||||||
|
@ -22,6 +25,30 @@ class ShadowInline(admin.TabularInline):
|
||||||
can_delete = False
|
can_delete = False
|
||||||
|
|
||||||
|
|
||||||
|
class TaskResultInline(admin.TabularInline):
|
||||||
|
can_delete = False
|
||||||
|
extra = 0
|
||||||
|
readonly_fields = ['task_uuid', 'task_name', 'is_finished', 'is_success',
|
||||||
|
'state', 'result_body']
|
||||||
|
|
||||||
|
def get_queryset(self, request):
|
||||||
|
qs = super(TaskResultInline, self).get_queryset(request)
|
||||||
|
for entry in qs:
|
||||||
|
entry.update_taskstatus()
|
||||||
|
return qs
|
||||||
|
|
||||||
|
def has_add_permission(self, request, obj=None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class UserTaskResultInline(TaskResultInline):
|
||||||
|
model = UserTaskResult
|
||||||
|
|
||||||
|
|
||||||
|
class GroupTaskResultInline(TaskResultInline):
|
||||||
|
model = GroupTaskResult
|
||||||
|
|
||||||
|
|
||||||
class UserCreationForm(forms.ModelForm):
|
class UserCreationForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
A form for creating system users.
|
A form for creating system users.
|
||||||
|
@ -61,7 +88,7 @@ class UserCreationForm(forms.ModelForm):
|
||||||
|
|
||||||
|
|
||||||
class UserAdmin(admin.ModelAdmin):
|
class UserAdmin(admin.ModelAdmin):
|
||||||
inlines = [AdditionalGroupInline, ShadowInline]
|
inlines = [AdditionalGroupInline, ShadowInline, UserTaskResultInline]
|
||||||
readonly_fields = ['uid']
|
readonly_fields = ['uid']
|
||||||
add_form = UserCreationForm
|
add_form = UserCreationForm
|
||||||
|
|
||||||
|
@ -91,5 +118,31 @@ class UserAdmin(admin.ModelAdmin):
|
||||||
return super(UserAdmin, self).get_inline_instances(request, obj)
|
return super(UserAdmin, self).get_inline_instances(request, obj)
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Group)
|
class GroupAdmin(admin.ModelAdmin):
|
||||||
|
inlines = [GroupTaskResultInline]
|
||||||
|
|
||||||
|
def get_inline_instances(self, request, obj=None):
|
||||||
|
if obj is None:
|
||||||
|
return []
|
||||||
|
return super(GroupAdmin, self).get_inline_instances(request, obj)
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteTaskResultAdmin(admin.ModelAdmin):
|
||||||
|
readonly_fields = ['task_uuid', 'task_name', 'modeltype', 'modelname',
|
||||||
|
'is_finished', 'is_success', 'state', 'result_body']
|
||||||
|
list_display = ('task_uuid', 'task_name', 'modeltype', 'modelname',
|
||||||
|
'is_finished', 'state')
|
||||||
|
|
||||||
|
def has_add_permission(self, request, obj=None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_queryset(self, request):
|
||||||
|
qs = super(DeleteTaskResultAdmin, self).get_queryset(request)
|
||||||
|
for entry in qs:
|
||||||
|
entry.update_taskstatus()
|
||||||
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Group, GroupAdmin)
|
||||||
admin.site.register(User, UserAdmin)
|
admin.site.register(User, UserAdmin)
|
||||||
|
admin.site.register(DeleteTaskResult, DeleteTaskResultAdmin)
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
# -*- 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 'GroupTaskResult'
|
||||||
|
db.create_table(u'osusers_grouptaskresult', (
|
||||||
|
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
|
||||||
|
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
|
||||||
|
('task_uuid', self.gf('django.db.models.fields.CharField')(max_length=64, primary_key=True)),
|
||||||
|
('task_name', self.gf('django.db.models.fields.CharField')(max_length=255)),
|
||||||
|
('is_finished', self.gf('django.db.models.fields.BooleanField')(default=False)),
|
||||||
|
('is_success', self.gf('django.db.models.fields.BooleanField')(default=False)),
|
||||||
|
('state', self.gf('django.db.models.fields.CharField')(max_length=10)),
|
||||||
|
('result_body', self.gf('django.db.models.fields.TextField')(blank=True)),
|
||||||
|
('group', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['osusers.Group'])),
|
||||||
|
))
|
||||||
|
db.send_create_signal(u'osusers', ['GroupTaskResult'])
|
||||||
|
|
||||||
|
# Adding model 'UserTaskResult'
|
||||||
|
db.create_table(u'osusers_usertaskresult', (
|
||||||
|
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
|
||||||
|
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
|
||||||
|
('task_uuid', self.gf('django.db.models.fields.CharField')(max_length=64, primary_key=True)),
|
||||||
|
('task_name', self.gf('django.db.models.fields.CharField')(max_length=255)),
|
||||||
|
('is_finished', self.gf('django.db.models.fields.BooleanField')(default=False)),
|
||||||
|
('is_success', self.gf('django.db.models.fields.BooleanField')(default=False)),
|
||||||
|
('state', self.gf('django.db.models.fields.CharField')(max_length=10)),
|
||||||
|
('result_body', self.gf('django.db.models.fields.TextField')(blank=True)),
|
||||||
|
('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['osusers.User'])),
|
||||||
|
))
|
||||||
|
db.send_create_signal(u'osusers', ['UserTaskResult'])
|
||||||
|
|
||||||
|
# Adding model 'DeleteTaskResult'
|
||||||
|
db.create_table(u'osusers_deletetaskresult', (
|
||||||
|
('created', self.gf('model_utils.fields.AutoCreatedField')(default=datetime.datetime.now)),
|
||||||
|
('modified', self.gf('model_utils.fields.AutoLastModifiedField')(default=datetime.datetime.now)),
|
||||||
|
('task_uuid', self.gf('django.db.models.fields.CharField')(max_length=64, primary_key=True)),
|
||||||
|
('task_name', self.gf('django.db.models.fields.CharField')(max_length=255)),
|
||||||
|
('is_finished', self.gf('django.db.models.fields.BooleanField')(default=False)),
|
||||||
|
('is_success', self.gf('django.db.models.fields.BooleanField')(default=False)),
|
||||||
|
('state', self.gf('django.db.models.fields.CharField')(max_length=10)),
|
||||||
|
('result_body', self.gf('django.db.models.fields.TextField')(blank=True)),
|
||||||
|
('modeltype', self.gf('django.db.models.fields.CharField')(max_length=20, db_index=True)),
|
||||||
|
('modelname', self.gf('django.db.models.fields.CharField')(max_length=255)),
|
||||||
|
))
|
||||||
|
db.send_create_signal(u'osusers', ['DeleteTaskResult'])
|
||||||
|
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
# Deleting model 'GroupTaskResult'
|
||||||
|
db.delete_table(u'osusers_grouptaskresult')
|
||||||
|
|
||||||
|
# Deleting model 'UserTaskResult'
|
||||||
|
db.delete_table(u'osusers_usertaskresult')
|
||||||
|
|
||||||
|
# Deleting model 'DeleteTaskResult'
|
||||||
|
db.delete_table(u'osusers_deletetaskresult')
|
||||||
|
|
||||||
|
|
||||||
|
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.deletetaskresult': {
|
||||||
|
'Meta': {'object_name': 'DeleteTaskResult'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'is_finished': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'is_success': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'modelname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
'modeltype': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_index': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'result_body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'state': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
|
||||||
|
'task_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
'task_uuid': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'})
|
||||||
|
},
|
||||||
|
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.grouptaskresult': {
|
||||||
|
'Meta': {'object_name': 'GroupTaskResult'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||||
|
'is_finished': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'is_success': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'result_body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'state': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
|
||||||
|
'task_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
'task_uuid': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': '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'})
|
||||||
|
},
|
||||||
|
u'osusers.usertaskresult': {
|
||||||
|
'Meta': {'object_name': 'UserTaskResult'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'is_finished': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'is_success': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'result_body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'state': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
|
||||||
|
'task_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
'task_uuid': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'}),
|
||||||
|
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.User']"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['osusers']
|
|
@ -0,0 +1,113 @@
|
||||||
|
# -*- 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 index on 'GroupTaskResult', fields ['task_name']
|
||||||
|
db.create_index(u'osusers_grouptaskresult', ['task_name'])
|
||||||
|
|
||||||
|
# Adding index on 'UserTaskResult', fields ['task_name']
|
||||||
|
db.create_index(u'osusers_usertaskresult', ['task_name'])
|
||||||
|
|
||||||
|
# Adding index on 'DeleteTaskResult', fields ['task_name']
|
||||||
|
db.create_index(u'osusers_deletetaskresult', ['task_name'])
|
||||||
|
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
# Removing index on 'DeleteTaskResult', fields ['task_name']
|
||||||
|
db.delete_index(u'osusers_deletetaskresult', ['task_name'])
|
||||||
|
|
||||||
|
# Removing index on 'UserTaskResult', fields ['task_name']
|
||||||
|
db.delete_index(u'osusers_usertaskresult', ['task_name'])
|
||||||
|
|
||||||
|
# Removing index on 'GroupTaskResult', fields ['task_name']
|
||||||
|
db.delete_index(u'osusers_grouptaskresult', ['task_name'])
|
||||||
|
|
||||||
|
|
||||||
|
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.deletetaskresult': {
|
||||||
|
'Meta': {'object_name': 'DeleteTaskResult'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'is_finished': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'is_success': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'modelname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
'modeltype': ('django.db.models.fields.CharField', [], {'max_length': '20', 'db_index': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'result_body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'state': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
|
||||||
|
'task_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||||
|
'task_uuid': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'})
|
||||||
|
},
|
||||||
|
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.grouptaskresult': {
|
||||||
|
'Meta': {'object_name': 'GroupTaskResult'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||||
|
'is_finished': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'is_success': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'result_body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'state': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
|
||||||
|
'task_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||||
|
'task_uuid': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': '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'})
|
||||||
|
},
|
||||||
|
u'osusers.usertaskresult': {
|
||||||
|
'Meta': {'object_name': 'UserTaskResult'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'is_finished': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'is_success': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'result_body': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'state': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
|
||||||
|
'task_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||||
|
'task_uuid': ('django.db.models.fields.CharField', [], {'max_length': '64', 'primary_key': 'True'}),
|
||||||
|
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.User']"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['osusers']
|
|
@ -10,6 +10,8 @@ from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from model_utils.models import TimeStampedModel
|
from model_utils.models import TimeStampedModel
|
||||||
|
|
||||||
|
from celery.result import AsyncResult
|
||||||
|
|
||||||
from passlib.hash import sha512_crypt
|
from passlib.hash import sha512_crypt
|
||||||
from passlib.utils import generate_password
|
from passlib.utils import generate_password
|
||||||
|
|
||||||
|
@ -23,6 +25,33 @@ from .tasks import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TaskResult(TimeStampedModel, models.Model):
|
||||||
|
|
||||||
|
task_uuid = models.CharField(primary_key=True, max_length=64, blank=False)
|
||||||
|
task_name = models.CharField(max_length=255, blank=False, db_index=True)
|
||||||
|
is_finished = models.BooleanField(default=False)
|
||||||
|
is_success = models.BooleanField(default=False)
|
||||||
|
state = models.CharField(max_length=10)
|
||||||
|
result_body = models.TextField(blank=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
def _set_result_fields(self, asyncresult):
|
||||||
|
if asyncresult.ready():
|
||||||
|
self.is_finished = True
|
||||||
|
self.is_success = asyncresult.state == 'SUCCESS'
|
||||||
|
self.result_body = str(asyncresult.result)
|
||||||
|
self.state = asyncresult.state
|
||||||
|
asyncresult.get(no_ack=False)
|
||||||
|
|
||||||
|
def update_taskstatus(self):
|
||||||
|
if not self.is_finished:
|
||||||
|
asyncresult = AsyncResult(self.task_uuid, task_name=self.task_name)
|
||||||
|
self._set_result_fields(asyncresult)
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
class GroupManager(models.Manager):
|
class GroupManager(models.Manager):
|
||||||
|
|
||||||
def get_next_gid(self):
|
def get_next_gid(self):
|
||||||
|
@ -53,14 +82,65 @@ class Group(TimeStampedModel, models.Model):
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Group, self).save(*args, **kwargs)
|
super(Group, self).save(*args, **kwargs)
|
||||||
create_ldap_group.delay(self.groupname, self.gid, self.descr)
|
GroupTaskResult.objects.create_grouptaskresult(
|
||||||
|
self, create_ldap_group.delay(self.groupname, self.gid, self.descr)
|
||||||
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
|
DeleteTaskResult.objects.create_deletetaskresult(
|
||||||
|
'group', self.groupname,
|
||||||
delete_ldap_group_if_empty.delay(self.groupname)
|
delete_ldap_group_if_empty.delay(self.groupname)
|
||||||
|
)
|
||||||
super(Group, self).delete(*args, **kwargs)
|
super(Group, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class TaskResultManager(models.Manager):
|
||||||
|
|
||||||
|
def create(self, asyncresult):
|
||||||
|
result = self.model(
|
||||||
|
task_uuid=asyncresult.task_id, task_name=asyncresult.task_name
|
||||||
|
)
|
||||||
|
result._set_result_fields(asyncresult)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteTaskResultManager(TaskResultManager):
|
||||||
|
|
||||||
|
def create_deletetaskresult(self, modeltype, modelname, asyncresult):
|
||||||
|
taskresult = super(DeleteTaskResultManager, self).create(
|
||||||
|
asyncresult)
|
||||||
|
taskresult.modeltype = modeltype
|
||||||
|
taskresult.modelname = modelname
|
||||||
|
taskresult.save()
|
||||||
|
return taskresult
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteTaskResult(TaskResult):
|
||||||
|
|
||||||
|
modeltype = models.CharField(max_length=20, db_index=True)
|
||||||
|
modelname = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
objects = DeleteTaskResultManager()
|
||||||
|
|
||||||
|
|
||||||
|
class GroupTaskResultManager(TaskResultManager):
|
||||||
|
|
||||||
|
def create_grouptaskresult(self, group, asyncresult, commit=False):
|
||||||
|
taskresult = super(GroupTaskResultManager, self).create(
|
||||||
|
asyncresult)
|
||||||
|
taskresult.group = group
|
||||||
|
taskresult.save()
|
||||||
|
return taskresult
|
||||||
|
|
||||||
|
|
||||||
|
class GroupTaskResult(TaskResult):
|
||||||
|
|
||||||
|
group = models.ForeignKey(Group)
|
||||||
|
|
||||||
|
objects = GroupTaskResultManager()
|
||||||
|
|
||||||
|
|
||||||
class UserManager(models.Manager):
|
class UserManager(models.Manager):
|
||||||
|
|
||||||
def get_next_uid(self):
|
def get_next_uid(self):
|
||||||
|
@ -94,7 +174,10 @@ class UserManager(models.Manager):
|
||||||
password = generate_password()
|
password = generate_password()
|
||||||
homedir = os.path.join(settings.OSUSER_HOME_BASEPATH, username)
|
homedir = os.path.join(settings.OSUSER_HOME_BASEPATH, username)
|
||||||
group = Group.objects.create(groupname=username, gid=gid)
|
group = Group.objects.create(groupname=username, gid=gid)
|
||||||
|
GroupTaskResult.objects.create(
|
||||||
|
group,
|
||||||
create_ldap_group.delay(group.groupname, group.gid, group.descr)
|
create_ldap_group.delay(group.groupname, group.gid, group.descr)
|
||||||
|
)
|
||||||
user = self.create(username=username, group=group, uid=uid,
|
user = self.create(username=username, group=group, uid=uid,
|
||||||
homedir=homedir,
|
homedir=homedir,
|
||||||
shell=settings.OSUSER_DEFAULT_SHELL)
|
shell=settings.OSUSER_DEFAULT_SHELL)
|
||||||
|
@ -126,15 +209,22 @@ class User(TimeStampedModel, models.Model):
|
||||||
return '{0} ({1})'.format(self.username, self.uid)
|
return '{0} ({1})'.format(self.username, self.uid)
|
||||||
|
|
||||||
def set_password(self, password):
|
def set_password(self, password):
|
||||||
|
UserTaskResult.objects.create_usertaskresult(
|
||||||
|
self,
|
||||||
create_ldap_user.delay(
|
create_ldap_user.delay(
|
||||||
self.username, self.uid, self.group.id, self.gecos, self.homedir,
|
self.username, self.uid, self.group.id, self.gecos,
|
||||||
self.shell, password
|
self.homedir, self.shell, password
|
||||||
|
),
|
||||||
|
commit=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
UserTaskResult.objects.create_usertaskresult(
|
||||||
|
self,
|
||||||
create_ldap_user.delay(
|
create_ldap_user.delay(
|
||||||
self.username, self.uid, self.group.id, self.gecos, self.homedir,
|
self.username, self.uid, self.group.id, self.gecos,
|
||||||
self.shell, password=None
|
self.homedir, self.shell, password=None
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return super(User, self).save(*args, **kwargs)
|
return super(User, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -142,13 +232,40 @@ class User(TimeStampedModel, models.Model):
|
||||||
for group in [
|
for group in [
|
||||||
ag.group for ag in AdditionalGroup.objects.filter(user=self)
|
ag.group for ag in AdditionalGroup.objects.filter(user=self)
|
||||||
]:
|
]:
|
||||||
remove_ldap_user_from_group.delay(self.username, group.groupname)
|
DeleteTaskResult.objects.create_deletetaskresult(
|
||||||
|
'usergroup',
|
||||||
|
'{0} in {1}'.format(self.username, group.groupname),
|
||||||
|
remove_ldap_user_from_group.delay(
|
||||||
|
self.username, group.groupname)
|
||||||
|
)
|
||||||
|
DeleteTaskResult.objects.create_deletetaskresult(
|
||||||
|
'user', self.username,
|
||||||
delete_ldap_user.delay(self.username)
|
delete_ldap_user.delay(self.username)
|
||||||
|
)
|
||||||
|
DeleteTaskResult.objects.create_deletetaskresult(
|
||||||
|
'group', self.group.groupname,
|
||||||
delete_ldap_group_if_empty.delay(self.group.groupname)
|
delete_ldap_group_if_empty.delay(self.group.groupname)
|
||||||
|
)
|
||||||
self.group.delete()
|
self.group.delete()
|
||||||
super(User, self).delete(*args, **kwargs)
|
super(User, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class UserTaskResultManager(TaskResultManager):
|
||||||
|
|
||||||
|
def create_usertaskresult(self, user, asyncresult, commit=False):
|
||||||
|
taskresult = self.create(asyncresult)
|
||||||
|
taskresult.user = user
|
||||||
|
taskresult.save()
|
||||||
|
return taskresult
|
||||||
|
|
||||||
|
|
||||||
|
class UserTaskResult(TaskResult):
|
||||||
|
|
||||||
|
user = models.ForeignKey(User)
|
||||||
|
|
||||||
|
objects = UserTaskResultManager()
|
||||||
|
|
||||||
|
|
||||||
class ShadowManager(models.Manager):
|
class ShadowManager(models.Manager):
|
||||||
|
|
||||||
def create_shadow(self, user, password):
|
def create_shadow(self, user, password):
|
||||||
|
@ -223,13 +340,21 @@ class AdditionalGroup(TimeStampedModel, models.Model):
|
||||||
"You can not use a user's primary group."))
|
"You can not use a user's primary group."))
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
add_ldap_user_to_group.delay(
|
res = add_ldap_user_to_group.delay(
|
||||||
self.user.username, self.group.groupname)
|
self.user.username, self.group.groupname)
|
||||||
|
GroupTaskResult.objects.create(
|
||||||
|
group=self.group, task_uuid=res.id,
|
||||||
|
task_name=res.task_name
|
||||||
|
)
|
||||||
super(AdditionalGroup, self).save(*args, **kwargs)
|
super(AdditionalGroup, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
|
DeleteTaskResult.objects.create_deletetaskresult(
|
||||||
|
'usergroup',
|
||||||
|
str(self),
|
||||||
remove_ldap_user_from_group.delay(
|
remove_ldap_user_from_group.delay(
|
||||||
self.user.username, self.group.groupname)
|
self.user.username, self.group.groupname)
|
||||||
|
)
|
||||||
super(AdditionalGroup, self).delete(*args, **kwargs)
|
super(AdditionalGroup, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
Loading…
Reference in a new issue