From bd1bf440596c4035fda1bcf3b01d1860b6d71132 Mon Sep 17 00:00:00 2001 From: Daniel Dupriest Date: Tue, 22 Jan 2019 16:38:09 -0800 Subject: [PATCH] Created CustomUser and tweaked backend models. --- back/backend/migrations/0001_initial.py | 126 ------------------------ back/backend/models.py | 24 ++--- back/db.sqlite3 | Bin 208896 -> 0 bytes back/reimbursinator/settings.py | 4 + back/users/__init__.py | 0 back/users/admin.py | 12 +++ back/users/apps.py | 5 + back/users/forms.py | 15 +++ back/users/migrations/__init__.py | 0 back/users/models.py | 5 + back/users/tests.py | 3 + back/users/views.py | 3 + 12 files changed, 59 insertions(+), 138 deletions(-) delete mode 100644 back/backend/migrations/0001_initial.py delete mode 100644 back/db.sqlite3 create mode 100644 back/users/__init__.py create mode 100644 back/users/admin.py create mode 100644 back/users/apps.py create mode 100644 back/users/forms.py create mode 100644 back/users/migrations/__init__.py create mode 100644 back/users/models.py create mode 100644 back/users/tests.py create mode 100644 back/users/views.py diff --git a/back/backend/migrations/0001_initial.py b/back/backend/migrations/0001_initial.py deleted file mode 100644 index 69073ec..0000000 --- a/back/backend/migrations/0001_initial.py +++ /dev/null @@ -1,126 +0,0 @@ -# Generated by Django 2.1.4 on 2019-01-20 22:35 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ] - - operations = [ - migrations.CreateModel( - name='DataBool', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('data', models.BooleanField()), - ], - ), - migrations.CreateModel( - name='DataDate', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('data', models.DateField()), - ], - ), - migrations.CreateModel( - name='DataDecimal', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('data', models.DecimalField(decimal_places=2, max_digits=9)), - ], - ), - migrations.CreateModel( - name='DataFile', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('data', models.FileField(upload_to='')), - ], - ), - migrations.CreateModel( - name='DataInteger', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('data', models.IntegerField()), - ], - ), - migrations.CreateModel( - name='DataString', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('data', models.TextField()), - ], - ), - migrations.CreateModel( - name='Field', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('label', models.CharField(max_length=256)), - ('number', models.IntegerField()), - ('type', models.CharField(max_length=128)), - ('completed', models.BooleanField()), - ], - ), - migrations.CreateModel( - name='Report', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=128)), - ('date_created', models.DateTimeField(verbose_name='date created')), - ('date_submitted', models.DateTimeField(verbose_name='date submitted')), - ('submitted', models.BooleanField()), - ('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), - ], - ), - migrations.CreateModel( - name='Section', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('completed', models.BooleanField()), - ('title', models.CharField(max_length=256)), - ('html_description', models.TextField()), - ('number', models.IntegerField()), - ('report_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Report')), - ], - ), - migrations.AddField( - model_name='field', - name='section_id', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Section'), - ), - migrations.AddField( - model_name='datastring', - name='field_id', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'), - ), - migrations.AddField( - model_name='datainteger', - name='field_id', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'), - ), - migrations.AddField( - model_name='datafile', - name='field_id', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'), - ), - migrations.AddField( - model_name='datadecimal', - name='field_id', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'), - ), - migrations.AddField( - model_name='datadate', - name='field_id', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'), - ), - migrations.AddField( - model_name='databool', - name='field_id', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'), - ), - ] diff --git a/back/backend/models.py b/back/backend/models.py index d44a8eb..afff981 100644 --- a/back/backend/models.py +++ b/back/backend/models.py @@ -1,12 +1,12 @@ from django.db import models -from django.contrib.auth.models import User +from django.conf import settings class Report(models.Model): - user_id = models.ForeignKey(User, on_delete=models.CASCADE) + user_id = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) title = models.CharField(max_length=128) date_created = models.DateTimeField('date created') - date_submitted = models.DateTimeField('date submitted') - submitted = models.BooleanField() + date_submitted = models.DateTimeField('date submitted', null=True, blank=True) + submitted = models.BooleanField(default=False) class Section(models.Model): report_id = models.ForeignKey(Report, on_delete=models.CASCADE) @@ -20,28 +20,28 @@ class Field(models.Model): label = models.CharField(max_length=256) number = models.IntegerField() type = models.CharField(max_length=128) - completed = models.BooleanField() + completed = models.BooleanField(default=False) class DataBool(models.Model): field_id = models.ForeignKey(Field, on_delete=models.CASCADE) - data = models.BooleanField() + data = models.BooleanField(default=False) class DataDecimal(models.Model): field_id = models.ForeignKey(Field, on_delete=models.CASCADE) - data = models.DecimalField(max_digits=9,decimal_places=2) + data = models.DecimalField(max_digits=9,decimal_places=2, null=True, blank=True) class DataDate(models.Model): field_id = models.ForeignKey(Field, on_delete=models.CASCADE) - data = models.DateField() + data = models.DateField(null=True, blank=True) class DataFile(models.Model): field_id = models.ForeignKey(Field, on_delete=models.CASCADE) - data = models.FileField() - + data = models.FileField(null=True, blank=True) + class DataString(models.Model): field_id = models.ForeignKey(Field, on_delete=models.CASCADE) - data = models.TextField() + data = models.TextField(default='') class DataInteger(models.Model): field_id = models.ForeignKey(Field, on_delete=models.CASCADE) - data = models.IntegerField() + data = models.IntegerField(null=True, blank=True) diff --git a/back/db.sqlite3 b/back/db.sqlite3 deleted file mode 100644 index 9019fc8c8751942ce6b2d7a4dcd86cf1ad87c61d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 208896 zcmeI54{Tew@sma>oJlgyYR z6_T>!wirssNr!aw6Xzjyleh~-fCiEetfi+rDHg5-zVFP$nN4gw$m0w4ea zAOHd&00JNY0w4eaAaENAc#|~Qkk?I1kMlJP`7HSW$&pd{Z{?qpPq^Q7f6{%$9dmu# z^{VS9T%%Ng9}oZm5C8!X009sH0T2Lzdy7D%zuPiAKATapm(*e|6bgmY`C`7BR|=6( zI5iatPenq$NaS!demI;wl!~WPGodKyw(K3Bt*DhszErFZY8i?sEYM4?nD z6pKCTrisq!iDt}+ShlU?iG*fCvC}S^=NUauQslX;6!JNxS}Ir4N-mdH%jHrzy+(Vg ztg4k(Q!^AvEE0~)I%%?bJy{}MR-fC*m(_H(RIIASYW3>6T1nG>N7|*BnTf_@;S+r{ z#c4f7+}tk?s8CwX7t_U!0vnkoHZzB2;_+}eaoj<3oYHf|%sJ|8O6%3O9Z4qRv1H_A zFU@d9&k!|dP}h`vVbdX+Ig|`VW+I8l>@>+!dXk7pvaXib@_fqNc(7*xk*0{IDNi~w<*R(0m28zx z<@8EHSxsjzmh##5gB^<|!?EzJji#cMMXHFAO4y>4yu{MBa}$k*5}|m=N>hy2QDs#iP>OVbBI zN~TmQ3=T8}=?Qgrzct#R%&FP@no=0_G>KR81$8%R66fi2p;fi)?Y2gx+_Oq?wWL2Q z;tw-CE|+!0!4~`c5t+wrov639l2;44!5(W+;^&RWD#r({v}uuzKb>GtCTJ&zWNWxy zopq{GE$54?Ly~n`Z+tDkT2|OIkV=0at>KYBVIkioe?|VDe2QEl0r^LyU;eiI3HeLp zVfvYXC&&lM``XY$2n0X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zTV84L@BiJxLk&~~0T2KI5C8!X009sH0T2KI5CDODgaFq6_sBrOCJ2B42!H?xfB*=9 z00@8p2!H?x+yVjo{r_8lhpHd|0w4eaAOHd&00JNY0w4eaAaIWm!216l87SBU0T2KI z5C8!X009sH0T2KI5CDN&Ab|D%ExQYC1`0Mo00ck)1V8`;KmY_l00ck)1VG>x2>c&Z*#yi0 diff --git a/back/reimbursinator/settings.py b/back/reimbursinator/settings.py index f17a05c..fbb8d16 100644 --- a/back/reimbursinator/settings.py +++ b/back/reimbursinator/settings.py @@ -39,6 +39,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'backend', + 'users', ] MIDDLEWARE = [ @@ -82,6 +83,9 @@ DATABASES = { } } +# Authentication + +AUTH_USER_MODEL = 'users.CustomUser' # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators diff --git a/back/users/__init__.py b/back/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/back/users/admin.py b/back/users/admin.py new file mode 100644 index 0000000..2787176 --- /dev/null +++ b/back/users/admin.py @@ -0,0 +1,12 @@ +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin + +from .forms import CustomUserCreationForm, CustomUserChangeForm +from .models import CustomUser + +class CustomUserAdmin(UserAdmin): + add_form = CustomUserCreationForm + form = CustomUserChangeForm + model = CustomUser + +admin.site.register(CustomUser, CustomUserAdmin) diff --git a/back/users/apps.py b/back/users/apps.py new file mode 100644 index 0000000..4ce1fab --- /dev/null +++ b/back/users/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + name = 'users' diff --git a/back/users/forms.py b/back/users/forms.py new file mode 100644 index 0000000..ad18d01 --- /dev/null +++ b/back/users/forms.py @@ -0,0 +1,15 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm, UserChangeForm + +from .models import CustomUser + +class CustomUserCreationForm(UserCreationForm): + class Meta(UserCreationForm): + model = CustomUser + fields = UserCreationForm.Meta.fields + ('age',) + +class CustomUserChangeForm(UserChangeForm): + + class Meta: + model = CustomUser + fields = UserChangeForm.Meta.fields diff --git a/back/users/migrations/__init__.py b/back/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/back/users/models.py b/back/users/models.py new file mode 100644 index 0000000..e51d043 --- /dev/null +++ b/back/users/models.py @@ -0,0 +1,5 @@ +from django.contrib.auth.models import AbstractUser +from django.db import models + +class CustomUser(AbstractUser): + age = models.PositiveIntegerField(null=True, blank=True) diff --git a/back/users/tests.py b/back/users/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/back/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/back/users/views.py b/back/users/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/back/users/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.