use custom user table

This commit is contained in:
j 2020-05-30 00:05:50 +02:00
parent 548a73f121
commit 408788cac1
11 changed files with 103 additions and 0 deletions

View File

@ -120,6 +120,7 @@ INSTALLED_APPS = (
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'django.contrib.humanize',
'system',
'django_extensions',
'django_celery_results',
@ -151,6 +152,8 @@ INSTALLED_APPS = (
'home',
)
AUTH_USER_MODEL = 'system.User'
# Log errors into db
LOGGING = {
'version': 1,

View File

6
pandora/system/admin.py Normal file
View File

@ -0,0 +1,6 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
admin.site.register(User, UserAdmin)

5
pandora/system/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class SystemConfig(AppConfig):
name = 'system'

View File

@ -0,0 +1,42 @@
# Generated by Django 3.0.6 on 2020-05-29 21:41
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0008_alter_user_username_max_length'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=255, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=255, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=255, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'db_table': 'auth_user',
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]

View File

@ -0,0 +1,21 @@
# Generated by Django 3.0.6 on 2020-05-29 21:54
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('system', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='user',
options={'verbose_name': 'user', 'verbose_name_plural': 'users'},
),
migrations.AlterModelTable(
name='user',
table=None,
),
]

View File

6
pandora/system/models.py Normal file
View File

@ -0,0 +1,6 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass

3
pandora/system/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
pandora/system/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -117,6 +117,12 @@ def run_git(path, *args):
return subprocess.check_output(cmd, env=env).decode().strip()
def run_sql(sql):
cmd = [join(base, 'pandora/manage.py'), 'dbshell']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, error = p.communicate(input=sql.encode())
return stdout.decode()
def get_version(path):
return run_git(path, 'rev-list', 'HEAD', '--count')
@ -278,6 +284,14 @@ if __name__ == "__main__":
if old <= 6313:
run('./bin/pip', 'uninstall', 'django-celery', '-y')
run('./bin/pip', 'install', '-r', 'requirements.txt')
if old <= 6315:
for sql in [
"INSERT INTO django_migrations (app, name, applied) VALUES ('system', '0001_initial', CURRENT_TIMESTAMP)",
"UPDATE django_content_type SET app_label = 'system' WHERE app_label = 'auth' and model = 'user'",
]:
run_sql(sql)
run(join(base, 'pandora/manage.py'), 'migrate', 'system')
else:
if len(sys.argv) == 1:
branch = get_branch()