use primitive fields instead of models for tasks

- modify osusers.tasks and osusers.models to avoid serialization of full
  models for celery tasks and use the required fields only
This commit is contained in:
Jan Dittberner 2014-05-30 18:39:51 +02:00
parent 0c5706d886
commit 865f54ab67
2 changed files with 16 additions and 10 deletions

View file

@ -53,7 +53,7 @@ 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) create_ldap_group.delay(self.groupname, self.gid, self.descr)
return self return self
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
@ -94,7 +94,7 @@ 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)
create_ldap_group.delay(group) 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,10 +126,16 @@ 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):
create_ldap_user.delay(self, password) create_ldap_user.delay(
self.username, self.uid, self.group.id, self.gecos, self.homedir,
self.shell, password
)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
create_ldap_user.delay(self, password=None) create_ldap_user.delay(
self.username, self.uid, self.group.id, self.gecos, self.homedir,
self.shell, password=None
)
return super(User, self).save(*args, **kwargs) return super(User, self).save(*args, **kwargs)
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
@ -137,7 +143,7 @@ class User(TimeStampedModel, models.Model):
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) remove_ldap_user_from_group.delay(self.username, group.groupname)
delete_ldap_user.delay(self) delete_ldap_user.delay(self.username)
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)

View file

@ -14,13 +14,13 @@ class LdapRouter(object):
@shared_task @shared_task
def create_ldap_group(group): def create_ldap_group(groupname, gid, descr):
return group.groupname pass
@shared_task @shared_task
def create_ldap_user(user, password): def create_ldap_user(username, uid, gid, gecos, homedir, shell, password):
return user.username pass
@shared_task @shared_task
@ -34,7 +34,7 @@ def remove_ldap_user_from_group(username, groupname):
@shared_task @shared_task
def delete_ldap_user(user): def delete_ldap_user(username):
pass pass