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.
This commit is contained in:
Rishi Gupta 2016-10-27 21:58:59 -07:00 committed by Tim Abbott
parent b3c018f55c
commit c1bbd8d70d
1 changed files with 11 additions and 0 deletions

View File

@ -1142,6 +1142,17 @@ def get_realm(domain):
except Realm.DoesNotExist: except Realm.DoesNotExist:
return None 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(): def clear_database():
# type: () -> None # type: () -> None
pylibmc.Client(['127.0.0.1']).flush_all() pylibmc.Client(['127.0.0.1']).flush_all()