Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

types: Create a new TypedDict RealmPlaygroundDict for playground objects.

Sahil Batra6f93f07844f3
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 93108d7599b..2e8ea230a3a 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -182,6 +182,7 @@ from zerver.lib.types import (
ProfileFieldData,
RawStreamDict,
RawSubscriptionDict,
+ RealmPlaygroundDict,
SubscriptionInfo,
SubscriptionStreamDict,
UnspecifiedValue,
@@ -8097,9 +8098,7 @@ def do_remove_realm_domain(
transaction.on_commit(lambda: send_event(realm, event, active_user_ids(realm.id)))
-def notify_realm_playgrounds(
- realm: Realm, realm_playgrounds: List[Dict[str, Union[int, str]]]
-) -> None:
+def notify_realm_playgrounds(realm: Realm, realm_playgrounds: List[RealmPlaygroundDict]) -> None:
event = dict(type="realm_playgrounds", realm_playgrounds=realm_playgrounds)
transaction.on_commit(lambda: send_event(realm, event, active_user_ids(realm.id)))
@@ -8123,12 +8122,12 @@ def do_add_realm_playground(
extra_data=orjson.dumps(
{
"realm_playgrounds": realm_playgrounds,
- "added_playground": {
- "id": realm_playground.id,
- "name": realm_playground.name,
- "pygments_language": realm_playground.pygments_language,
- "url_prefix": realm_playground.url_prefix,
- },
+ "added_playground": RealmPlaygroundDict(
+ id=realm_playground.id,
+ name=realm_playground.name,
+ pygments_language=realm_playground.pygments_language,
+ url_prefix=realm_playground.url_prefix,
+ ),
}
).decode(),
)
diff --git a/zerver/lib/types.py b/zerver/lib/types.py
index 43db3cb4a64..66544dcdcef 100644
--- a/zerver/lib/types.py
+++ b/zerver/lib/types.py
@@ -227,3 +227,10 @@ class SubscriptionInfo:
subscriptions: List[SubscriptionStreamDict]
unsubscribed: List[SubscriptionStreamDict]
never_subscribed: List[NeverSubscribedStreamDict]
+
+
+class RealmPlaygroundDict(TypedDict):
+ id: int
+ name: str
+ pygments_language: str
+ url_prefix: str
diff --git a/zerver/models.py b/zerver/models.py
index 1d1527da5c7..2201048e9d9 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -86,6 +86,7 @@ from zerver.lib.types import (
ProfileData,
ProfileDataElementBase,
ProfileDataElementValue,
+ RealmPlaygroundDict,
RealmUserValidator,
UnspecifiedValue,
UserFieldElement,
@@ -1381,11 +1382,11 @@ class RealmPlayground(models.Model):
return f"<RealmPlayground({self.realm.string_id}): {self.pygments_language} {self.name}>"
-def get_realm_playgrounds(realm: Realm) -> List[Dict[str, Union[int, str]]]:
- playgrounds: List[Dict[str, Union[int, str]]] = []
+def get_realm_playgrounds(realm: Realm) -> List[RealmPlaygroundDict]:
+ playgrounds: List[RealmPlaygroundDict] = []
for playground in RealmPlayground.objects.filter(realm=realm).all():
playgrounds.append(
- dict(
+ RealmPlaygroundDict(
id=playground.id,
name=playground.name,
pygments_language=playground.pygments_language,
diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py
index d9b98b90844..85404db0ebb 100644
--- a/zerver/tests/test_audit_log.py
+++ b/zerver/tests/test_audit_log.py
@@ -44,6 +44,7 @@ from zerver.lib.message import get_last_message_id
from zerver.lib.stream_traffic import get_streams_traffic
from zerver.lib.streams import create_stream_if_needed
from zerver.lib.test_classes import ZulipTestCase
+from zerver.lib.types import RealmPlaygroundDict
from zerver.models import (
Message,
Realm,
@@ -745,12 +746,12 @@ class TestRealmAuditLog(ZulipTestCase):
pygments_language="Python",
url_prefix="https://python.example.com",
)
- added_playground: Dict[str, Union[int, str]] = {
- "id": playground_id,
- "name": "Python playground",
- "pygments_language": "Python",
- "url_prefix": "https://python.example.com",
- }
+ added_playground = RealmPlaygroundDict(
+ id=playground_id,
+ name="Python playground",
+ pygments_language="Python",
+ url_prefix="https://python.example.com",
+ )
expected_extra_data = {
"realm_playgrounds": intial_playgrounds + [added_playground],
"added_playground": added_playground,