rename_stream.py: Fix broken code.

* get_realm returns None if no matching realm is present, but
  create_stream.py assumed it raises Realm.DoesNotExist.
* encoded/decode strings properly.
This commit is contained in:
Eklavya Sharma 2016-07-05 07:50:18 +05:30 committed by Tim Abbott
parent c679c180f5
commit 6fd8906358
2 changed files with 5 additions and 6 deletions

View File

@ -41,7 +41,6 @@ exclude_py2 = []
exclude_py3 = """
zerver/lib/ccache.py
zerver/management/commands/rename_stream.py
zerver/management/commands/runtornado.py
zerver/tests/test_i18n.py
zerver/views/messages.py

View File

@ -7,6 +7,7 @@ from argparse import ArgumentParser
from django.core.management.base import BaseCommand
from zerver.lib.actions import do_rename_stream
from zerver.lib.str_utils import force_text
from zerver.models import Realm, get_realm
import sys
@ -30,11 +31,10 @@ class Command(BaseCommand):
new_name = options['new_name']
encoding = sys.getfilesystemencoding()
try:
realm = get_realm(domain)
except Realm.DoesNotExist:
realm = get_realm(force_text(domain, encoding))
if realm is None:
print("Unknown domain %s" % (domain,))
exit(1)
do_rename_stream(realm, old_name.decode(encoding),
new_name.decode(encoding))
do_rename_stream(realm, force_text(old_name, encoding),
force_text(new_name, encoding))