mirror of https://github.com/zulip/zulip.git
parent
f443fcea48
commit
0e192d6aff
|
@ -86,6 +86,14 @@ import copy
|
||||||
# works on both str and unicode in python 2 but in python 3 it only works on str.
|
# works on both str and unicode in python 2 but in python 3 it only works on str.
|
||||||
SizedTextIterable = Union[Sequence[text_type], AbstractSet[text_type]]
|
SizedTextIterable = Union[Sequence[text_type], AbstractSet[text_type]]
|
||||||
|
|
||||||
|
STREAM_ASSIGNMENT_COLORS = [
|
||||||
|
"#76ce90", "#fae589", "#a6c7e5", "#e79ab5",
|
||||||
|
"#bfd56f", "#f4ae55", "#b0a5fd", "#addfe5",
|
||||||
|
"#f5ce6e", "#c2726a", "#94c849", "#bd86e5",
|
||||||
|
"#ee7e4a", "#a6dcbf", "#95a5fd", "#53a063",
|
||||||
|
"#9987e1", "#e4523d", "#c2c2c2", "#4f8de4",
|
||||||
|
"#c6a8ad", "#e7cc4d", "#c8bebf", "#a47462"]
|
||||||
|
|
||||||
# Store an event in the log for re-importing messages
|
# Store an event in the log for re-importing messages
|
||||||
def log_event(event):
|
def log_event(event):
|
||||||
# type: (MutableMapping[str, Any]) -> None
|
# type: (MutableMapping[str, Any]) -> None
|
||||||
|
@ -1100,20 +1108,13 @@ def pick_color(user_profile):
|
||||||
def pick_color_helper(user_profile, subs):
|
def pick_color_helper(user_profile, subs):
|
||||||
# type: (UserProfile, Iterable[Subscription]) -> text_type
|
# type: (UserProfile, Iterable[Subscription]) -> text_type
|
||||||
# These colors are shared with the palette in subs.js.
|
# These colors are shared with the palette in subs.js.
|
||||||
stream_assignment_colors = [
|
|
||||||
"#76ce90", "#fae589", "#a6c7e5", "#e79ab5",
|
|
||||||
"#bfd56f", "#f4ae55", "#b0a5fd", "#addfe5",
|
|
||||||
"#f5ce6e", "#c2726a", "#94c849", "#bd86e5",
|
|
||||||
"#ee7e4a", "#a6dcbf", "#95a5fd", "#53a063",
|
|
||||||
"#9987e1", "#e4523d", "#c2c2c2", "#4f8de4",
|
|
||||||
"#c6a8ad", "#e7cc4d", "#c8bebf", "#a47462"]
|
|
||||||
used_colors = [sub.color for sub in subs if sub.active]
|
used_colors = [sub.color for sub in subs if sub.active]
|
||||||
available_colors = [s for s in stream_assignment_colors if s not in used_colors]
|
available_colors = [s for s in STREAM_ASSIGNMENT_COLORS if s not in used_colors]
|
||||||
|
|
||||||
if available_colors:
|
if available_colors:
|
||||||
return available_colors[0]
|
return available_colors[0]
|
||||||
else:
|
else:
|
||||||
return stream_assignment_colors[len(used_colors) % len(stream_assignment_colors)]
|
return STREAM_ASSIGNMENT_COLORS[len(used_colors) % len(STREAM_ASSIGNMENT_COLORS)]
|
||||||
|
|
||||||
def get_subscription(stream_name, user_profile):
|
def get_subscription(stream_name, user_profile):
|
||||||
# type: (text_type, UserProfile) -> Subscription
|
# type: (text_type, UserProfile) -> Subscription
|
||||||
|
|
|
@ -10,7 +10,7 @@ from zerver.models import Message, UserProfile, Stream, Recipient, Client, \
|
||||||
Subscription, Huddle, get_huddle, Realm, UserMessage, \
|
Subscription, Huddle, get_huddle, Realm, UserMessage, \
|
||||||
get_huddle_hash, clear_database, get_client, get_user_profile_by_id, \
|
get_huddle_hash, clear_database, get_client, get_user_profile_by_id, \
|
||||||
split_email_to_domain, email_to_username
|
split_email_to_domain, email_to_username
|
||||||
from zerver.lib.actions import do_send_message, set_default_streams, \
|
from zerver.lib.actions import STREAM_ASSIGNMENT_COLORS, do_send_message, set_default_streams, \
|
||||||
do_activate_user, do_deactivate_user, do_change_password, do_change_is_admin,\
|
do_activate_user, do_deactivate_user, do_change_password, do_change_is_admin,\
|
||||||
do_change_bot_type
|
do_change_bot_type
|
||||||
from zerver.lib.parallel import run_parallel
|
from zerver.lib.parallel import run_parallel
|
||||||
|
@ -142,9 +142,10 @@ class Command(BaseCommand):
|
||||||
do_change_is_admin(iago, True)
|
do_change_is_admin(iago, True)
|
||||||
# Create public streams.
|
# Create public streams.
|
||||||
stream_list = ["Verona", "Denmark", "Scotland", "Venice", "Rome"]
|
stream_list = ["Verona", "Denmark", "Scotland", "Venice", "Rome"]
|
||||||
create_streams(realms, zulip_realm, stream_list)
|
|
||||||
recipient_streams = [Stream.objects.get(name=name, realm=zulip_realm).id for name in stream_list] # type: List[int]
|
|
||||||
|
|
||||||
|
create_streams(realms, zulip_realm, stream_list)
|
||||||
|
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
|
# Create subscriptions to streams. The following
|
||||||
# algorithm will give each of the users a different but
|
# algorithm will give each of the users a different but
|
||||||
# deterministic subset of the streams (given a fixed list
|
# deterministic subset of the streams (given a fixed list
|
||||||
|
@ -156,7 +157,11 @@ class Command(BaseCommand):
|
||||||
for type_id in recipient_streams[:int(len(recipient_streams) *
|
for type_id in recipient_streams[:int(len(recipient_streams) *
|
||||||
float(i)/len(profiles)) + 1]:
|
float(i)/len(profiles)) + 1]:
|
||||||
r = Recipient.objects.get(type=Recipient.STREAM, type_id=type_id)
|
r = Recipient.objects.get(type=Recipient.STREAM, type_id=type_id)
|
||||||
s = Subscription(recipient=r, user_profile=profile)
|
s = Subscription(
|
||||||
|
recipient=r,
|
||||||
|
user_profile=profile,
|
||||||
|
color=STREAM_ASSIGNMENT_COLORS[i % len(STREAM_ASSIGNMENT_COLORS)])
|
||||||
|
|
||||||
subscriptions_to_add.append(s)
|
subscriptions_to_add.append(s)
|
||||||
Subscription.objects.bulk_create(subscriptions_to_add)
|
Subscription.objects.bulk_create(subscriptions_to_add)
|
||||||
else:
|
else:
|
||||||
|
@ -231,7 +236,7 @@ class Command(BaseCommand):
|
||||||
# when running populate_db for the test suite
|
# when running populate_db for the test suite
|
||||||
|
|
||||||
zulip_stream_list = ["devel", "all", "announce", "design", "support", "social", "test",
|
zulip_stream_list = ["devel", "all", "announce", "design", "support", "social", "test",
|
||||||
"errors", "sales"]
|
"errors", "sales"]
|
||||||
create_streams(realms, zulip_realm, zulip_stream_list)
|
create_streams(realms, zulip_realm, zulip_stream_list)
|
||||||
|
|
||||||
# Add a few default streams
|
# Add a few default streams
|
||||||
|
@ -241,12 +246,15 @@ class Command(BaseCommand):
|
||||||
# Now subscribe everyone to these streams
|
# Now subscribe everyone to these streams
|
||||||
subscriptions_to_add = []
|
subscriptions_to_add = []
|
||||||
profiles = UserProfile.objects.select_related().filter(realm=zulip_realm)
|
profiles = UserProfile.objects.select_related().filter(realm=zulip_realm)
|
||||||
for cls in zulip_stream_list:
|
for i, stream_name in enumerate(zulip_stream_list):
|
||||||
stream = Stream.objects.get(name=cls, realm=zulip_realm)
|
stream = Stream.objects.get(name=stream_name, realm=zulip_realm)
|
||||||
recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
|
recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
|
||||||
for profile in profiles:
|
for profile in profiles:
|
||||||
# Subscribe to some streams.
|
# Subscribe to some streams.
|
||||||
s = Subscription(recipient=recipient, user_profile=profile)
|
s = Subscription(
|
||||||
|
recipient=recipient,
|
||||||
|
user_profile=profile,
|
||||||
|
color=STREAM_ASSIGNMENT_COLORS[i % len(STREAM_ASSIGNMENT_COLORS)])
|
||||||
subscriptions_to_add.append(s)
|
subscriptions_to_add.append(s)
|
||||||
Subscription.objects.bulk_create(subscriptions_to_add)
|
Subscription.objects.bulk_create(subscriptions_to_add)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue