From c1bbd8d70dd4aee1ca68d52de0b64dcff0c92961 Mon Sep 17 00:00:00 2001 From: Rishi Gupta Date: Thu, 27 Oct 2016 21:58:59 -0700 Subject: [PATCH] models.py: Add get_realm_by_string_id to assist with Realm.domain migration. Step 0 of a two step process: 1. Replace all occurances of get_realm(domain) with get_realm_by_string_id(string_id) 2. Rename get_realm_by_string_id to get_realm. --- zerver/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zerver/models.py b/zerver/models.py index a5c6ff0f67..4485bc922e 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -1142,6 +1142,17 @@ def get_realm(domain): except Realm.DoesNotExist: return None +# Added to assist with the domain to string_id transition. Will eventually +# be renamed and replace get_realm. +def get_realm_by_string_id(string_id): + # type: (text_type) -> Optional[Realm] + if not string_id: + return None + try: + return Realm.objects.get(string_id=string_id) + except Realm.DoesNotExist: + return None + def clear_database(): # type: () -> None pylibmc.Client(['127.0.0.1']).flush_all()