add customer field to osusers.models.User
- allow association of os users to Django users (customers) - adapt admin forms - add migration
This commit is contained in:
parent
39fd326ac2
commit
18e47d73b4
4 changed files with 31 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
* :feature:`-` add a `customer` field to :py:class:`osusers.models.User`
|
||||||
* :feature:`-` allow empty password input in
|
* :feature:`-` allow empty password input in
|
||||||
:py:class:`osusers.admin.UserCreationForm` to allow generated passwords for
|
:py:class:`osusers.admin.UserCreationForm` to allow generated passwords for
|
||||||
new users
|
new users
|
||||||
|
|
|
@ -38,7 +38,7 @@ class UserCreationForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = []
|
fields = ['customer']
|
||||||
|
|
||||||
def clean_password2(self):
|
def clean_password2(self):
|
||||||
"""
|
"""
|
||||||
|
@ -57,6 +57,7 @@ class UserCreationForm(forms.ModelForm):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
user = User.objects.create_user(
|
user = User.objects.create_user(
|
||||||
|
customer=self.cleaned_data['customer'],
|
||||||
password=self.cleaned_data['password1'], commit=commit)
|
password=self.cleaned_data['password1'], commit=commit)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ class UserAdmin(admin.ModelAdmin):
|
||||||
add_fieldsets = (
|
add_fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
'classes': ('wide',),
|
'classes': ('wide',),
|
||||||
'fields': ('password1', 'password2')}),
|
'fields': ('customer', 'password1', 'password2')}),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_form(self, request, obj=None, **kwargs):
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
|
|
22
gnuviechadmin/osusers/migrations/0003_user_customer.py
Normal file
22
gnuviechadmin/osusers/migrations/0003_user_customer.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('osusers', '0002_auto_20141226_1456'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='customer',
|
||||||
|
field=models.ForeignKey(default=1, to=settings.AUTH_USER_MODEL),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -104,7 +104,9 @@ class UserManager(models.Manager):
|
||||||
return nextuser
|
return nextuser
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def create_user(self, username=None, password=None, commit=False):
|
def create_user(
|
||||||
|
self, customer, username=None, password=None, commit=False
|
||||||
|
):
|
||||||
uid = self.get_next_uid()
|
uid = self.get_next_uid()
|
||||||
gid = Group.objects.get_next_gid()
|
gid = Group.objects.get_next_gid()
|
||||||
if username is None:
|
if username is None:
|
||||||
|
@ -114,7 +116,7 @@ class UserManager(models.Manager):
|
||||||
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)
|
||||||
user = self.create(username=username, group=group, uid=uid,
|
user = self.create(username=username, group=group, uid=uid,
|
||||||
homedir=homedir,
|
homedir=homedir, customer=customer,
|
||||||
shell=settings.OSUSER_DEFAULT_SHELL)
|
shell=settings.OSUSER_DEFAULT_SHELL)
|
||||||
user.set_password(password)
|
user.set_password(password)
|
||||||
if commit:
|
if commit:
|
||||||
|
@ -132,6 +134,7 @@ class User(TimeStampedModel, models.Model):
|
||||||
gecos = models.CharField(_('Gecos field'), max_length=128, blank=True)
|
gecos = models.CharField(_('Gecos field'), max_length=128, blank=True)
|
||||||
homedir = models.CharField(_('Home directory'), max_length=256)
|
homedir = models.CharField(_('Home directory'), max_length=256)
|
||||||
shell = models.CharField(_('Login shell'), max_length=64)
|
shell = models.CharField(_('Login shell'), max_length=64)
|
||||||
|
customer = models.ForeignKey(settings.AUTH_USER_MODEL)
|
||||||
|
|
||||||
objects = UserManager()
|
objects = UserManager()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue