management: Add library for getting a client object.

This is to be used in some analytics features we're adding in the near
future.
This commit is contained in:
Tim Abbott
2018-03-13 16:25:31 -07:00
parent e9f4d9db2b
commit 54d558b128
2 changed files with 8 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ from django.core.exceptions import MultipleObjectsReturned
from django.core.management.base import BaseCommand, CommandError
from typing import Any, Dict, Optional, List
from zerver.models import Realm, UserProfile
from zerver.models import Realm, UserProfile, Client, get_client
def is_integer_string(val: str) -> bool:
try:
@@ -120,3 +120,7 @@ You can use the command list_realms to find ID of the realms in this server."""
"to specify which one to modify.")
except UserProfile.DoesNotExist:
raise CommandError("This Zulip server does not contain a user with email '%s'" % (email,))
def get_client(self) -> Client:
"""Returns a Zulip Client object to be used for things done in management commands"""
return get_client("ZulipServer")