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 9019fc8..0000000 Binary files a/back/db.sqlite3 and /dev/null differ 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.