Files
zulip/zerver/migrations/0224_alter_field_realm_video_chat_provider.py
Anders Kaseorg 69730a78cc python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:

import re
import sys

last_filename = None
last_row = None
lines = []

for msg in sys.stdin:
    m = re.match(
        r"\x1b\[35mflake8    \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
    )
    if m:
        filename, row_str, col_str, err = m.groups()
        row, col = int(row_str), int(col_str)

        if filename == last_filename:
            assert last_row != row
        else:
            if last_filename is not None:
                with open(last_filename, "w") as f:
                    f.writelines(lines)

            with open(filename) as f:
                lines = f.readlines()
            last_filename = filename
        last_row = row

        line = lines[row - 1]
        if err in ["C812", "C815"]:
            lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
        elif err in ["C819"]:
            assert line[col - 2] == ","
            lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")

if last_filename is not None:
    with open(last_filename, "w") as f:
        f.writelines(lines)

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-06-11 16:04:12 -07:00

79 lines
2.6 KiB
Python

# Generated by Django 1.11.20 on 2019-05-09 06:54
from typing import Any, Dict, Optional
from django.db import migrations, models
from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
# We include a copy of this structure as it was at the time this
# migration was merged, since future should not impact the migration.
VIDEO_CHAT_PROVIDERS = {
'jitsi_meet': {
'name': "Jitsi",
'id': 1,
},
'google_hangouts': {
'name': "Google Hangouts",
'id': 2,
},
'zoom': {
'name': "Zoom",
'id': 3,
},
}
def get_video_chat_provider_detail(providers_dict: Dict[str, Dict[str, Any]],
p_name: Optional[str]=None, p_id: Optional[int]=None,
) -> Dict[str, Any]:
for provider in providers_dict.values():
if (p_name and provider['name'] == p_name):
return provider
if (p_id and provider['id'] == p_id):
return provider
return dict()
def update_existing_video_chat_provider_values(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
Realm = apps.get_model('zerver', 'Realm')
for realm in Realm.objects.all():
realm.video_chat_provider = get_video_chat_provider_detail(
VIDEO_CHAT_PROVIDERS,
p_name=realm.video_chat_provider_old)['id']
realm.save(update_fields=["video_chat_provider"])
def reverse_code(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
for realm in Realm.objects.all():
realm.video_chat_provider_old = get_video_chat_provider_detail(
VIDEO_CHAT_PROVIDERS,
p_id=realm.video_chat_provider)['name']
realm.save(update_fields=["video_chat_provider_old"])
class Migration(migrations.Migration):
atomic = False
dependencies = [
('zerver', '0223_rename_to_is_muted'),
]
operations = [
migrations.RenameField(
model_name='realm',
old_name='video_chat_provider',
new_name='video_chat_provider_old',
),
migrations.AddField(
model_name='realm',
name='video_chat_provider',
field=models.PositiveSmallIntegerField(default=VIDEO_CHAT_PROVIDERS['jitsi_meet']['id']),
),
migrations.RunPython(update_existing_video_chat_provider_values,
reverse_code=reverse_code,
elidable=True),
migrations.RemoveField(
model_name='realm',
name='video_chat_provider_old',
),
]