2013-10-19 15:28:59 +02:00
|
|
|
from __future__ import absolute_import
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2013-10-19 15:28:59 +02:00
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2013-10-19 15:28:59 +02:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
|
|
from zerver.lib.actions import do_create_stream
|
|
|
|
from zerver.models import Realm, get_realm
|
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from argparse import ArgumentParser
|
2013-10-19 15:28:59 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Create a stream, and subscribe all active users (excluding bots).
|
|
|
|
|
|
|
|
This should be used for TESTING only, unless you understand the limitations of
|
2015-08-21 02:10:41 +02:00
|
|
|
the command."""
|
2013-10-19 15:28:59 +02:00
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
def add_arguments(self, parser):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (ArgumentParser) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
parser.add_argument('domain', metavar='<domain>', type=str,
|
|
|
|
help='domain in which to create the stream')
|
|
|
|
parser.add_argument('stream_name', metavar='<stream name>', type=str,
|
|
|
|
help='name of stream to create')
|
2013-10-19 15:28:59 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **str) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
domain = options['domain']
|
|
|
|
stream_name = options['stream_name']
|
2013-10-19 15:28:59 +02:00
|
|
|
encoding = sys.getfilesystemencoding()
|
|
|
|
|
|
|
|
try:
|
|
|
|
realm = get_realm(domain)
|
|
|
|
except Realm.DoesNotExist:
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Unknown domain %s" % (domain,))
|
2013-10-19 15:28:59 +02:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
do_create_stream(realm, stream_name.decode(encoding))
|