From c4596c25c6594d4b7602d913ec68df4423c0f5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 1 Sep 2019 00:27:36 +0200 Subject: [PATCH] Run linting (aka the blackening) --- accounting/admin.py | 7 +- accounting/apps.py | 2 +- accounting/migrations/0001_initial.py | 251 ++++++++++++++++++++------ accounting/models.py | 61 ++----- accounting/tests.py | 5 +- manage.py | 2 +- membership/apps.py | 2 +- membership/migrations/0001_initial.py | 230 +++++++++++++++++------ membership/models.py | 47 ++--- project/context_processors.py | 4 +- project/settings/base.py | 101 +++++------ project/urls.py | 4 +- users/admin.py | 4 +- users/apps.py | 2 +- users/migrations/0001_initial.py | 75 ++++++-- users/models.py | 12 +- users/urls.py | 67 +++++-- users/views.py | 14 +- 18 files changed, 590 insertions(+), 300 deletions(-) diff --git a/accounting/admin.py b/accounting/admin.py index 41d2755..61e4ada 100644 --- a/accounting/admin.py +++ b/accounting/admin.py @@ -7,22 +7,25 @@ from . import models @admin.register(models.Order) class OrderAdmin(admin.ModelAdmin): - list_display = ('who', 'description', 'created', 'is_paid',) + list_display = ("who", "description", "created", "is_paid") def who(self, instance): return instance.user.get_full_name() + who.short_description = _("Customer") @admin.register(models.Payment) class PaymentAdmin(admin.ModelAdmin): - list_display = ('who', 'description', 'order_id', 'created',) + list_display = ("who", "description", "order_id", "created") def who(self, instance): return instance.order.user.get_full_name() + who.short_description = _("Customer") def order_id(self, instance): return instance.order.id + order_id.short_description = _("Order ID") diff --git a/accounting/apps.py b/accounting/apps.py index bbcd3d0..e142288 100644 --- a/accounting/apps.py +++ b/accounting/apps.py @@ -2,4 +2,4 @@ from django.apps import AppConfig class AccountingConfig(AppConfig): - name = 'accounting' + name = "accounting" diff --git a/accounting/migrations/0001_initial.py b/accounting/migrations/0001_initial.py index a226af6..23a2ef0 100644 --- a/accounting/migrations/0001_initial.py +++ b/accounting/migrations/0001_initial.py @@ -12,73 +12,222 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ] + dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)] operations = [ migrations.CreateModel( - name='Account', + name="Account", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), - ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), - ('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "modified", + models.DateTimeField(auto_now=True, verbose_name="modified"), + ), + ( + "created", + models.DateTimeField(auto_now_add=True, verbose_name="created"), + ), + ( + "owner", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), ], - options={ - 'abstract': False, - }, + options={"abstract": False}, ), migrations.CreateModel( - name='Order', + name="Order", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), - ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), - ('description', models.CharField(max_length=1024, verbose_name='description')), - ('price_currency', djmoney.models.fields.CurrencyField(choices=[('DKK', 'DKK')], default='XYZ', editable=False, max_length=3)), - ('price', djmoney.models.fields.MoneyField(decimal_places=2, default=Decimal('0.0'), max_digits=16, verbose_name='price (excl. VAT)')), - ('vat_currency', djmoney.models.fields.CurrencyField(choices=[('DKK', 'DKK')], default='XYZ', editable=False, max_length=3)), - ('vat', djmoney.models.fields.MoneyField(decimal_places=2, default=Decimal('0.0'), max_digits=16, verbose_name='VAT')), - ('is_paid', models.BooleanField(default=False, verbose_name='is paid')), - ('account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='accounting.Account')), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "modified", + models.DateTimeField(auto_now=True, verbose_name="modified"), + ), + ( + "created", + models.DateTimeField(auto_now_add=True, verbose_name="created"), + ), + ( + "description", + models.CharField(max_length=1024, verbose_name="description"), + ), + ( + "price_currency", + djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], + default="XYZ", + editable=False, + max_length=3, + ), + ), + ( + "price", + djmoney.models.fields.MoneyField( + decimal_places=2, + default=Decimal("0.0"), + max_digits=16, + verbose_name="price (excl. VAT)", + ), + ), + ( + "vat_currency", + djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], + default="XYZ", + editable=False, + max_length=3, + ), + ), + ( + "vat", + djmoney.models.fields.MoneyField( + decimal_places=2, + default=Decimal("0.0"), + max_digits=16, + verbose_name="VAT", + ), + ), + ("is_paid", models.BooleanField(default=False, verbose_name="is paid")), + ( + "account", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="accounting.Account", + ), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), ], - options={ - 'verbose_name': 'Order', - 'verbose_name_plural': 'Orders', - }, + options={"verbose_name": "Order", "verbose_name_plural": "Orders"}, ), migrations.CreateModel( - name='Payment', + name="Payment", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), - ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), - ('amount_currency', djmoney.models.fields.CurrencyField(choices=[('DKK', 'DKK')], default='XYZ', editable=False, max_length=3)), - ('amount', djmoney.models.fields.MoneyField(decimal_places=2, default=Decimal('0.0'), max_digits=16)), - ('description', models.CharField(max_length=1024, verbose_name='description')), - ('stripe_charge_id', models.CharField(blank=True, max_length=255, null=True)), - ('order', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='accounting.Order')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "modified", + models.DateTimeField(auto_now=True, verbose_name="modified"), + ), + ( + "created", + models.DateTimeField(auto_now_add=True, verbose_name="created"), + ), + ( + "amount_currency", + djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], + default="XYZ", + editable=False, + max_length=3, + ), + ), + ( + "amount", + djmoney.models.fields.MoneyField( + decimal_places=2, default=Decimal("0.0"), max_digits=16 + ), + ), + ( + "description", + models.CharField(max_length=1024, verbose_name="description"), + ), + ( + "stripe_charge_id", + models.CharField(blank=True, max_length=255, null=True), + ), + ( + "order", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="accounting.Order", + ), + ), ], - options={ - 'verbose_name': 'payment', - 'verbose_name_plural': 'payments', - }, + options={"verbose_name": "payment", "verbose_name_plural": "payments"}, ), migrations.CreateModel( - name='Transaction', + name="Transaction", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), - ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), - ('amount_currency', djmoney.models.fields.CurrencyField(choices=[('DKK', 'DKK')], default='XYZ', editable=False, max_length=3)), - ('amount', djmoney.models.fields.MoneyField(decimal_places=2, default=Decimal('0.0'), help_text='This will include VAT', max_digits=16, verbose_name='amount')), - ('description', models.CharField(max_length=1024, verbose_name='description')), - ('account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transactions', to='accounting.Account')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "modified", + models.DateTimeField(auto_now=True, verbose_name="modified"), + ), + ( + "created", + models.DateTimeField(auto_now_add=True, verbose_name="created"), + ), + ( + "amount_currency", + djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], + default="XYZ", + editable=False, + max_length=3, + ), + ), + ( + "amount", + djmoney.models.fields.MoneyField( + decimal_places=2, + default=Decimal("0.0"), + help_text="This will include VAT", + max_digits=16, + verbose_name="amount", + ), + ), + ( + "description", + models.CharField(max_length=1024, verbose_name="description"), + ), + ( + "account", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="transactions", + to="accounting.Account", + ), + ), ], - options={ - 'abstract': False, - }, + options={"abstract": False}, ), ] diff --git a/accounting/models.py b/accounting/models.py index 0b55eb3..d7aa141 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -11,14 +11,8 @@ from djmoney.models.fields import MoneyField class CreatedModifiedAbstract(models.Model): - modified = models.DateTimeField( - auto_now=True, - verbose_name=_("modified"), - ) - created = models.DateTimeField( - auto_now_add=True, - verbose_name=_("created"), - ) + modified = models.DateTimeField(auto_now=True, verbose_name=_("modified")) + created = models.DateTimeField(auto_now_add=True, verbose_name=_("created")) class Meta: abstract = True @@ -34,7 +28,7 @@ class Account(CreatedModifiedAbstract): @property def balance(self): - return self.transactions.all().aggregate(Sum('amount')).get('amount', 0) + return self.transactions.all().aggregate(Sum("amount")).get("amount", 0) class Transaction(CreatedModifiedAbstract): @@ -44,20 +38,15 @@ class Transaction(CreatedModifiedAbstract): """ account = models.ForeignKey( - Account, - on_delete=models.PROTECT, - related_name="transactions", + Account, on_delete=models.PROTECT, related_name="transactions" ) amount = MoneyField( verbose_name=_("amount"), max_digits=16, decimal_places=2, - help_text=_("This will include VAT") - ) - description = models.CharField( - max_length=1024, - verbose_name=_("description") + help_text=_("This will include VAT"), ) + description = models.CharField(max_length=1024, verbose_name=_("description")) class Order(CreatedModifiedAbstract): @@ -71,26 +60,14 @@ class Order(CreatedModifiedAbstract): account = models.ForeignKey(Account, on_delete=models.PROTECT) is_paid = models.BooleanField(default=False) - description = models.CharField( - max_length=1024, - verbose_name=_("description") - ) + description = models.CharField(max_length=1024, verbose_name=_("description")) price = MoneyField( - verbose_name=_("price (excl. VAT)"), - max_digits=16, - decimal_places=2, - ) - vat = MoneyField( - verbose_name=_("VAT"), - max_digits=16, - decimal_places=2, + verbose_name=_("price (excl. VAT)"), max_digits=16, decimal_places=2 ) + vat = MoneyField(verbose_name=_("VAT"), max_digits=16, decimal_places=2) - is_paid = models.BooleanField( - default=False, - verbose_name=_("is paid"), - ) + is_paid = models.BooleanField(default=False, verbose_name=_("is paid")) @property def total(self): @@ -105,7 +82,7 @@ class Order(CreatedModifiedAbstract): pk = str(self.pk).encode("utf-8") x = md5() x.update(pk) - extra_hash = (settings.SECRET_KEY + 'blah').encode('utf-8') + extra_hash = (settings.SECRET_KEY + "blah").encode("utf-8") x.update(extra_hash) return x.hexdigest() @@ -119,22 +96,12 @@ class Order(CreatedModifiedAbstract): class Payment(CreatedModifiedAbstract): - amount = MoneyField( - max_digits=16, - decimal_places=2, - ) + amount = MoneyField(max_digits=16, decimal_places=2) order = models.ForeignKey(Order, on_delete=models.PROTECT) - description = models.CharField( - max_length=1024, - verbose_name=_("description") - ) + description = models.CharField(max_length=1024, verbose_name=_("description")) - stripe_charge_id = models.CharField( - max_length=255, - null=True, - blank=True, - ) + stripe_charge_id = models.CharField(max_length=255, null=True, blank=True) @property def display_id(self): diff --git a/accounting/tests.py b/accounting/tests.py index b2e28e3..c847203 100644 --- a/accounting/tests.py +++ b/accounting/tests.py @@ -7,10 +7,9 @@ from . import models # def test(): # do stuff + @pytest.mark.django_db def test_balance(): user = User.objects.create_user("test", "lala@adas.com", "1234") - account = models.Account.objects.create( - owner=user - ) + account = models.Account.objects.create(owner=user) assert account.balance == 0 diff --git a/manage.py b/manage.py index 0b8fe53..548b6a5 100755 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") try: from django.core.management import execute_from_command_line - except ImportError as exc: + except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " diff --git a/membership/apps.py b/membership/apps.py index 537f521..d4f0399 100644 --- a/membership/apps.py +++ b/membership/apps.py @@ -2,4 +2,4 @@ from django.apps import AppConfig class MembershipConfig(AppConfig): - name = 'membership' + name = "membership" diff --git a/membership/migrations/0001_initial.py b/membership/migrations/0001_initial.py index 70b3ad8..2a32dcf 100644 --- a/membership/migrations/0001_initial.py +++ b/membership/migrations/0001_initial.py @@ -12,90 +12,216 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ] + dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)] operations = [ migrations.CreateModel( - name='Membership', + name="Membership", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), - ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), - ('can_vote', models.BooleanField(default=False, help_text='Indicates that the user has a democratic membership of the organization.', verbose_name='can vote')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "modified", + models.DateTimeField(auto_now=True, verbose_name="modified"), + ), + ( + "created", + models.DateTimeField(auto_now_add=True, verbose_name="created"), + ), + ( + "can_vote", + models.BooleanField( + default=False, + help_text="Indicates that the user has a democratic membership of the organization.", + verbose_name="can vote", + ), + ), ], options={ - 'verbose_name': 'membership', - 'verbose_name_plural': 'memberships', + "verbose_name": "membership", + "verbose_name_plural": "memberships", }, ), migrations.CreateModel( - name='Organization', + name="Organization", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), - ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), - ('name', models.CharField(max_length=64, verbose_name='name')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "modified", + models.DateTimeField(auto_now=True, verbose_name="modified"), + ), + ( + "created", + models.DateTimeField(auto_now_add=True, verbose_name="created"), + ), + ("name", models.CharField(max_length=64, verbose_name="name")), ], options={ - 'verbose_name': 'organization', - 'verbose_name_plural': 'organizations', + "verbose_name": "organization", + "verbose_name_plural": "organizations", }, ), migrations.CreateModel( - name='Subscription', + name="Subscription", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), - ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), - ('active', models.BooleanField(default=False, help_text='Automatically set by payment system.', verbose_name='active')), - ('starts', models.DateField()), - ('ends', models.DateField()), - ('renewed_subscription', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='membership.Subscription', verbose_name='renewed subscription')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "modified", + models.DateTimeField(auto_now=True, verbose_name="modified"), + ), + ( + "created", + models.DateTimeField(auto_now_add=True, verbose_name="created"), + ), + ( + "active", + models.BooleanField( + default=False, + help_text="Automatically set by payment system.", + verbose_name="active", + ), + ), + ("starts", models.DateField()), + ("ends", models.DateField()), + ( + "renewed_subscription", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="membership.Subscription", + verbose_name="renewed subscription", + ), + ), ], options={ - 'verbose_name': 'subscription', - 'verbose_name_plural': 'subscriptions', + "verbose_name": "subscription", + "verbose_name_plural": "subscriptions", }, ), migrations.CreateModel( - name='SubscriptionType', + name="SubscriptionType", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('modified', models.DateTimeField(auto_now=True, verbose_name='modified')), - ('created', models.DateTimeField(auto_now_add=True, verbose_name='created')), - ('name', models.CharField(max_length=64, verbose_name='name')), - ('fee_currency', djmoney.models.fields.CurrencyField(choices=[('DKK', 'DKK')], default='XYZ', editable=False, max_length=3)), - ('fee', djmoney.models.fields.MoneyField(decimal_places=2, default=Decimal('0.0'), max_digits=16)), - ('fee_vat_currency', djmoney.models.fields.CurrencyField(choices=[('DKK', 'DKK')], default='XYZ', editable=False, max_length=3)), - ('fee_vat', djmoney.models.fields.MoneyField(decimal_places=2, default=Decimal('0'), max_digits=16)), - ('duration', models.PositiveSmallIntegerField(choices=[(1, 'annual')], default=1, verbose_name='duration')), - ('organization', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='membership.Organization')), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "modified", + models.DateTimeField(auto_now=True, verbose_name="modified"), + ), + ( + "created", + models.DateTimeField(auto_now_add=True, verbose_name="created"), + ), + ("name", models.CharField(max_length=64, verbose_name="name")), + ( + "fee_currency", + djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], + default="XYZ", + editable=False, + max_length=3, + ), + ), + ( + "fee", + djmoney.models.fields.MoneyField( + decimal_places=2, default=Decimal("0.0"), max_digits=16 + ), + ), + ( + "fee_vat_currency", + djmoney.models.fields.CurrencyField( + choices=[("DKK", "DKK")], + default="XYZ", + editable=False, + max_length=3, + ), + ), + ( + "fee_vat", + djmoney.models.fields.MoneyField( + decimal_places=2, default=Decimal("0"), max_digits=16 + ), + ), + ( + "duration", + models.PositiveSmallIntegerField( + choices=[(1, "annual")], default=1, verbose_name="duration" + ), + ), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="membership.Organization", + ), + ), ], options={ - 'verbose_name': 'subscription type', - 'verbose_name_plural': 'subscription types', + "verbose_name": "subscription type", + "verbose_name_plural": "subscription types", }, ), migrations.AddField( - model_name='subscription', - name='subscription_type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='memberships', to='membership.SubscriptionType', verbose_name='subscription type'), + model_name="subscription", + name="subscription_type", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="memberships", + to="membership.SubscriptionType", + verbose_name="subscription type", + ), ), migrations.AddField( - model_name='subscription', - name='user', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), + model_name="subscription", + name="user", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL + ), ), migrations.AddField( - model_name='membership', - name='organization', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='membership.Organization'), + model_name="membership", + name="organization", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="membership.Organization", + ), ), migrations.AddField( - model_name='membership', - name='user', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), + model_name="membership", + name="user", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL + ), ), ] diff --git a/membership/models.py b/membership/models.py index aaca0de..ec70410 100644 --- a/membership/models.py +++ b/membership/models.py @@ -6,14 +6,8 @@ from djmoney.models.fields import MoneyField class CreatedModifiedAbstract(models.Model): - modified = models.DateTimeField( - auto_now=True, - verbose_name=_("modified"), - ) - created = models.DateTimeField( - auto_now_add=True, - verbose_name=_("created"), - ) + modified = models.DateTimeField(auto_now=True, verbose_name=_("modified")) + created = models.DateTimeField(auto_now_add=True, verbose_name=_("created")) class Meta: abstract = True @@ -24,10 +18,8 @@ class Organization(CreatedModifiedAbstract): This holds the data of the organization that someone is a member of. It is possible that we'll create more advanced features here. """ - name = models.CharField( - verbose_name=_("name"), - max_length=64, - ) + + name = models.CharField(verbose_name=_("name"), max_length=64) def __str__(self): return self.name @@ -56,14 +48,13 @@ class Membership(CreatedModifiedAbstract): help_text=_( "Indicates that the user has a democratic membership of the " "organization." - ) + ), ) def __str__(self): return _("{} is a member of {}").format( - self.user.get_full_name(), - self.organization.name, + self.user.get_full_name(), self.organization.name ) class Meta: @@ -79,26 +70,14 @@ class SubscriptionType(CreatedModifiedAbstract): organization = models.ForeignKey(Organization, on_delete=models.PROTECT) - name = models.CharField( - verbose_name=_("name"), - max_length=64, - ) + name = models.CharField(verbose_name=_("name"), max_length=64) - fee = MoneyField( - max_digits=16, - decimal_places=2, - ) + fee = MoneyField(max_digits=16, decimal_places=2) - fee_vat = MoneyField( - max_digits=16, - decimal_places=2, - default=0, - ) + fee_vat = MoneyField(max_digits=16, decimal_places=2, default=0) duration = models.PositiveSmallIntegerField( - default=1, - choices=[(1, _("annual"))], - verbose_name=_("duration"), + default=1, choices=[(1, _("annual"))], verbose_name=_("duration") ) class Meta: @@ -116,7 +95,7 @@ class Subscription(CreatedModifiedAbstract): subscription_type = models.ForeignKey( SubscriptionType, - related_name='memberships', + related_name="memberships", verbose_name=_("subscription type"), on_delete=models.PROTECT, ) @@ -125,14 +104,14 @@ class Subscription(CreatedModifiedAbstract): active = models.BooleanField( default=False, verbose_name=_("active"), - help_text=_("Automatically set by payment system.") + help_text=_("Automatically set by payment system."), ) starts = models.DateField() ends = models.DateField() renewed_subscription = models.ForeignKey( - 'self', + "self", null=True, blank=True, verbose_name=_("renewed subscription"), diff --git a/project/context_processors.py b/project/context_processors.py index c4873c2..7e80076 100644 --- a/project/context_processors.py +++ b/project/context_processors.py @@ -4,6 +4,4 @@ from django.contrib.sites.shortcuts import get_current_site def current_site(request): """Include the current site in the context.""" - return { - 'site': get_current_site(request) - } + return {"site": get_current_site(request)} diff --git a/project/settings/base.py b/project/settings/base.py index 513b05d..fcbda74 100644 --- a/project/settings/base.py +++ b/project/settings/base.py @@ -26,63 +26,62 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.sites', - - 'users', - 'accounting', - 'membership', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "django.contrib.sites", + "users", + "accounting", + "membership", ] MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'project.urls' +ROOT_URLCONF = "project.urls" TEMPLATES = [ { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join("project", "templates")], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - 'project.context_processors.current_site', - ], + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [os.path.join("project", "templates")], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + "project.context_processors.current_site", + ] }, - }, + } ] AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.ModelBackend', - 'allauth.account.auth_backends.AuthenticationBackend', + "django.contrib.auth.backends.ModelBackend", + "allauth.account.auth_backends.AuthenticationBackend", ) -WSGI_APPLICATION = 'project.wsgi.application' +WSGI_APPLICATION = "project.wsgi.application" # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": os.path.join(BASE_DIR, "db.sqlite3"), } } @@ -92,28 +91,24 @@ DATABASES = { AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" # noqa }, + {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, # noqa + {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"}, # noqa { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', # noqa - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', # noqa - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', # noqa + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator" # noqa }, ] -AUTH_USER_MODEL = 'users.User' +AUTH_USER_MODEL = "users.User" # Internationalization # https://docs.djangoproject.com/en/2.0/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = "en-us" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -125,13 +120,13 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.0/howto/static-files/ -STATIC_URL = '/static/' +STATIC_URL = "/static/" -STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] +STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")] SITE_ID = 1 -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" -CURRENCIES = ('DKK',) -CURRENCY_CHOICES = [('DKK', 'DKK')] +CURRENCIES = ("DKK",) +CURRENCY_CHOICES = [("DKK", "DKK")] diff --git a/project/urls.py b/project/urls.py index 41148c9..3e82ac1 100644 --- a/project/urls.py +++ b/project/urls.py @@ -6,7 +6,7 @@ from django.urls import path from . import views urlpatterns = [ - path('', views.index), + path("", views.index), path("users/", include("users.urls")), - path('admin/', admin.site.urls), + path("admin/", admin.site.urls), ] diff --git a/users/admin.py b/users/admin.py index 8c38f3f..a3c40c7 100644 --- a/users/admin.py +++ b/users/admin.py @@ -1,3 +1 @@ -from django.contrib import admin - -# Register your models here. +from django.contrib import admin # noqa diff --git a/users/apps.py b/users/apps.py index 4ce1fab..3ef1284 100644 --- a/users/apps.py +++ b/users/apps.py @@ -2,4 +2,4 @@ from django.apps import AppConfig class UsersConfig(AppConfig): - name = 'users' + name = "users" diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py index b9ab905..386b839 100644 --- a/users/migrations/0001_initial.py +++ b/users/migrations/0001_initial.py @@ -9,28 +9,65 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - ('auth', '0011_update_proxy_permissions'), - ] + dependencies = [("auth", "0011_update_proxy_permissions")] operations = [ migrations.CreateModel( - name='User', + name="User", 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')), - ('nick', models.CharField(blank=True, max_length=60, null=True)), - ('email', models.EmailField(help_text='Your email address will be used for password resets and notification about your event/submissions.', max_length=254, unique=True, verbose_name='E-Mail')), - ('is_active', models.BooleanField(default=True)), - ('is_staff', models.BooleanField(default=False)), - ('is_superuser', models.BooleanField(default=False)), - ('token_uuid', models.UUIDField(default=uuid.uuid4, editable=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')), + ( + "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" + ), + ), + ("nick", models.CharField(blank=True, max_length=60, null=True)), + ( + "email", + models.EmailField( + help_text="Your email address will be used for password resets and notification about your event/submissions.", + max_length=254, + unique=True, + verbose_name="E-Mail", + ), + ), + ("is_active", models.BooleanField(default=True)), + ("is_staff", models.BooleanField(default=False)), + ("is_superuser", models.BooleanField(default=False)), + ("token_uuid", models.UUIDField(default=uuid.uuid4, editable=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", + ), + ), ], - options={ - 'verbose_name': 'User', - }, - ), + options={"verbose_name": "User"}, + ) ] diff --git a/users/models.py b/users/models.py index 5c96291..6de0dcc 100644 --- a/users/models.py +++ b/users/models.py @@ -20,23 +20,23 @@ class UserManager(BaseUserManager): user = self.create_user(password=password, **kwargs) user.is_staff = True user.is_superuser = True - user.save(update_fields=['is_staff', 'is_superuser']) + user.save(update_fields=["is_staff", "is_superuser"]) return user class User(PermissionsMixin, AbstractBaseUser): - EMAIL_FIELD = 'email' - USERNAME_FIELD = 'email' + EMAIL_FIELD = "email" + USERNAME_FIELD = "email" objects = UserManager() nick = models.CharField(max_length=60, null=True, blank=True) email = models.EmailField( unique=True, - verbose_name=_('E-Mail'), + verbose_name=_("E-Mail"), help_text=_( - 'Your email address will be used for password resets and notification about your event/submissions.' + "Your email address will be used for password resets and notification about your event/submissions." ), ) @@ -54,7 +54,7 @@ class User(PermissionsMixin, AbstractBaseUser): return self.get_display_name() def get_display_name(self) -> str: - return self.nick if self.nick else str(_('Unnamed user')) + return self.nick if self.nick else str(_("Unnamed user")) class Meta: verbose_name = _("User") diff --git a/users/urls.py b/users/urls.py index 5651d02..009e547 100644 --- a/users/urls.py +++ b/users/urls.py @@ -3,20 +3,59 @@ from django.urls import path from . import views -app_name = 'users' +app_name = "users" urlpatterns = [ - path('signup/', views.SignupView.as_view(), name='signup'), - path('signup/confirm/', views.SignupConfirmView.as_view(), name='signup_confirm'), - - path('login/', auth_views.LoginView.as_view(template_name="users/login.html"), name='login'), - path('logout/', auth_views.LogoutView.as_view(template_name="users/logged_out.html"), name='logout'), - - path('password_change/', views.PasswordChangeView.as_view(template_name="users/password_change_form.html"), name='password_change'), - path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(template_name="users/password_change_done.html"), name='password_change_done'), - - path('password_reset/', views.PasswordResetView.as_view(template_name="users/password_reset_form.html"), name='password_reset'), - path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(template_name="users/password_reset_done.html"), name='password_reset_done'), - path('reset///', views.PasswordResetConfirmView.as_view(template_name="users/password_reset_confirm.html"), name='password_reset_confirm'), - path('reset/done/', auth_views.PasswordResetCompleteView.as_view(template_name="users/password_reset_complete.html"), name='password_reset_complete'), + path("signup/", views.SignupView.as_view(), name="signup"), + path("signup/confirm/", views.SignupConfirmView.as_view(), name="signup_confirm"), + path( + "login/", + auth_views.LoginView.as_view(template_name="users/login.html"), + name="login", + ), + path( + "logout/", + auth_views.LogoutView.as_view(template_name="users/logged_out.html"), + name="logout", + ), + path( + "password_change/", + views.PasswordChangeView.as_view( + template_name="users/password_change_form.html" + ), + name="password_change", + ), + path( + "password_change/done/", + auth_views.PasswordChangeDoneView.as_view( + template_name="users/password_change_done.html" + ), + name="password_change_done", + ), + path( + "password_reset/", + views.PasswordResetView.as_view(template_name="users/password_reset_form.html"), + name="password_reset", + ), + path( + "password_reset/done/", + auth_views.PasswordResetDoneView.as_view( + template_name="users/password_reset_done.html" + ), + name="password_reset_done", + ), + path( + "reset///", + views.PasswordResetConfirmView.as_view( + template_name="users/password_reset_confirm.html" + ), + name="password_reset_confirm", + ), + path( + "reset/done/", + auth_views.PasswordResetCompleteView.as_view( + template_name="users/password_reset_complete.html" + ), + name="password_reset_complete", + ), ] diff --git a/users/views.py b/users/views.py index 631f57e..30df8e5 100644 --- a/users/views.py +++ b/users/views.py @@ -6,20 +6,21 @@ from django.views.generic.base import TemplateView from django.views.generic.edit import FormView from . import forms + # from . import email class PasswordResetView(auth_views.PasswordResetView): - email_template_name = 'users/password_reset_email.html' - success_url = reverse_lazy('users:password_reset_done') + email_template_name = "users/password_reset_email.html" + success_url = reverse_lazy("users:password_reset_done") class PasswordResetConfirmView(auth_views.PasswordResetConfirmView): - success_url = reverse_lazy('users:password_reset_complete') + success_url = reverse_lazy("users:password_reset_complete") class PasswordChangeView(auth_views.PasswordChangeView): - success_url = reverse_lazy('users:password_change_done') + success_url = reverse_lazy("users:password_change_done") class SignupView(FormView): @@ -31,7 +32,7 @@ class SignupView(FormView): user = form.save(commit=False) user.is_active = False - user.set_password(form.cleaned_data['password1']) + user.set_password(form.cleaned_data["password1"]) user.save() # mail = email.UserConfirm(user=user) @@ -48,10 +49,9 @@ class SignupConfirmView(TemplateView): class SignupConfirmRedirectView(RedirectView): - def get_redirect_url(self): - uuid = self.kwargs['uuid'] + uuid = self.kwargs["uuid"] if self.kwargs["token"] == forms.get_confirm_code(uuid): redirect("users:confirmed") # TODO