55 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# Generated by Django 3.1 on 2020-08-28 13:14
 | 
						|
from django.apps.registry import Apps
 | 
						|
from django.db import migrations, models
 | 
						|
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
 | 
						|
 | 
						|
 | 
						|
def add_title_for_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
 | 
						|
    slug_title_map = {
 | 
						|
        "default-authentication-flow": "Welcome to passbook!",
 | 
						|
        "default-invalidation-flow": "Default Invalidation Flow",
 | 
						|
        "default-source-enrollment": "Welcome to passbook!",
 | 
						|
        "default-source-authentication": "Welcome to passbook!",
 | 
						|
        "default-provider-authorization-implicit-consent": "Default Provider Authorization Flow (implicit consent)",
 | 
						|
        "default-provider-authorization-explicit-consent": "Default Provider Authorization Flow (explicit consent)",
 | 
						|
        "default-password-change": "Change password",
 | 
						|
    }
 | 
						|
    db_alias = schema_editor.connection.alias
 | 
						|
    Flow = apps.get_model("passbook_flows", "Flow")
 | 
						|
    for flow in Flow.objects.using(db_alias).all():
 | 
						|
        if flow.slug in slug_title_map:
 | 
						|
            flow.title = slug_title_map[flow.slug]
 | 
						|
        else:
 | 
						|
            flow.title = flow.name
 | 
						|
        flow.save()
 | 
						|
 | 
						|
 | 
						|
class Migration(migrations.Migration):
 | 
						|
 | 
						|
    dependencies = [
 | 
						|
        ("passbook_flows", "0010_provider_flows"),
 | 
						|
    ]
 | 
						|
 | 
						|
    operations = [
 | 
						|
        migrations.AlterModelOptions(
 | 
						|
            name="flow",
 | 
						|
            options={
 | 
						|
                "permissions": [("export_flow", "Can export a Flow")],
 | 
						|
                "verbose_name": "Flow",
 | 
						|
                "verbose_name_plural": "Flows",
 | 
						|
            },
 | 
						|
        ),
 | 
						|
        migrations.AddField(
 | 
						|
            model_name="flow",
 | 
						|
            name="title",
 | 
						|
            field=models.TextField(default="", blank=True),
 | 
						|
            preserve_default=False,
 | 
						|
        ),
 | 
						|
        migrations.RunPython(add_title_for_defaults),
 | 
						|
        migrations.AlterField(
 | 
						|
            model_name="flow",
 | 
						|
            name="title",
 | 
						|
            field=models.TextField(),
 | 
						|
        ),
 | 
						|
    ]
 |