mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	In commit de65a04 we can see that if the need ever arises to modify
how stream descriptions are rendered, we would need to make changes
at 5 different call points which can be quite cumbersome. So this
functionality has been extracted to a new method called
'render_stream_descriptions'.
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# -*- coding: utf-8 -*-
 | 
						|
from __future__ import unicode_literals
 | 
						|
 | 
						|
from django.db import migrations, models
 | 
						|
 | 
						|
from django.db.migrations.state import StateApps
 | 
						|
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
 | 
						|
 | 
						|
from zerver.lib.actions import render_stream_description
 | 
						|
 | 
						|
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:
 | 
						|
        stream.rendered_description = render_stream_description(stream.description)
 | 
						|
        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),
 | 
						|
    ]
 |