Supply a name when creating realms.

For our populate_db bulk creation, just use the domain.

(imported from commit 4fb756f6dfa2d8f90e55822e27891e84168d5d1c)
This commit is contained in:
Jessica McKellar
2013-10-17 11:47:30 -04:00
parent 5c5ffd6ea3
commit 6dbf7613a1
3 changed files with 20 additions and 7 deletions

View File

@@ -1108,11 +1108,12 @@ def do_rename_stream(realm, old_name, new_name, log=True):
# email forwarding address to display the correctly-escaped new name.
return {"email_address": encode_email_address(stream)}
def do_create_realm(domain, restricted_to_domain=True):
def do_create_realm(domain, name, restricted_to_domain=True):
realm = get_realm(domain)
created = not realm
if created:
realm = Realm(domain=domain, restricted_to_domain=restricted_to_domain)
realm = Realm(domain=domain, name=name,
restricted_to_domain=restricted_to_domain)
realm.save()
# Create stream once Realm object has been saved

View File

@@ -11,7 +11,7 @@ def bulk_create_realms(realm_list):
realms_to_create = []
for domain in realm_list:
if domain not in existing_realms:
realms_to_create.append(Realm(domain=domain))
realms_to_create.append(Realm(domain=domain, name=domain))
existing_realms.add(domain)
Realm.objects.bulk_create(realms_to_create)

View File

@@ -5,11 +5,12 @@ from django.core.management.base import BaseCommand
from zerver.lib.actions import do_create_realm
import re
import sys
class Command(BaseCommand):
help = """Create a realm for the specified domain.
Usage: python manage.py create_realm foo.com"""
Usage: python manage.py create_realm --domain=foo.com --name='Foo, Inc.'"""
option_list = BaseCommand.option_list + (
make_option('-o', '--open-realm',
@@ -17,6 +18,14 @@ Usage: python manage.py create_realm foo.com"""
action="store_true",
default=False,
help='Make this an open realm.'),
make_option('-d', '--domain',
dest='domain',
type='str',
help='The domain for the realm.'),
make_option('-n', '--name',
dest='name',
type='str',
help='The user-visible name for the realm.'),
)
def validate_domain(self, domain):
@@ -32,15 +41,18 @@ Usage: python manage.py create_realm foo.com"""
raise ValueError("Domains must contain a '.'")
def handle(self, *args, **options):
if not args:
if options["domain"] is None or options["name"] is None:
print >>sys.stderr, "\033[1;31mPlease provide both a domain and name.\033[0m\n"
self.print_help("python manage.py", "create_realm")
exit(1)
domain = args[0]
domain = options["domain"]
name = options["name"]
self.validate_domain(domain)
realm, created = do_create_realm(
domain, restricted_to_domain=not options["open_realm"])
domain, name, restricted_to_domain=not options["open_realm"])
if created:
print domain, "created."
else: