mirror of https://github.com/zulip/zulip.git
management: Use self.get_realm in set_default_streams.
This commit is contained in:
parent
3bc475d04f
commit
9fb5381acb
|
@ -4,15 +4,12 @@ from __future__ import print_function
|
|||
from argparse import ArgumentParser, RawTextHelpFormatter
|
||||
from typing import Any, Dict, Text
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
|
||||
from zerver.models import get_realm
|
||||
from zerver.lib.actions import set_default_streams
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
|
||||
from optparse import make_option
|
||||
import sys
|
||||
|
||||
class Command(BaseCommand):
|
||||
class Command(ZulipBaseCommand):
|
||||
help = """Set default streams for a realm
|
||||
|
||||
Users created under this realm will start out with these streams. This
|
||||
|
@ -36,27 +33,24 @@ For example:
|
|||
|
||||
def add_arguments(self, parser):
|
||||
# type: (ArgumentParser) -> None
|
||||
parser.add_argument('-r', '--realm',
|
||||
dest='string_id',
|
||||
type=str,
|
||||
help='The subdomain or string_id of the existing realm to which to '
|
||||
'attach default streams.')
|
||||
|
||||
parser.add_argument('-s', '--streams',
|
||||
dest='streams',
|
||||
type=str,
|
||||
help='A comma-separated list of stream names.')
|
||||
self.add_realm_args(parser, True)
|
||||
|
||||
def handle(self, **options):
|
||||
# type: (**str) -> None
|
||||
if options["string_id"] is None or options["streams"] is None:
|
||||
print("Please provide both a subdomain name or string_id and a default \
|
||||
set of streams (which can be empty, with `--streams=`).", file=sys.stderr)
|
||||
realm = self.get_realm(options)
|
||||
if options["streams"] is None:
|
||||
print("Please provide a default set of streams (which can be empty,\
|
||||
with `--streams=`).", file=sys.stderr)
|
||||
exit(1)
|
||||
realm = self.get_realm(options)
|
||||
|
||||
stream_dict = {
|
||||
stream.strip(): {"description": stream.strip(), "invite_only": False}
|
||||
for stream in options["streams"].split(",")
|
||||
} # type: Dict[Text, Dict[Text, Any]]
|
||||
realm = get_realm(options["string_id"])
|
||||
|
||||
set_default_streams(realm, stream_dict)
|
||||
|
|
Loading…
Reference in New Issue