mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
pep8: Add compliance with rule E261 to bulk_create.py.
This commit is contained in:
committed by
Tim Abbott
parent
c23901c3a8
commit
1e61e734c8
@@ -16,7 +16,7 @@ def bulk_create_users(realm, users_raw, bot_type=None, tos_version=None, timezon
|
||||
users = sorted([user_raw for user_raw in users_raw if user_raw[0] not in existing_users])
|
||||
|
||||
# Now create user_profiles
|
||||
profiles_to_create = [] # type: List[UserProfile]
|
||||
profiles_to_create = [] # type: List[UserProfile]
|
||||
for (email, full_name, short_name, active) in users:
|
||||
profile = create_user_profile(realm, email,
|
||||
initial_password(email), active, bot_type,
|
||||
@@ -31,23 +31,23 @@ def bulk_create_users(realm, users_raw, bot_type=None, tos_version=None, timezon
|
||||
event_type='user_created', event_time=profile_.date_joined)
|
||||
for profile_ in profiles_to_create])
|
||||
|
||||
profiles_by_email = {} # type: Dict[Text, UserProfile]
|
||||
profiles_by_id = {} # type: Dict[int, UserProfile]
|
||||
profiles_by_email = {} # type: Dict[Text, UserProfile]
|
||||
profiles_by_id = {} # type: Dict[int, UserProfile]
|
||||
for profile in UserProfile.objects.select_related().all():
|
||||
profiles_by_email[profile.email] = profile
|
||||
profiles_by_id[profile.id] = profile
|
||||
|
||||
recipients_to_create = [] # type: List[Recipient]
|
||||
recipients_to_create = [] # type: List[Recipient]
|
||||
for (email, full_name, short_name, active) in users:
|
||||
recipients_to_create.append(Recipient(type_id=profiles_by_email[email].id,
|
||||
type=Recipient.PERSONAL))
|
||||
Recipient.objects.bulk_create(recipients_to_create)
|
||||
|
||||
recipients_by_email = {} # type: Dict[Text, Recipient]
|
||||
recipients_by_email = {} # type: Dict[Text, Recipient]
|
||||
for recipient in Recipient.objects.filter(type=Recipient.PERSONAL):
|
||||
recipients_by_email[profiles_by_id[recipient.type_id].email] = recipient
|
||||
|
||||
subscriptions_to_create = [] # type: List[Subscription]
|
||||
subscriptions_to_create = [] # type: List[Subscription]
|
||||
for (email, full_name, short_name, active) in users:
|
||||
subscriptions_to_create.append(
|
||||
Subscription(user_profile_id=profiles_by_email[email].id,
|
||||
@@ -59,7 +59,7 @@ def bulk_create_streams(realm, stream_dict):
|
||||
existing_streams = frozenset([name.lower() for name in
|
||||
Stream.objects.filter(realm=realm)
|
||||
.values_list('name', flat=True)])
|
||||
streams_to_create = [] # type: List[Stream]
|
||||
streams_to_create = [] # type: List[Stream]
|
||||
for name, options in stream_dict.items():
|
||||
if name.lower() not in existing_streams:
|
||||
streams_to_create.append(
|
||||
@@ -70,7 +70,7 @@ def bulk_create_streams(realm, stream_dict):
|
||||
)
|
||||
Stream.objects.bulk_create(streams_to_create)
|
||||
|
||||
recipients_to_create = [] # type: List[Recipient]
|
||||
recipients_to_create = [] # type: List[Recipient]
|
||||
for stream in Stream.objects.filter(realm=realm).values('id', 'name'):
|
||||
if stream['name'].lower() not in existing_streams:
|
||||
recipients_to_create.append(Recipient(type_id=stream['id'],
|
||||
@@ -79,9 +79,9 @@ def bulk_create_streams(realm, stream_dict):
|
||||
|
||||
def bulk_create_clients(client_list):
|
||||
# type: (Iterable[Text]) -> None
|
||||
existing_clients = set(client.name for client in Client.objects.select_related().all()) # type: Set[Text]
|
||||
existing_clients = set(client.name for client in Client.objects.select_related().all()) # type: Set[Text]
|
||||
|
||||
clients_to_create = [] # type: List[Client]
|
||||
clients_to_create = [] # type: List[Client]
|
||||
for name in client_list:
|
||||
if name not in existing_clients:
|
||||
clients_to_create.append(Client(name=name))
|
||||
@@ -90,20 +90,20 @@ def bulk_create_clients(client_list):
|
||||
|
||||
def bulk_create_huddles(users, huddle_user_list):
|
||||
# type: (Dict[Text, UserProfile], Iterable[Iterable[Text]]) -> None
|
||||
huddles = {} # type: Dict[Text, Huddle]
|
||||
huddles_by_id = {} # type: Dict[int, Huddle]
|
||||
huddle_set = set() # type: Set[Tuple[Text, Tuple[int, ...]]]
|
||||
existing_huddles = set() # type: Set[Text]
|
||||
huddles = {} # type: Dict[Text, Huddle]
|
||||
huddles_by_id = {} # type: Dict[int, Huddle]
|
||||
huddle_set = set() # type: Set[Tuple[Text, Tuple[int, ...]]]
|
||||
existing_huddles = set() # type: Set[Text]
|
||||
for huddle in Huddle.objects.all():
|
||||
existing_huddles.add(huddle.huddle_hash)
|
||||
for huddle_users in huddle_user_list:
|
||||
user_ids = [users[email].id for email in huddle_users] # type: List[int]
|
||||
user_ids = [users[email].id for email in huddle_users] # type: List[int]
|
||||
huddle_hash = get_huddle_hash(user_ids)
|
||||
if huddle_hash in existing_huddles:
|
||||
continue
|
||||
huddle_set.add((huddle_hash, tuple(sorted(user_ids))))
|
||||
|
||||
huddles_to_create = [] # type: List[Huddle]
|
||||
huddles_to_create = [] # type: List[Huddle]
|
||||
for (huddle_hash, _) in huddle_set:
|
||||
huddles_to_create.append(Huddle(huddle_hash=huddle_hash))
|
||||
Huddle.objects.bulk_create(huddles_to_create)
|
||||
@@ -112,16 +112,16 @@ def bulk_create_huddles(users, huddle_user_list):
|
||||
huddles[huddle.huddle_hash] = huddle
|
||||
huddles_by_id[huddle.id] = huddle
|
||||
|
||||
recipients_to_create = [] # type: List[Recipient]
|
||||
recipients_to_create = [] # type: List[Recipient]
|
||||
for (huddle_hash, _) in huddle_set:
|
||||
recipients_to_create.append(Recipient(type_id=huddles[huddle_hash].id, type=Recipient.HUDDLE))
|
||||
Recipient.objects.bulk_create(recipients_to_create)
|
||||
|
||||
huddle_recipients = {} # type: Dict[Text, Recipient]
|
||||
huddle_recipients = {} # type: Dict[Text, Recipient]
|
||||
for recipient in Recipient.objects.filter(type=Recipient.HUDDLE):
|
||||
huddle_recipients[huddles_by_id[recipient.type_id].huddle_hash] = recipient
|
||||
|
||||
subscriptions_to_create = [] # type: List[Subscription]
|
||||
subscriptions_to_create = [] # type: List[Subscription]
|
||||
for (huddle_hash, huddle_user_ids) in huddle_set:
|
||||
for user_id in huddle_user_ids:
|
||||
subscriptions_to_create.append(Subscription(active=True, user_profile_id=user_id,
|
||||
|
||||
Reference in New Issue
Block a user