Files
zulip/zerver/migrations/0206_stream_rendered_description.py
Anders Kaseorg 7a34e9a3fd black: Reformat with Black 23.
Black 23 enforces some slightly more specific rules about empty line
counts and redundant parenthesis removal, but the result is still
compatible with Black 22.

(This does not actually upgrade our Python environment to Black 23
yet.)

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit df001db1a9)
2023-04-05 16:07:58 -07:00

34 lines
1.1 KiB
Python

from django.db import migrations, models
from django.db.backends.postgresql.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
def render_all_stream_descriptions(
apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
# FIXME: Application code should not be imported from migrations.
from zerver.lib.streams import render_stream_description
Stream = apps.get_model("zerver", "Stream")
all_streams = Stream.objects.exclude(description="")
for stream in all_streams:
stream.rendered_description = render_stream_description(stream.description, stream.realm)
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, reverse_code=migrations.RunPython.noop, elidable=True
),
]