-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #187
- Loading branch information
Showing
14 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ deploy: | |
|
||
graph: | ||
./manage.py graph_models \ | ||
accounts \ | ||
core \ | ||
courses \ | ||
schools \ | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Account | ||
|
||
|
||
@admin.register(Account) | ||
class AccountAdmin(admin.ModelAdmin): | ||
list_display = ("id", "user", "status") | ||
list_filter = ("status",) | ||
raw_id_fields = ("user",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AccountsConfig(AppConfig): | ||
name = "accounts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 3.1.2 on 2020-11-03 04:46 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Account", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"status", | ||
models.IntegerField( | ||
choices=[ | ||
(1, "Exempt"), | ||
(2, "Beta"), | ||
(3, "Trialing"), | ||
(4, "Active"), | ||
(5, "Past Due"), | ||
(6, "Canceled"), | ||
], | ||
db_index=True, | ||
default=2, | ||
), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="+", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
) | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django.conf import settings | ||
from django.db import models | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
from homeschool.users.models import User | ||
|
||
|
||
class Account(models.Model): | ||
"""A record to track the status of the account.""" | ||
|
||
class AccountStatus(models.IntegerChoices): | ||
EXEMPT = 1 # For special accounts that require no subscription | ||
BETA = 2 # For beta users | ||
TRIALING = 3 | ||
ACTIVE = 4 | ||
PAST_DUE = 5 | ||
CANCELED = 6 | ||
|
||
user = models.ForeignKey( | ||
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="+" | ||
) | ||
status = models.IntegerField( | ||
choices=AccountStatus.choices, default=AccountStatus.BETA, db_index=True | ||
) | ||
|
||
|
||
@receiver(post_save, sender=User) | ||
def create_account(sender, instance, created, **kwargs): | ||
"""A new user gets an associated account.""" | ||
if created: | ||
Account.objects.create(user=instance) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import factory | ||
|
||
|
||
class AccountFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = "accounts.Account" | ||
|
||
user = factory.SubFactory("homeschool.users.tests.factories.UserFactory") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from homeschool.accounts.models import Account | ||
from homeschool.accounts.tests.factories import AccountFactory | ||
from homeschool.test import TestCase | ||
|
||
|
||
class TestAccount(TestCase): | ||
def test_factory(self): | ||
account = AccountFactory() | ||
|
||
assert account.user is not None | ||
assert account.status == Account.AccountStatus.BETA |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 3.1.2 on 2020-11-03 04:18 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("core", "0001_initial")] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="flag", | ||
name="everyone", | ||
field=models.BooleanField( | ||
blank=True, | ||
help_text=( | ||
"Flip this flag on (Yes) or off (No) for everyone, overriding all" | ||
" other settings. Leave as Unknown to use normally." | ||
), | ||
null=True, | ||
verbose_name="Everyone", | ||
), | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters