mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
streams: Add default stream description population data.
This commit is contained in:
@@ -66,14 +66,20 @@ def bulk_create_users(realms, users_raw, bot_type=None, tos_version=None):
|
||||
recipient=recipients_by_email[email]))
|
||||
Subscription.objects.bulk_create(subscriptions_to_create)
|
||||
|
||||
def bulk_create_streams(realms, stream_list):
|
||||
# type: (Mapping[text_type, Realm], Iterable[Tuple[text_type, text_type]]) -> None
|
||||
def bulk_create_streams(realms, stream_dict):
|
||||
# type: (Mapping[text_type, Realm], Dict[text_type, Dict[text_type, Any]]) -> None
|
||||
existing_streams = set((stream.realm.domain, stream.name.lower())
|
||||
for stream in Stream.objects.select_related().all())
|
||||
streams_to_create = [] # type: List[Stream]
|
||||
for (domain, name) in stream_list:
|
||||
if (domain, name.lower()) not in existing_streams:
|
||||
streams_to_create.append(Stream(realm=realms[domain], name=name))
|
||||
for name, options in stream_dict.items():
|
||||
if (options["domain"], name.lower()) not in existing_streams:
|
||||
streams_to_create.append(
|
||||
Stream(
|
||||
realm=realms[options["domain"]],
|
||||
name=name, description=options["description"],
|
||||
invite_only=options["invite_only"]
|
||||
)
|
||||
)
|
||||
Stream.objects.bulk_create(streams_to_create)
|
||||
|
||||
recipients_to_create = [] # type: List[Recipient]
|
||||
|
||||
@@ -33,12 +33,17 @@ def create_users(realms, name_list, bot_type=None):
|
||||
tos_version = settings.TOS_VERSION if bot_type is None else None
|
||||
bulk_create_users(realms, user_set, bot_type=bot_type, tos_version=tos_version)
|
||||
|
||||
def create_streams(realms, realm, stream_list):
|
||||
# type: (Mapping[Text, Realm], Realm, Iterable[Text]) -> None
|
||||
stream_set = set() # type: Set[Tuple[Text, Text]]
|
||||
for stream_name in stream_list:
|
||||
stream_set.add((realm.domain, stream_name))
|
||||
bulk_create_streams(realms, stream_set)
|
||||
def create_streams(realms, realm, stream_dict):
|
||||
# type: (Mapping[Text, Realm], Realm, Dict[Text, Dict[Text, Any]]) -> None
|
||||
stream_dictionary = {
|
||||
name: {
|
||||
"domain": realm.domain,
|
||||
"description": options["description"],
|
||||
"invite_only": options["invite_only"],
|
||||
} for name, options in stream_dict.items()
|
||||
} # type: Dict[Text, Dict[Text, Any]]
|
||||
|
||||
bulk_create_streams(realms, stream_dictionary)
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Populate a test database"
|
||||
@@ -148,8 +153,15 @@ class Command(BaseCommand):
|
||||
do_change_is_admin(iago, True)
|
||||
# Create public streams.
|
||||
stream_list = ["Verona", "Denmark", "Scotland", "Venice", "Rome"]
|
||||
stream_dict = {
|
||||
"Verona": {"description": "A city in Italy", "invite_only": False},
|
||||
"Denmark": {"description": "A Scandinavian country", "invite_only": False},
|
||||
"Scotland": {"description": "Located in the United Kingdom", "invite_only": False},
|
||||
"Venice": {"description": "A northeastern Italian city", "invite_only": False},
|
||||
"Rome": {"description": "Yet another Italian city", "invite_only": False}
|
||||
} # type: Dict[Text, Dict[Text, Any]]
|
||||
|
||||
create_streams(realms, zulip_realm, stream_list)
|
||||
create_streams(realms, zulip_realm, stream_dict)
|
||||
recipient_streams = [Stream.objects.get(name=name, realm=zulip_realm).id
|
||||
for name in stream_list] # type: List[int]
|
||||
# Create subscriptions to streams. The following
|
||||
@@ -241,18 +253,28 @@ class Command(BaseCommand):
|
||||
# suite fast, don't add these users and subscriptions
|
||||
# when running populate_db for the test suite
|
||||
|
||||
zulip_stream_list = ["devel", "all", "announce", "design", "support", "social", "test",
|
||||
"errors", "sales"]
|
||||
create_streams(realms, zulip_realm, zulip_stream_list)
|
||||
zulip_stream_dict = {
|
||||
"devel": {"description": "For developing", "invite_only": False},
|
||||
"all": {"description": "For everything", "invite_only": False},
|
||||
"announce": {"description": "For announcements", "invite_only": False},
|
||||
"design": {"description": "For design", "invite_only": False},
|
||||
"support": {"description": "For support", "invite_only": False},
|
||||
"social": {"description": "For socializing", "invite_only": False},
|
||||
"test": {"description": "For testing", "invite_only": False},
|
||||
"errors": {"description": "For errors", "invite_only": False},
|
||||
"sales": {"description": "For sales discussion", "invite_only": False}
|
||||
} # type: Dict[Text, Dict[Text, Any]]
|
||||
create_streams(realms, zulip_realm, zulip_stream_dict)
|
||||
|
||||
# Add a few default streams
|
||||
for stream_name in ["design", "devel", "social", "support"]:
|
||||
DefaultStream.objects.create(realm=zulip_realm, stream=get_stream(stream_name, zulip_realm))
|
||||
for default_stream_name in ["design", "devel", "social", "support"]:
|
||||
DefaultStream.objects.create(realm=zulip_realm,
|
||||
stream=get_stream(default_stream_name, zulip_realm))
|
||||
|
||||
# Now subscribe everyone to these streams
|
||||
subscriptions_to_add = []
|
||||
profiles = UserProfile.objects.select_related().filter(realm=zulip_realm)
|
||||
for i, stream_name in enumerate(zulip_stream_list):
|
||||
for i, stream_name in enumerate(zulip_stream_dict):
|
||||
stream = Stream.objects.get(name=stream_name, realm=zulip_realm)
|
||||
recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
|
||||
for profile in profiles:
|
||||
|
||||
Reference in New Issue
Block a user