2013-10-10 21:37:26 +02:00
|
|
|
from __future__ import absolute_import
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2013-10-10 21:37:26 +02:00
|
|
|
|
2012-11-27 18:26:51 +01:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
2015-10-13 22:54:35 +02:00
|
|
|
from zerver.models import get_realm
|
2013-11-22 22:09:47 +01:00
|
|
|
from zerver.lib.actions import set_default_streams
|
2012-11-27 18:26:51 +01:00
|
|
|
|
|
|
|
from optparse import make_option
|
|
|
|
import sys
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Set default streams for a realm
|
|
|
|
|
|
|
|
Users created under this realm will start out with these streams. This
|
|
|
|
command is not additive: if you re-run it on a domain with a different
|
|
|
|
set of default streams, those will be the new complete set of default
|
|
|
|
streams.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
2015-10-04 18:56:26 +02:00
|
|
|
python2.7 manage.py set_default_streams --domain=foo.com --streams=foo,bar,baz
|
|
|
|
python2.7 manage.py set_default_streams --domain=foo.com --streams="foo,bar,baz with space"
|
|
|
|
python2.7 manage.py set_default_streams --domain=foo.com --streams=
|
2012-11-27 18:26:51 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
option_list = BaseCommand.option_list + (
|
|
|
|
make_option('-d', '--domain',
|
|
|
|
dest='domain',
|
|
|
|
type='str',
|
|
|
|
help='The name of the existing realm to which to attach default streams.'),
|
|
|
|
make_option('-s', '--streams',
|
|
|
|
dest='streams',
|
|
|
|
type='str',
|
|
|
|
help='A comma-separated list of stream names.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def handle(self, **options):
|
|
|
|
if options["domain"] is None or options["streams"] is None:
|
2015-11-01 17:11:06 +01:00
|
|
|
print("Please provide both a domain name and a default \
|
|
|
|
set of streams (which can be empty, with `--streams=`).", file=sys.stderr)
|
2012-11-27 18:26:51 +01:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
stream_names = [stream.strip() for stream in options["streams"].split(",")]
|
2015-10-13 22:54:35 +02:00
|
|
|
realm = get_realm(options["domain"])
|
2012-11-27 18:26:51 +01:00
|
|
|
set_default_streams(realm, stream_names)
|