Add Project.badge_key so we can preserve the current badge URLs

This commit is contained in:
Pēteris Caune 2019-01-12 21:56:56 +02:00
parent 6b7f212c8a
commit d102f10a2d
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
5 changed files with 42 additions and 0 deletions

View File

@ -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),
),
]

View File

@ -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),
]

View File

@ -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):

View File

@ -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()

View File

@ -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