From e3176bc05b4657640304307c7968dc285f3bb69a Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Mon, 4 Jul 2016 18:57:28 -0600 Subject: [PATCH 1/7] Factor out User functions to a new model. --- bikeshop_project/bikeshop/settings/base.py | 2 +- .../bikeshop/utils/member_import.py | 2 +- .../core/migrations/0001_initial.py | 37 +++++++--- .../core/migrations/0002_payment.py | 25 ------- .../core/migrations/0003_visit.py | 27 -------- .../migrations/0004_auto_20160405_0354.py | 31 --------- .../migrations/0004_auto_20160410_1816.py | 30 -------- .../core/migrations/0005_merge.py | 16 ----- .../migrations/0006_auto_20160410_1833.py | 35 ---------- .../migrations/0007_auto_20160501_2253.py | 31 --------- .../migrations/0008_auto_20160526_0059.py | 25 ------- .../0009_remove_membership_member.py | 19 ------ .../core/migrations/0010_membership_member.py | 23 ------- .../migrations/0011_auto_20160531_0233.py | 22 ------ .../migrations/0012_auto_20160531_0234.py | 25 ------- .../migrations/0013_auto_20160531_0236.py | 25 ------- .../core/migrations/0014_payment_paid.py | 20 ------ .../migrations/0015_auto_20160531_0413.py | 20 ------ .../migrations/0016_auto_20160531_0416.py | 24 ------- .../migrations/0017_auto_20160626_1842.py | 20 ------ .../migrations/0018_auto_20160626_1844.py | 20 ------ bikeshop_project/registration/admin.py | 68 +++++++++---------- .../registration/migrations/0001_initial.py | 33 +++++---- .../migrations/0002_member_email_consent.py | 20 ------ .../migrations/0003_auto_20160327_0620.py | 25 ------- .../migrations/0004_auto_20160410_1816.py | 32 --------- .../migrations/0005_member_membership.py | 22 ------ .../0006_remove_member_membership.py | 19 ------ bikeshop_project/registration/models.py | 54 ++++++++++----- 29 files changed, 121 insertions(+), 631 deletions(-) delete mode 100644 bikeshop_project/core/migrations/0002_payment.py delete mode 100644 bikeshop_project/core/migrations/0003_visit.py delete mode 100644 bikeshop_project/core/migrations/0004_auto_20160405_0354.py delete mode 100644 bikeshop_project/core/migrations/0004_auto_20160410_1816.py delete mode 100644 bikeshop_project/core/migrations/0005_merge.py delete mode 100644 bikeshop_project/core/migrations/0006_auto_20160410_1833.py delete mode 100644 bikeshop_project/core/migrations/0007_auto_20160501_2253.py delete mode 100644 bikeshop_project/core/migrations/0008_auto_20160526_0059.py delete mode 100644 bikeshop_project/core/migrations/0009_remove_membership_member.py delete mode 100644 bikeshop_project/core/migrations/0010_membership_member.py delete mode 100644 bikeshop_project/core/migrations/0011_auto_20160531_0233.py delete mode 100644 bikeshop_project/core/migrations/0012_auto_20160531_0234.py delete mode 100644 bikeshop_project/core/migrations/0013_auto_20160531_0236.py delete mode 100644 bikeshop_project/core/migrations/0014_payment_paid.py delete mode 100644 bikeshop_project/core/migrations/0015_auto_20160531_0413.py delete mode 100644 bikeshop_project/core/migrations/0016_auto_20160531_0416.py delete mode 100644 bikeshop_project/core/migrations/0017_auto_20160626_1842.py delete mode 100644 bikeshop_project/core/migrations/0018_auto_20160626_1844.py delete mode 100644 bikeshop_project/registration/migrations/0002_member_email_consent.py delete mode 100644 bikeshop_project/registration/migrations/0003_auto_20160327_0620.py delete mode 100644 bikeshop_project/registration/migrations/0004_auto_20160410_1816.py delete mode 100644 bikeshop_project/registration/migrations/0005_member_membership.py delete mode 100644 bikeshop_project/registration/migrations/0006_remove_member_membership.py diff --git a/bikeshop_project/bikeshop/settings/base.py b/bikeshop_project/bikeshop/settings/base.py index cf9818b..f765bec 100644 --- a/bikeshop_project/bikeshop/settings/base.py +++ b/bikeshop_project/bikeshop/settings/base.py @@ -129,7 +129,7 @@ STATICFILES_DIRS = [ STATIC_ROOT = 'static' STATIC_URL = '/static/' -AUTH_USER_MODEL = 'registration.Member' +AUTH_USER_MODEL = 'registration.CustomUser' COMPRESS_PRECOMPILERS = ( ('text/x-scss', 'django_libsass.SassCompiler'), diff --git a/bikeshop_project/bikeshop/utils/member_import.py b/bikeshop_project/bikeshop/utils/member_import.py index 2428220..967ad5e 100644 --- a/bikeshop_project/bikeshop/utils/member_import.py +++ b/bikeshop_project/bikeshop/utils/member_import.py @@ -53,7 +53,7 @@ def member_import(): try: new_member = Member.objects.create( - email=row.get('email', None) or email_generator(), + email=row.get('email', None), email_consent=row.get('email_consent', False), first_name=row.get('first_name'), last_name=row.get('last_name'), diff --git a/bikeshop_project/core/migrations/0001_initial.py b/bikeshop_project/core/migrations/0001_initial.py index 7c6d0f5..f00fc7b 100644 --- a/bikeshop_project/core/migrations/0001_initial.py +++ b/bikeshop_project/core/migrations/0001_initial.py @@ -1,8 +1,7 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-03-23 02:01 +# Generated by Django 1.9.4 on 2016-07-04 22:08 from __future__ import unicode_literals -from django.conf import settings from django.db import migrations, models import django.db.models.deletion import django.utils.timezone @@ -13,7 +12,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('registration', '0001_initial'), ] operations = [ @@ -24,12 +23,32 @@ class Migration(migrations.Migration): ('created_at', models.DateTimeField(auto_now_add=True)), ('modified_at', models.DateTimeField(auto_now=True)), ('renewed_at', models.DateTimeField(default=django.utils.timezone.now)), - ('safe_space', models.BooleanField(default=False)), - ('community', models.BooleanField(default=False)), - ('space', models.BooleanField(default=False)), - ('give_back', models.BooleanField(default=False)), - ('acknowledgement', models.BooleanField(default=False)), - ('member', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='membership', to=settings.AUTH_USER_MODEL)), + ('self_identification', models.CharField(blank=True, max_length=255, null=True)), + ('gender', models.CharField(blank=True, max_length=255, null=True)), + ('involvement', models.CharField(blank=True, max_length=255, null=True)), + ('member', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='memberships', to='registration.Member')), ], ), + migrations.CreateModel( + name='Payment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('type', models.CharField(choices=[('NONE', 'None'), ('CASH', 'Cash'), ('CHEQUE', 'Cheque'), ('VOLUNTEERING', 'Volunteering'), ('SQUARE', 'Square'), ('PAYPAL', 'PayPal'), ('UNKNOWN', 'Unknown')], default='NONE', max_length=12)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ], + ), + migrations.CreateModel( + name='Visit', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('purpose', models.CharField(choices=[('VOLUNTEER', 'volunteer'), ('FIX', 'fix bike'), ('WORKSHOP', 'workshop'), ('VISIT', 'visit'), ('DONATE', 'donate'), ('STAFF', 'staff')], max_length=50)), + ('member', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='registration.Member')), + ], + ), + migrations.AddField( + model_name='membership', + name='payment', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='membership', to='core.Payment'), + ), ] diff --git a/bikeshop_project/core/migrations/0002_payment.py b/bikeshop_project/core/migrations/0002_payment.py deleted file mode 100644 index cec9bd3..0000000 --- a/bikeshop_project/core/migrations/0002_payment.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-03-23 02:27 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Payment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('type', models.CharField(choices=[('CASH', 'cash'), ('CHEQUE', 'cheque'), ('VOLUNTEERING', 'volunteering'), ('STRIPE', 'stripe'), ('PAYPAL', 'paypal')], max_length=12)), - ('created_at', models.DateTimeField(auto_now_add=True)), - ('membership', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Membership')), - ], - ), - ] diff --git a/bikeshop_project/core/migrations/0003_visit.py b/bikeshop_project/core/migrations/0003_visit.py deleted file mode 100644 index 503d81d..0000000 --- a/bikeshop_project/core/migrations/0003_visit.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-03-23 02:34 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('core', '0002_payment'), - ] - - operations = [ - migrations.CreateModel( - name='Visit', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created_at', models.DateTimeField(auto_now_add=True)), - ('purpose', models.CharField(choices=[('VOLUNTEER', 'volunteer'), ('WORK', 'work on bike'), ('WORKSHOP', 'workshop')], max_length=50)), - ('member', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), - ], - ), - ] diff --git a/bikeshop_project/core/migrations/0004_auto_20160405_0354.py b/bikeshop_project/core/migrations/0004_auto_20160405_0354.py deleted file mode 100644 index 66807c7..0000000 --- a/bikeshop_project/core/migrations/0004_auto_20160405_0354.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-04-05 03:54 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0003_visit'), - ] - - operations = [ - migrations.RemoveField( - model_name='membership', - name='acknowledgement', - ), - migrations.RemoveField( - model_name='membership', - name='community', - ), - migrations.RemoveField( - model_name='membership', - name='safe_space', - ), - migrations.RemoveField( - model_name='membership', - name='space', - ), - ] diff --git a/bikeshop_project/core/migrations/0004_auto_20160410_1816.py b/bikeshop_project/core/migrations/0004_auto_20160410_1816.py deleted file mode 100644 index 5a71358..0000000 --- a/bikeshop_project/core/migrations/0004_auto_20160410_1816.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-04-10 18:16 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0003_visit'), - ] - - operations = [ - migrations.AddField( - model_name='membership', - name='gender', - field=models.CharField(blank=True, max_length=255, null=True), - ), - migrations.AddField( - model_name='membership', - name='involvement', - field=models.CharField(blank=True, max_length=255, null=True), - ), - migrations.AddField( - model_name='membership', - name='self_identification', - field=models.CharField(blank=True, max_length=255, null=True), - ), - ] diff --git a/bikeshop_project/core/migrations/0005_merge.py b/bikeshop_project/core/migrations/0005_merge.py deleted file mode 100644 index a65903c..0000000 --- a/bikeshop_project/core/migrations/0005_merge.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-04-10 18:33 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0004_auto_20160405_0354'), - ('core', '0004_auto_20160410_1816'), - ] - - operations = [ - ] diff --git a/bikeshop_project/core/migrations/0006_auto_20160410_1833.py b/bikeshop_project/core/migrations/0006_auto_20160410_1833.py deleted file mode 100644 index f152ad2..0000000 --- a/bikeshop_project/core/migrations/0006_auto_20160410_1833.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-04-10 18:33 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0005_merge'), - ] - - operations = [ - migrations.AddField( - model_name='membership', - name='acknowledgement', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='membership', - name='community', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='membership', - name='safe_space', - field=models.BooleanField(default=False), - ), - migrations.AlterField( - model_name='visit', - name='purpose', - field=models.CharField(choices=[('VOLUNTEER', 'volunteer'), ('FIX', 'fix bike'), ('WORKSHOP', 'workshop'), ('VISIT', 'visit'), ('DONATE', 'donate'), ('STAFF', 'staff')], max_length=50), - ), - ] diff --git a/bikeshop_project/core/migrations/0007_auto_20160501_2253.py b/bikeshop_project/core/migrations/0007_auto_20160501_2253.py deleted file mode 100644 index 1219ac9..0000000 --- a/bikeshop_project/core/migrations/0007_auto_20160501_2253.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-01 22:53 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0006_auto_20160410_1833'), - ] - - operations = [ - migrations.RemoveField( - model_name='membership', - name='acknowledgement', - ), - migrations.RemoveField( - model_name='membership', - name='community', - ), - migrations.RemoveField( - model_name='membership', - name='give_back', - ), - migrations.RemoveField( - model_name='membership', - name='safe_space', - ), - ] diff --git a/bikeshop_project/core/migrations/0008_auto_20160526_0059.py b/bikeshop_project/core/migrations/0008_auto_20160526_0059.py deleted file mode 100644 index b980641..0000000 --- a/bikeshop_project/core/migrations/0008_auto_20160526_0059.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-26 00:59 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0007_auto_20160501_2253'), - ] - - operations = [ - migrations.RemoveField( - model_name='payment', - name='membership', - ), - migrations.AddField( - model_name='membership', - name='payment', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Payment'), - ), - ] diff --git a/bikeshop_project/core/migrations/0009_remove_membership_member.py b/bikeshop_project/core/migrations/0009_remove_membership_member.py deleted file mode 100644 index 6a8d3ba..0000000 --- a/bikeshop_project/core/migrations/0009_remove_membership_member.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-26 01:50 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0008_auto_20160526_0059'), - ] - - operations = [ - migrations.RemoveField( - model_name='membership', - name='member', - ), - ] diff --git a/bikeshop_project/core/migrations/0010_membership_member.py b/bikeshop_project/core/migrations/0010_membership_member.py deleted file mode 100644 index c956f08..0000000 --- a/bikeshop_project/core/migrations/0010_membership_member.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-31 02:31 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('core', '0009_remove_membership_member'), - ] - - operations = [ - migrations.AddField( - model_name='membership', - name='member', - field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='membership', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/bikeshop_project/core/migrations/0011_auto_20160531_0233.py b/bikeshop_project/core/migrations/0011_auto_20160531_0233.py deleted file mode 100644 index b310553..0000000 --- a/bikeshop_project/core/migrations/0011_auto_20160531_0233.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-31 02:33 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0010_membership_member'), - ] - - operations = [ - migrations.AlterField( - model_name='membership', - name='member', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='memberships', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/bikeshop_project/core/migrations/0012_auto_20160531_0234.py b/bikeshop_project/core/migrations/0012_auto_20160531_0234.py deleted file mode 100644 index d4343da..0000000 --- a/bikeshop_project/core/migrations/0012_auto_20160531_0234.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-31 02:34 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0011_auto_20160531_0233'), - ] - - operations = [ - migrations.RemoveField( - model_name='membership', - name='payment', - ), - migrations.AddField( - model_name='payment', - name='membership', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='core.Membership'), - ), - ] diff --git a/bikeshop_project/core/migrations/0013_auto_20160531_0236.py b/bikeshop_project/core/migrations/0013_auto_20160531_0236.py deleted file mode 100644 index 5dae435..0000000 --- a/bikeshop_project/core/migrations/0013_auto_20160531_0236.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-31 02:36 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0012_auto_20160531_0234'), - ] - - operations = [ - migrations.RemoveField( - model_name='payment', - name='membership', - ), - migrations.AddField( - model_name='membership', - name='payment', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='membership', to='core.Payment'), - ), - ] diff --git a/bikeshop_project/core/migrations/0014_payment_paid.py b/bikeshop_project/core/migrations/0014_payment_paid.py deleted file mode 100644 index 67223fe..0000000 --- a/bikeshop_project/core/migrations/0014_payment_paid.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-31 02:38 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0013_auto_20160531_0236'), - ] - - operations = [ - migrations.AddField( - model_name='payment', - name='paid', - field=models.BooleanField(default=False), - ), - ] diff --git a/bikeshop_project/core/migrations/0015_auto_20160531_0413.py b/bikeshop_project/core/migrations/0015_auto_20160531_0413.py deleted file mode 100644 index 3e6bdc0..0000000 --- a/bikeshop_project/core/migrations/0015_auto_20160531_0413.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-31 04:13 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0014_payment_paid'), - ] - - operations = [ - migrations.AlterField( - model_name='payment', - name='type', - field=models.CharField(choices=[('CASH', 'cash'), ('CHEQUE', 'cheque'), ('VOLUNTEERING', 'volunteering'), ('STRIPE', 'stripe'), ('PAYPAL', 'paypal')], default='None', max_length=12), - ), - ] diff --git a/bikeshop_project/core/migrations/0016_auto_20160531_0416.py b/bikeshop_project/core/migrations/0016_auto_20160531_0416.py deleted file mode 100644 index 55ee7fc..0000000 --- a/bikeshop_project/core/migrations/0016_auto_20160531_0416.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-31 04:16 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0015_auto_20160531_0413'), - ] - - operations = [ - migrations.RemoveField( - model_name='payment', - name='paid', - ), - migrations.AlterField( - model_name='payment', - name='type', - field=models.CharField(choices=[('NONE', 'None'), ('CASH', 'Cash'), ('CHEQUE', 'Cheque'), ('VOLUNTEERING', 'Volunteering'), ('STRIPE', 'Stripe'), ('PAYPAL', 'PayPal')], default='NONE', max_length=12), - ), - ] diff --git a/bikeshop_project/core/migrations/0017_auto_20160626_1842.py b/bikeshop_project/core/migrations/0017_auto_20160626_1842.py deleted file mode 100644 index a880362..0000000 --- a/bikeshop_project/core/migrations/0017_auto_20160626_1842.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-06-26 18:42 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0016_auto_20160531_0416'), - ] - - operations = [ - migrations.AlterField( - model_name='payment', - name='type', - field=models.CharField(choices=[('NONE', 'None'), ('CASH', 'Cash'), ('CHEQUE', 'Cheque'), ('VOLUNTEERING', 'Volunteering'), ('SQUARE', 'Square'), ('PAYPAL', 'PayPal')], default='NONE', max_length=12), - ), - ] diff --git a/bikeshop_project/core/migrations/0018_auto_20160626_1844.py b/bikeshop_project/core/migrations/0018_auto_20160626_1844.py deleted file mode 100644 index e29f8ed..0000000 --- a/bikeshop_project/core/migrations/0018_auto_20160626_1844.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-06-26 18:44 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0017_auto_20160626_1842'), - ] - - operations = [ - migrations.AlterField( - model_name='payment', - name='type', - field=models.CharField(choices=[('NONE', 'None'), ('CASH', 'Cash'), ('CHEQUE', 'Cheque'), ('VOLUNTEERING', 'Volunteering'), ('SQUARE', 'Square'), ('PAYPAL', 'PayPal'), ('UNKNOWN', 'Unknown')], default='NONE', max_length=12), - ), - ] diff --git a/bikeshop_project/registration/admin.py b/bikeshop_project/registration/admin.py index de2620a..bef2f8b 100644 --- a/bikeshop_project/registration/admin.py +++ b/bikeshop_project/registration/admin.py @@ -1,34 +1,34 @@ -from django.contrib import admin -from .models import Member -from django.contrib.auth.admin import UserAdmin -from django.contrib.auth.forms import UserChangeForm - - -class MemberChangeForm(UserChangeForm): - class Meta(UserChangeForm.Meta): - model = Member - -class MemberAdmin(UserAdmin): - form = MemberChangeForm - - fieldsets = fieldsets = ( - (None, {'fields': ('email', 'password')}), - ('Personal info', {'fields': ('first_name', 'last_name')}), - ('Permissions', {'fields': ('is_active', 'is_superuser', - 'groups', 'user_permissions')}), - ('Important dates', {'fields': ('last_login',)}), - ) - add_fieldsets = ( - (None, { - 'classes': ('wide',), - 'fields': ('email', 'password1', 'password2'), - }), - ) - ordering = ('email',) - list_display = ('email', 'first_name', 'last_name') - list_filter = ('is_superuser', 'is_active', 'groups') - search_fields = ('email', 'first_name', 'last_name', 'email') - - -# Register your models here. -admin.site.register(Member, MemberAdmin) +# from django.contrib import admin +# from .models import CustomUser +# from django.contrib.auth.admin import UserAdmin +# from django.contrib.auth.forms import UserChangeForm +# +# +# class CustomUserChangeForm(UserChangeForm): +# class Meta(UserChangeForm.Meta): +# model = CustomUser +# +# +# class CustomUserAdmin(UserAdmin): +# form = CustomUserChangeForm +# +# fieldsets = ( +# (None, {'fields': ('email', 'password')}), +# ('Permissions', {'fields': ('is_active', 'is_superuser', +# 'groups', 'user_permissions')}), +# ('Important dates', {'fields': ('last_login',)}), +# ) +# add_fieldsets = ( +# (None, { +# 'classes': ('wide',), +# 'fields': ('email', 'password1', 'password2'), +# }), +# ) +# ordering = ('email',) +# list_display = ('email',) +# list_filter = ('is_superuser', 'is_active', 'groups') +# search_fields = ('email',) +# +# +# # Register your models here. +# admin.site.register(CustomUser, CustomUserAdmin) diff --git a/bikeshop_project/registration/migrations/0001_initial.py b/bikeshop_project/registration/migrations/0001_initial.py index da6c081..a211a58 100644 --- a/bikeshop_project/registration/migrations/0001_initial.py +++ b/bikeshop_project/registration/migrations/0001_initial.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-03-23 01:25 +# Generated by Django 1.9.4 on 2016-07-04 22:04 from __future__ import unicode_literals +from django.conf import settings from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -15,13 +17,28 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='Member', + name='CustomUser', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('password', models.CharField(max_length=128, 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')), ('email', models.EmailField(max_length=255, unique=True, verbose_name='email address')), + ('is_admin', models.BooleanField(default=False)), + ('is_active', models.BooleanField(default=True)), + ('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={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Member', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('email', models.EmailField(blank=True, max_length=255, null=True, verbose_name='email address')), + ('email_consent', models.BooleanField(default=False)), ('first_name', models.CharField(max_length=255)), ('last_name', models.CharField(max_length=255)), ('preferred_name', models.CharField(blank=True, max_length=255, null=True)), @@ -32,18 +49,10 @@ class Migration(migrations.Migration): ('city', models.CharField(blank=True, max_length=255, null=True)), ('province', models.CharField(blank=True, max_length=255, null=True)), ('country', models.CharField(blank=True, max_length=255, null=True)), - ('post_code', models.CharField(blank=True, max_length=20, null=True)), - ('self_identification', models.CharField(blank=True, max_length=255, null=True)), - ('gender', models.CharField(blank=True, max_length=255, null=True)), - ('involvement', models.CharField(blank=True, max_length=255, null=True)), + ('post_code', models.CharField(max_length=20, null=True)), ('waiver', models.DateTimeField(blank=True, null=True)), ('is_active', models.BooleanField(default=True)), - ('is_admin', models.BooleanField(default=False)), - ('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')), + ('user', models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], - options={ - 'abstract': False, - }, ), ] diff --git a/bikeshop_project/registration/migrations/0002_member_email_consent.py b/bikeshop_project/registration/migrations/0002_member_email_consent.py deleted file mode 100644 index 7f18d39..0000000 --- a/bikeshop_project/registration/migrations/0002_member_email_consent.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-03-27 04:50 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('registration', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='member', - name='email_consent', - field=models.BooleanField(default=False), - ), - ] diff --git a/bikeshop_project/registration/migrations/0003_auto_20160327_0620.py b/bikeshop_project/registration/migrations/0003_auto_20160327_0620.py deleted file mode 100644 index de51319..0000000 --- a/bikeshop_project/registration/migrations/0003_auto_20160327_0620.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-03-27 06:20 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('registration', '0002_member_email_consent'), - ] - - operations = [ - migrations.AlterField( - model_name='member', - name='date_of_birth', - field=models.DateField(null=True), - ), - migrations.AlterField( - model_name='member', - name='post_code', - field=models.CharField(max_length=20, null=True), - ), - ] diff --git a/bikeshop_project/registration/migrations/0004_auto_20160410_1816.py b/bikeshop_project/registration/migrations/0004_auto_20160410_1816.py deleted file mode 100644 index 003e3c7..0000000 --- a/bikeshop_project/registration/migrations/0004_auto_20160410_1816.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-04-10 18:16 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('registration', '0003_auto_20160327_0620'), - ] - - operations = [ - migrations.RemoveField( - model_name='member', - name='gender', - ), - migrations.RemoveField( - model_name='member', - name='involvement', - ), - migrations.RemoveField( - model_name='member', - name='self_identification', - ), - migrations.AlterField( - model_name='member', - name='date_of_birth', - field=models.DateField(blank=True, null=True), - ), - ] diff --git a/bikeshop_project/registration/migrations/0005_member_membership.py b/bikeshop_project/registration/migrations/0005_member_membership.py deleted file mode 100644 index d6c4c1c..0000000 --- a/bikeshop_project/registration/migrations/0005_member_membership.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-26 01:50 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0009_remove_membership_member'), - ('registration', '0004_auto_20160410_1816'), - ] - - operations = [ - migrations.AddField( - model_name='member', - name='membership', - field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='member', to='core.Membership'), - ), - ] diff --git a/bikeshop_project/registration/migrations/0006_remove_member_membership.py b/bikeshop_project/registration/migrations/0006_remove_member_membership.py deleted file mode 100644 index f5d750d..0000000 --- a/bikeshop_project/registration/migrations/0006_remove_member_membership.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.4 on 2016-05-31 02:31 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('registration', '0005_member_membership'), - ] - - operations = [ - migrations.RemoveField( - model_name='member', - name='membership', - ), - ] diff --git a/bikeshop_project/registration/models.py b/bikeshop_project/registration/models.py index b8a5ad0..26cad18 100644 --- a/bikeshop_project/registration/models.py +++ b/bikeshop_project/registration/models.py @@ -2,14 +2,12 @@ from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, Permis from django.db import models -class CustomMemberManager(BaseUserManager): - def create_user(self, email, first_name, last_name, password=None): +class CustomUserManager(BaseUserManager): + def create_user(self, email, password=None): """ Creates and saves a User with the given email and password. :param email: str :param password: str - :param first_name: str - :param last_name: str :return: object `CustomUser` """ if not email: @@ -38,12 +36,43 @@ class CustomMemberManager(BaseUserManager): return user -class Member(AbstractBaseUser, PermissionsMixin): +class CustomUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField( verbose_name='email address', max_length=255, unique=True, ) + is_admin = models.BooleanField(default=False) + is_active = models.BooleanField(default=True) + + objects = CustomUserManager() + + USERNAME_FIELD = 'email' + + @property + def is_staff(self): + # Simplest possible answer: All admins are staff + return self.is_admin + + def get_short_name(self): + return self.email + + def get_full_name(self): + return self.email + + def __str__(self): # __unicode__ on Python 2 + return self.email + + +class Member(models.Model): + user = models.OneToOneField(CustomUser, on_delete=models.CASCADE, null=True) + email = models.EmailField( + verbose_name='email address', + max_length=255, + unique=False, + null=True, + blank=True, + ) email_consent = models.BooleanField(default=False) first_name = models.CharField(max_length=255, null=False) last_name = models.CharField(max_length=255, null=False) @@ -58,12 +87,6 @@ class Member(AbstractBaseUser, PermissionsMixin): post_code = models.CharField(max_length=20, null=True, blank=False) waiver = models.DateTimeField(null=True, blank=True) is_active = models.BooleanField(default=True) - is_admin = models.BooleanField(default=False) - - objects = CustomMemberManager() - - USERNAME_FIELD = 'email' - # REQUIRED_FIELDS = [] @property def full_name(self): @@ -78,12 +101,7 @@ class Member(AbstractBaseUser, PermissionsMixin): def get_short_name(self): # The user is identified by their email address - return self.email + return self.user.email def __str__(self): # __unicode__ on Python 2 - return self.email - - @property - def is_staff(self): - # Simplest possible answer: All admins are staff - return self.is_admin + return self.user.email From 57c82745a499b6aa5ff57bd80c80bb6d90c11668 Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Mon, 4 Jul 2016 19:04:37 -0600 Subject: [PATCH 2/7] Wrong return. --- bikeshop_project/bikeshop/utils/member_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bikeshop_project/bikeshop/utils/member_import.py b/bikeshop_project/bikeshop/utils/member_import.py index 967ad5e..f10985f 100644 --- a/bikeshop_project/bikeshop/utils/member_import.py +++ b/bikeshop_project/bikeshop/utils/member_import.py @@ -44,7 +44,7 @@ def member_import(): try: waiver = dateutil.parser.parse(row.get('signed', None)) except ValueError: - dob = None + waiver = None try: renewed_at = dateutil.parser.parse(row.get('timestamp', None)) From 9b252938984de7b842a35c25ae4b4050b75e751b Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Mon, 4 Jul 2016 19:05:38 -0600 Subject: [PATCH 3/7] Redundant parens. --- bikeshop_project/bikeshop/utils/member_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bikeshop_project/bikeshop/utils/member_import.py b/bikeshop_project/bikeshop/utils/member_import.py index f10985f..45a790c 100644 --- a/bikeshop_project/bikeshop/utils/member_import.py +++ b/bikeshop_project/bikeshop/utils/member_import.py @@ -28,7 +28,7 @@ def payment_type(pt): try: return [type for type in types if type[1].lower() == pt.lower()][0] except IndexError: - return ('UNKNOWN', 'Unknown') + return 'UNKNOWN', 'Unknown' def member_import(): From c993de85bd6f14c535130a0c6cbe4edb78f24427 Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Mon, 4 Jul 2016 19:05:52 -0600 Subject: [PATCH 4/7] Rename function. --- bikeshop_project/bikeshop/utils/member_import.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bikeshop_project/bikeshop/utils/member_import.py b/bikeshop_project/bikeshop/utils/member_import.py index 45a790c..33c6596 100644 --- a/bikeshop_project/bikeshop/utils/member_import.py +++ b/bikeshop_project/bikeshop/utils/member_import.py @@ -23,10 +23,10 @@ def email_generator(): return '{0}.{1}@example.com'.format(*local) -def payment_type(pt): - types = Payment.payment_choices +def get_payment_type(pt): + payment_types = Payment.payment_choices try: - return [type for type in types if type[1].lower() == pt.lower()][0] + return [payment_type for payment_type in payment_types if payment_type[1].lower() == pt.lower()][0] except IndexError: return 'UNKNOWN', 'Unknown' @@ -70,10 +70,10 @@ def member_import(): ) payment = Payment.objects.create( - type=payment_type(row.get('payment'))[0], + type=get_payment_type(row.get('payment'))[0], ) - membership = Membership.objects.create( + Membership.objects.create( renewed_at=renewed_at, self_identification=row.get('self_identification', None), gender=row.get('gender', None), From ebb2b80c77e5659f6f38e761221b8217fb913407 Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Mon, 4 Jul 2016 19:20:42 -0600 Subject: [PATCH 5/7] Get rid of 'Custom' in admin site. --- bikeshop_project/registration/models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bikeshop_project/registration/models.py b/bikeshop_project/registration/models.py index 26cad18..c1f6434 100644 --- a/bikeshop_project/registration/models.py +++ b/bikeshop_project/registration/models.py @@ -63,6 +63,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): def __str__(self): # __unicode__ on Python 2 return self.email + class Meta: + verbose_name = 'User' + verbose_name_plural = 'Users' + class Member(models.Model): user = models.OneToOneField(CustomUser, on_delete=models.CASCADE, null=True) From 8efb40ed2c588d6a22074d33b5a21cbf258d9294 Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Mon, 4 Jul 2016 19:22:16 -0600 Subject: [PATCH 6/7] Return values that can't be null. --- bikeshop_project/registration/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bikeshop_project/registration/models.py b/bikeshop_project/registration/models.py index c1f6434..15d1e01 100644 --- a/bikeshop_project/registration/models.py +++ b/bikeshop_project/registration/models.py @@ -98,14 +98,14 @@ class Member(models.Model): def get_full_name(self): # The user is identified by their email address - if self.first_name and self.last_name: - return '{0} {1}'.format(self.first_name, self.last_name) - else: - return self.email + return '{0} {1}'.format(self.first_name, self.last_name) def get_short_name(self): # The user is identified by their email address - return self.user.email + if self.email: + return self.email + else: + return self.last_name def __str__(self): # __unicode__ on Python 2 - return self.user.email + return self.email From 0745279c12e8a1eb027a94e174b2921235fbd576 Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Mon, 4 Jul 2016 19:22:30 -0600 Subject: [PATCH 7/7] Update available models in admin site. --- bikeshop_project/registration/admin.py | 72 ++++++++++++++------------ 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/bikeshop_project/registration/admin.py b/bikeshop_project/registration/admin.py index bef2f8b..841275d 100644 --- a/bikeshop_project/registration/admin.py +++ b/bikeshop_project/registration/admin.py @@ -1,34 +1,38 @@ -# from django.contrib import admin -# from .models import CustomUser -# from django.contrib.auth.admin import UserAdmin -# from django.contrib.auth.forms import UserChangeForm -# -# -# class CustomUserChangeForm(UserChangeForm): -# class Meta(UserChangeForm.Meta): -# model = CustomUser -# -# -# class CustomUserAdmin(UserAdmin): -# form = CustomUserChangeForm -# -# fieldsets = ( -# (None, {'fields': ('email', 'password')}), -# ('Permissions', {'fields': ('is_active', 'is_superuser', -# 'groups', 'user_permissions')}), -# ('Important dates', {'fields': ('last_login',)}), -# ) -# add_fieldsets = ( -# (None, { -# 'classes': ('wide',), -# 'fields': ('email', 'password1', 'password2'), -# }), -# ) -# ordering = ('email',) -# list_display = ('email',) -# list_filter = ('is_superuser', 'is_active', 'groups') -# search_fields = ('email',) -# -# -# # Register your models here. -# admin.site.register(CustomUser, CustomUserAdmin) +from django.contrib import admin +from .models import CustomUser, Member +from django.contrib.auth.admin import UserAdmin +from django.contrib.auth.forms import UserChangeForm + + +class CustomUserChangeForm(UserChangeForm): + class Meta(UserChangeForm.Meta): + model = CustomUser + + +@admin.register(CustomUser) +class CustomUserAdmin(UserAdmin): + form = CustomUserChangeForm + + fieldsets = ( + (None, {'fields': ('email', 'password')}), + ('Permissions', {'fields': ('is_active', 'is_superuser', + 'groups', 'user_permissions')}), + ('Important dates', {'fields': ('last_login',)}), + ) + add_fieldsets = ( + (None, { + 'classes': ('wide',), + 'fields': ('email', 'password1', 'password2'), + }), + ) + ordering = ('email',) + list_display = ('email',) + list_filter = ('is_superuser', 'is_active', 'groups') + search_fields = ('email',) + + +@admin.register(Member) +class MemberAdmin(admin.ModelAdmin): + list_display = ('get_full_name',) + ordering = ('last_name',) + search_fields = ('email', 'first_name', 'last_name') \ No newline at end of file