mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
zerver/lib: Change use of typing.Text to str.
This commit is contained in:
committed by
Tim Abbott
parent
2f3b2fbf59
commit
1f9244e060
@@ -3,14 +3,14 @@ from django.conf import settings
|
||||
if False:
|
||||
from zerver.models import UserProfile
|
||||
|
||||
from typing import Any, Dict, Optional, Text
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from zerver.lib.avatar_hash import gravatar_hash, user_avatar_path_from_ids
|
||||
from zerver.lib.upload import upload_backend, MEDIUM_AVATAR_SIZE
|
||||
from zerver.models import UserProfile
|
||||
import urllib
|
||||
|
||||
def avatar_url(user_profile: UserProfile, medium: bool=False, client_gravatar: bool=False) -> Text:
|
||||
def avatar_url(user_profile: UserProfile, medium: bool=False, client_gravatar: bool=False) -> str:
|
||||
|
||||
return get_avatar_field(
|
||||
user_id=user_profile.id,
|
||||
@@ -22,7 +22,7 @@ def avatar_url(user_profile: UserProfile, medium: bool=False, client_gravatar: b
|
||||
client_gravatar=client_gravatar,
|
||||
)
|
||||
|
||||
def avatar_url_from_dict(userdict: Dict[str, Any], medium: bool=False) -> Text:
|
||||
def avatar_url_from_dict(userdict: Dict[str, Any], medium: bool=False) -> str:
|
||||
'''
|
||||
DEPRECATED: We should start using
|
||||
get_avatar_field to populate users,
|
||||
@@ -41,11 +41,11 @@ def avatar_url_from_dict(userdict: Dict[str, Any], medium: bool=False) -> Text:
|
||||
|
||||
def get_avatar_field(user_id: int,
|
||||
realm_id: int,
|
||||
email: Text,
|
||||
avatar_source: Text,
|
||||
email: str,
|
||||
avatar_source: str,
|
||||
avatar_version: int,
|
||||
medium: bool,
|
||||
client_gravatar: bool) -> Optional[Text]:
|
||||
client_gravatar: bool) -> Optional[str]:
|
||||
'''
|
||||
Most of the parameters to this function map to fields
|
||||
by the same name in UserProfile (avatar_source, realm_id,
|
||||
@@ -88,12 +88,12 @@ def get_avatar_field(user_id: int,
|
||||
url += '&version=%d' % (avatar_version,)
|
||||
return url
|
||||
|
||||
def get_gravatar_url(email: Text, avatar_version: int, medium: bool=False) -> Text:
|
||||
def get_gravatar_url(email: str, avatar_version: int, medium: bool=False) -> str:
|
||||
url = _get_unversioned_gravatar_url(email, medium)
|
||||
url += '&version=%d' % (avatar_version,)
|
||||
return url
|
||||
|
||||
def _get_unversioned_gravatar_url(email: Text, medium: bool) -> Text:
|
||||
def _get_unversioned_gravatar_url(email: str, medium: bool) -> str:
|
||||
if settings.ENABLE_GRAVATAR:
|
||||
gravitar_query_suffix = "&s=%s" % (MEDIUM_AVATAR_SIZE,) if medium else ""
|
||||
hash_key = gravatar_hash(email)
|
||||
@@ -101,17 +101,17 @@ def _get_unversioned_gravatar_url(email: Text, medium: bool) -> Text:
|
||||
return settings.DEFAULT_AVATAR_URI+'?x=x'
|
||||
|
||||
def _get_unversioned_avatar_url(user_profile_id: int,
|
||||
avatar_source: Text,
|
||||
avatar_source: str,
|
||||
realm_id: int,
|
||||
email: Optional[Text]=None,
|
||||
medium: bool=False) -> Text:
|
||||
email: Optional[str]=None,
|
||||
medium: bool=False) -> str:
|
||||
if avatar_source == 'U':
|
||||
hash_key = user_avatar_path_from_ids(user_profile_id, realm_id)
|
||||
return upload_backend.get_avatar_url(hash_key, medium=medium)
|
||||
assert email is not None
|
||||
return _get_unversioned_gravatar_url(email, medium)
|
||||
|
||||
def absolute_avatar_url(user_profile: UserProfile) -> Text:
|
||||
def absolute_avatar_url(user_profile: UserProfile) -> str:
|
||||
"""Absolute URLs are used to simplify logic for applications that
|
||||
won't be served by browsers, such as rendering GCM notifications."""
|
||||
return urllib.parse.urljoin(user_profile.realm.uri, avatar_url(user_profile))
|
||||
|
||||
Reference in New Issue
Block a user