From 408788cac1b434f7cf852ec18b3295f4e8d23d5f Mon Sep 17 00:00:00 2001 From: j Date: Sat, 30 May 2020 00:05:50 +0200 Subject: [PATCH] use custom user table --- pandora/settings.py | 3 ++ pandora/system/__init__.py | 0 pandora/system/admin.py | 6 +++ pandora/system/apps.py | 5 +++ pandora/system/migrations/0001_initial.py | 42 +++++++++++++++++++ .../migrations/0002_rename_user_table.py | 21 ++++++++++ pandora/system/migrations/__init__.py | 0 pandora/system/models.py | 6 +++ pandora/system/tests.py | 3 ++ pandora/system/views.py | 3 ++ update.py | 14 +++++++ 11 files changed, 103 insertions(+) create mode 100644 pandora/system/__init__.py create mode 100644 pandora/system/admin.py create mode 100644 pandora/system/apps.py create mode 100644 pandora/system/migrations/0001_initial.py create mode 100644 pandora/system/migrations/0002_rename_user_table.py create mode 100644 pandora/system/migrations/__init__.py create mode 100644 pandora/system/models.py create mode 100644 pandora/system/tests.py create mode 100644 pandora/system/views.py diff --git a/pandora/settings.py b/pandora/settings.py index aea1eb595..6cb4f3476 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -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, diff --git a/pandora/system/__init__.py b/pandora/system/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pandora/system/admin.py b/pandora/system/admin.py new file mode 100644 index 000000000..6d53b53a7 --- /dev/null +++ b/pandora/system/admin.py @@ -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) diff --git a/pandora/system/apps.py b/pandora/system/apps.py new file mode 100644 index 000000000..5dc4d64bc --- /dev/null +++ b/pandora/system/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SystemConfig(AppConfig): + name = 'system' diff --git a/pandora/system/migrations/0001_initial.py b/pandora/system/migrations/0001_initial.py new file mode 100644 index 000000000..5c0a7b32c --- /dev/null +++ b/pandora/system/migrations/0001_initial.py @@ -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()), + ], + ), + ] diff --git a/pandora/system/migrations/0002_rename_user_table.py b/pandora/system/migrations/0002_rename_user_table.py new file mode 100644 index 000000000..098c9b670 --- /dev/null +++ b/pandora/system/migrations/0002_rename_user_table.py @@ -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, + ), + ] diff --git a/pandora/system/migrations/__init__.py b/pandora/system/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pandora/system/models.py b/pandora/system/models.py new file mode 100644 index 000000000..696b770a0 --- /dev/null +++ b/pandora/system/models.py @@ -0,0 +1,6 @@ +from django.db import models +from django.contrib.auth.models import AbstractUser + + +class User(AbstractUser): + pass diff --git a/pandora/system/tests.py b/pandora/system/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/pandora/system/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/pandora/system/views.py b/pandora/system/views.py new file mode 100644 index 000000000..91ea44a21 --- /dev/null +++ b/pandora/system/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/update.py b/update.py index ef802934d..e1639f901 100755 --- a/update.py +++ b/update.py @@ -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()