diff --git a/hc/accounts/migrations/0019_project_badge_key.py b/hc/accounts/migrations/0019_project_badge_key.py new file mode 100644 index 00000000..645918f6 --- /dev/null +++ b/hc/accounts/migrations/0019_project_badge_key.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.5 on 2019-01-12 19:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0018_auto_20190112_1426'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='badge_key', + field=models.CharField(blank=True, max_length=150, null=True), + ), + ] diff --git a/hc/accounts/migrations/0020_auto_20190112_1950.py b/hc/accounts/migrations/0020_auto_20190112_1950.py new file mode 100644 index 00000000..6e6ebe3f --- /dev/null +++ b/hc/accounts/migrations/0020_auto_20190112_1950.py @@ -0,0 +1,21 @@ +# Generated by Django 2.1.5 on 2019-01-12 19:50 + +from django.db import migrations + + +def set_badge_key(apps, schema_editor): + Project = apps.get_model("accounts", "Project") + for project in Project.objects.select_related("owner").all(): + project.badge_key = project.owner.username + project.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0019_project_badge_key'), + ] + + operations = [ + migrations.RunPython(set_badge_key, migrations.RunPython.noop), + ] diff --git a/hc/accounts/models.py b/hc/accounts/models.py index 3ead56a2..52c34323 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -240,6 +240,7 @@ class Project(models.Model): owner = models.ForeignKey(User, models.CASCADE) api_key = models.CharField(max_length=128, blank=True) api_key_readonly = models.CharField(max_length=128, blank=True) + badge_key = models.CharField(max_length=150, blank=True, null=True) class Member(models.Model): diff --git a/hc/accounts/tests/test_signup.py b/hc/accounts/tests/test_signup.py index aa2150b4..fbca78a0 100644 --- a/hc/accounts/tests/test_signup.py +++ b/hc/accounts/tests/test_signup.py @@ -26,6 +26,7 @@ class SignupTestCase(TestCase): # A project should have been created project = Project.objects.get() self.assertEqual(project.owner, user) + self.assertEqual(project.badge_key, user.username) # And check should be associated with the new user check = Check.objects.get() diff --git a/hc/accounts/views.py b/hc/accounts/views.py index c571ca31..4b68a59b 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -50,6 +50,7 @@ def _make_user(email): user.save() project = Project(owner=user) + project.badge_key = user.username project.save() # Ensure a profile gets created