mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 02:48:00 +00:00
exports: Rename parent_key to include_rows.
Even though Django usually treats foo__in and foo_id__in identically for filters where foo is a ForeignKey type, we want to insist on somewhat more consistent syntax, because we have the odd combo of type and type_id in Recipient, where type_id is kinda like a foreign key, but not a ForeignKey. So we assert for now that all our include_rows values end in "_id__in".
This commit is contained in:
@@ -433,7 +433,7 @@ class Config:
|
|||||||
concat_and_destroy: Optional[List[TableName]] = None,
|
concat_and_destroy: Optional[List[TableName]] = None,
|
||||||
id_source: Optional[IdSource] = None,
|
id_source: Optional[IdSource] = None,
|
||||||
source_filter: Optional[SourceFilter] = None,
|
source_filter: Optional[SourceFilter] = None,
|
||||||
parent_key: Optional[Field] = None,
|
include_rows: Optional[Field] = None,
|
||||||
use_all: bool = False,
|
use_all: bool = False,
|
||||||
is_seeded: bool = False,
|
is_seeded: bool = False,
|
||||||
exclude: Optional[List[Field]] = None,
|
exclude: Optional[List[Field]] = None,
|
||||||
@@ -444,7 +444,7 @@ class Config:
|
|||||||
self.normal_parent = normal_parent
|
self.normal_parent = normal_parent
|
||||||
self.virtual_parent = virtual_parent
|
self.virtual_parent = virtual_parent
|
||||||
self.filter_args = filter_args
|
self.filter_args = filter_args
|
||||||
self.parent_key = parent_key
|
self.include_rows = include_rows
|
||||||
self.use_all = use_all
|
self.use_all = use_all
|
||||||
self.is_seeded = is_seeded
|
self.is_seeded = is_seeded
|
||||||
self.exclude = exclude
|
self.exclude = exclude
|
||||||
@@ -455,6 +455,9 @@ class Config:
|
|||||||
self.source_filter = source_filter
|
self.source_filter = source_filter
|
||||||
self.children: List[Config] = []
|
self.children: List[Config] = []
|
||||||
|
|
||||||
|
if self.include_rows:
|
||||||
|
assert self.include_rows.endswith("_id__in")
|
||||||
|
|
||||||
if normal_parent is not None:
|
if normal_parent is not None:
|
||||||
self.parent: Optional[Config] = normal_parent
|
self.parent: Optional[Config] = normal_parent
|
||||||
else:
|
else:
|
||||||
@@ -566,9 +569,9 @@ def export_from_config(
|
|||||||
model = config.model
|
model = config.model
|
||||||
assert parent is not None
|
assert parent is not None
|
||||||
assert parent.table is not None
|
assert parent.table is not None
|
||||||
assert config.parent_key is not None
|
assert config.include_rows is not None
|
||||||
parent_ids = [r["id"] for r in response[parent.table]]
|
parent_ids = [r["id"] for r in response[parent.table]]
|
||||||
filter_parms: Dict[str, Any] = {config.parent_key: parent_ids}
|
filter_parms: Dict[str, Any] = {config.include_rows: parent_ids}
|
||||||
if config.filter_args is not None:
|
if config.filter_args is not None:
|
||||||
filter_parms.update(config.filter_args)
|
filter_parms.update(config.filter_args)
|
||||||
assert model is not None
|
assert model is not None
|
||||||
@@ -642,42 +645,42 @@ def get_realm_config() -> Config:
|
|||||||
table="zerver_defaultstream",
|
table="zerver_defaultstream",
|
||||||
model=DefaultStream,
|
model=DefaultStream,
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_customprofilefield",
|
table="zerver_customprofilefield",
|
||||||
model=CustomProfileField,
|
model=CustomProfileField,
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_realmemoji",
|
table="zerver_realmemoji",
|
||||||
model=RealmEmoji,
|
model=RealmEmoji,
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_realmdomain",
|
table="zerver_realmdomain",
|
||||||
model=RealmDomain,
|
model=RealmDomain,
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_realmfilter",
|
table="zerver_realmfilter",
|
||||||
model=RealmFilter,
|
model=RealmFilter,
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_realmplayground",
|
table="zerver_realmplayground",
|
||||||
model=RealmPlayground,
|
model=RealmPlayground,
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
@@ -691,7 +694,7 @@ def get_realm_config() -> Config:
|
|||||||
table="zerver_realmuserdefault",
|
table="zerver_realmuserdefault",
|
||||||
model=RealmUserDefault,
|
model=RealmUserDefault,
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
user_profile_config = Config(
|
user_profile_config = Config(
|
||||||
@@ -709,21 +712,21 @@ def get_realm_config() -> Config:
|
|||||||
table="zerver_usergroup",
|
table="zerver_usergroup",
|
||||||
model=UserGroup,
|
model=UserGroup,
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_usergroupmembership",
|
table="zerver_usergroupmembership",
|
||||||
model=UserGroupMembership,
|
model=UserGroupMembership,
|
||||||
normal_parent=user_groups_config,
|
normal_parent=user_groups_config,
|
||||||
parent_key="user_group__in",
|
include_rows="user_group_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_groupgroupmembership",
|
table="zerver_groupgroupmembership",
|
||||||
model=GroupGroupMembership,
|
model=GroupGroupMembership,
|
||||||
normal_parent=user_groups_config,
|
normal_parent=user_groups_config,
|
||||||
parent_key="supergroup__in",
|
include_rows="supergroup_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
@@ -738,21 +741,21 @@ def get_realm_config() -> Config:
|
|||||||
table="zerver_service",
|
table="zerver_service",
|
||||||
model=Service,
|
model=Service,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_botstoragedata",
|
table="zerver_botstoragedata",
|
||||||
model=BotStorageData,
|
model=BotStorageData,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="bot_profile__in",
|
include_rows="bot_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_botconfigdata",
|
table="zerver_botconfigdata",
|
||||||
model=BotConfigData,
|
model=BotConfigData,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="bot_profile__in",
|
include_rows="bot_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Some of these tables are intermediate "tables" that we
|
# Some of these tables are intermediate "tables" that we
|
||||||
@@ -763,7 +766,7 @@ def get_realm_config() -> Config:
|
|||||||
model=Subscription,
|
model=Subscription,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
filter_args={"recipient__type": Recipient.PERSONAL},
|
filter_args={"recipient__type": Recipient.PERSONAL},
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
@@ -780,14 +783,14 @@ def get_realm_config() -> Config:
|
|||||||
model=Stream,
|
model=Stream,
|
||||||
exclude=["email_token"],
|
exclude=["email_token"],
|
||||||
normal_parent=realm_config,
|
normal_parent=realm_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
stream_recipient_config = Config(
|
stream_recipient_config = Config(
|
||||||
table="_stream_recipient",
|
table="_stream_recipient",
|
||||||
model=Recipient,
|
model=Recipient,
|
||||||
normal_parent=stream_config,
|
normal_parent=stream_config,
|
||||||
parent_key="type_id__in",
|
include_rows="type_id__in",
|
||||||
filter_args={"type": Recipient.STREAM},
|
filter_args={"type": Recipient.STREAM},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -795,7 +798,7 @@ def get_realm_config() -> Config:
|
|||||||
table="_stream_subscription",
|
table="_stream_subscription",
|
||||||
model=Subscription,
|
model=Subscription,
|
||||||
normal_parent=stream_recipient_config,
|
normal_parent=stream_recipient_config,
|
||||||
parent_key="recipient_id__in",
|
include_rows="recipient_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -855,70 +858,70 @@ def add_user_profile_child_configs(user_profile_config: Config) -> None:
|
|||||||
table="zerver_alertword",
|
table="zerver_alertword",
|
||||||
model=AlertWord,
|
model=AlertWord,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_customprofilefieldvalue",
|
table="zerver_customprofilefieldvalue",
|
||||||
model=CustomProfileFieldValue,
|
model=CustomProfileFieldValue,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_muteduser",
|
table="zerver_muteduser",
|
||||||
model=MutedUser,
|
model=MutedUser,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_realmauditlog",
|
table="zerver_realmauditlog",
|
||||||
model=RealmAuditLog,
|
model=RealmAuditLog,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="modified_user__in",
|
include_rows="modified_user_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_useractivity",
|
table="zerver_useractivity",
|
||||||
model=UserActivity,
|
model=UserActivity,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile_id__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_useractivityinterval",
|
table="zerver_useractivityinterval",
|
||||||
model=UserActivityInterval,
|
model=UserActivityInterval,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile_id__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_userhotspot",
|
table="zerver_userhotspot",
|
||||||
model=UserHotspot,
|
model=UserHotspot,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user__in",
|
include_rows="user_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_userpresence",
|
table="zerver_userpresence",
|
||||||
model=UserPresence,
|
model=UserPresence,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_userstatus",
|
table="zerver_userstatus",
|
||||||
model=UserStatus,
|
model=UserStatus,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="zerver_usertopic",
|
table="zerver_usertopic",
|
||||||
model=UserTopic,
|
model=UserTopic,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1915,7 +1918,7 @@ def get_single_user_config() -> Config:
|
|||||||
table="zerver_subscription",
|
table="zerver_subscription",
|
||||||
model=Subscription,
|
model=Subscription,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user_profile__in",
|
include_rows="user_profile_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
# zerver_recipient
|
# zerver_recipient
|
||||||
@@ -1950,7 +1953,7 @@ def get_single_user_config() -> Config:
|
|||||||
table="analytics_usercount",
|
table="analytics_usercount",
|
||||||
model=UserCount,
|
model=UserCount,
|
||||||
normal_parent=user_profile_config,
|
normal_parent=user_profile_config,
|
||||||
parent_key="user__in",
|
include_rows="user_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
add_user_profile_child_configs(user_profile_config)
|
add_user_profile_child_configs(user_profile_config)
|
||||||
@@ -2030,21 +2033,21 @@ def get_analytics_config() -> Config:
|
|||||||
table="analytics_realmcount",
|
table="analytics_realmcount",
|
||||||
model=RealmCount,
|
model=RealmCount,
|
||||||
normal_parent=analytics_config,
|
normal_parent=analytics_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="analytics_usercount",
|
table="analytics_usercount",
|
||||||
model=UserCount,
|
model=UserCount,
|
||||||
normal_parent=analytics_config,
|
normal_parent=analytics_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
Config(
|
Config(
|
||||||
table="analytics_streamcount",
|
table="analytics_streamcount",
|
||||||
model=StreamCount,
|
model=StreamCount,
|
||||||
normal_parent=analytics_config,
|
normal_parent=analytics_config,
|
||||||
parent_key="realm_id__in",
|
include_rows="realm_id__in",
|
||||||
)
|
)
|
||||||
|
|
||||||
return analytics_config
|
return analytics_config
|
||||||
|
|||||||
Reference in New Issue
Block a user