2019-01-11 13:48:22 +01:00
|
|
|
from django.db import migrations, models
|
2020-04-27 07:19:08 +02:00
|
|
|
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
|
2020-01-14 21:59:46 +01:00
|
|
|
from django.db.migrations.state import StateApps
|
2019-01-11 13:48:22 +01:00
|
|
|
|
2019-03-01 09:10:40 +01:00
|
|
|
from zerver.lib.actions import render_stream_description
|
2019-01-11 13:48:22 +01:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2019-01-11 13:48:22 +01:00
|
|
|
def render_all_stream_descriptions(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
|
|
|
|
Stream = apps.get_model('zerver', 'Stream')
|
|
|
|
all_streams = Stream.objects.exclude(description='')
|
|
|
|
for stream in all_streams:
|
2019-03-01 09:10:40 +01:00
|
|
|
stream.rendered_description = render_stream_description(stream.description)
|
2019-01-11 13:48:22 +01:00
|
|
|
stream.save(update_fields=["rendered_description"])
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('zerver', '0205_remove_realmauditlog_requires_billing_update'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AddField(
|
|
|
|
model_name='stream',
|
|
|
|
name='rendered_description',
|
|
|
|
field=models.TextField(default=''),
|
|
|
|
),
|
|
|
|
migrations.RunPython(render_all_stream_descriptions,
|
2020-04-29 08:43:25 +02:00
|
|
|
reverse_code=migrations.RunPython.noop,
|
|
|
|
elidable=True),
|
2019-01-11 13:48:22 +01:00
|
|
|
]
|