mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
mypy: Use Python 3 type syntax in zerver/views.
This commit is contained in:
@@ -22,17 +22,19 @@ def _default_narrow(user_profile: UserProfile,
|
|||||||
narrow = [['stream', default_stream.name]]
|
narrow = [['stream', default_stream.name]]
|
||||||
return narrow
|
return narrow
|
||||||
|
|
||||||
|
NarrowT = Iterable[Sequence[Text]]
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def events_register_backend(request, user_profile,
|
def events_register_backend(
|
||||||
apply_markdown=REQ(default=False, validator=check_bool),
|
request: HttpRequest, user_profile: UserProfile,
|
||||||
client_gravatar=REQ(default=False, validator=check_bool),
|
apply_markdown: bool=REQ(default=False, validator=check_bool),
|
||||||
all_public_streams=REQ(default=None, validator=check_bool),
|
client_gravatar: bool=REQ(default=False, validator=check_bool),
|
||||||
include_subscribers=REQ(default=False, validator=check_bool),
|
all_public_streams: Optional[bool]=REQ(default=None, validator=check_bool),
|
||||||
event_types=REQ(validator=check_list(check_string), default=None),
|
include_subscribers: bool=REQ(default=False, validator=check_bool),
|
||||||
fetch_event_types=REQ(validator=check_list(check_string), default=None),
|
event_types: Optional[Iterable[str]]=REQ(validator=check_list(check_string), default=None),
|
||||||
narrow=REQ(validator=check_list(check_list(check_string, length=2)), default=[]),
|
fetch_event_types: Optional[Iterable[str]]=REQ(validator=check_list(check_string), default=None),
|
||||||
queue_lifespan_secs=REQ(converter=int, default=0)):
|
narrow: NarrowT=REQ(validator=check_list(check_list(check_string, length=2)), default=[]),
|
||||||
# type: (HttpRequest, UserProfile, bool, bool, Optional[bool], bool, Optional[Iterable[str]], Optional[Iterable[str]], Iterable[Sequence[Text]], int) -> HttpResponse
|
queue_lifespan_secs: int=REQ(converter=int, default=0)
|
||||||
|
) -> HttpResponse:
|
||||||
all_public_streams = _default_all_public_streams(user_profile, all_public_streams)
|
all_public_streams = _default_all_public_streams(user_profile, all_public_streams)
|
||||||
narrow = _default_narrow(user_profile, narrow)
|
narrow = _default_narrow(user_profile, narrow)
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,8 @@ def unmute_topic(user_profile: UserProfile, stream_name: str,
|
|||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def update_muted_topic(request, user_profile, stream=REQ(),
|
def update_muted_topic(request: HttpRequest, user_profile: UserProfile, stream: str=REQ(),
|
||||||
topic=REQ(), op=REQ()):
|
topic: str=REQ(), op: str=REQ()) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, str, str, str) -> HttpResponse
|
|
||||||
|
|
||||||
if op == 'add':
|
if op == 'add':
|
||||||
return mute_topic(user_profile, stream, topic)
|
return mute_topic(user_profile, stream, topic)
|
||||||
|
|||||||
@@ -49,10 +49,11 @@ def get_presence_backend(request: HttpRequest, user_profile: UserProfile,
|
|||||||
|
|
||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def update_active_status_backend(request, user_profile, status=REQ(),
|
def update_active_status_backend(request: HttpRequest, user_profile: UserProfile,
|
||||||
ping_only=REQ(validator=check_bool, default=False),
|
status: str=REQ(),
|
||||||
new_user_input=REQ(validator=check_bool, default=False)):
|
ping_only: bool=REQ(validator=check_bool, default=False),
|
||||||
# type: (HttpRequest, UserProfile, str, bool, bool) -> HttpResponse
|
new_user_input: bool=REQ(validator=check_bool, default=False)
|
||||||
|
) -> HttpResponse:
|
||||||
status_val = UserPresence.status_from_string(status)
|
status_val = UserPresence.status_from_string(status)
|
||||||
if status_val is None:
|
if status_val is None:
|
||||||
raise JsonableError(_("Invalid status: %s") % (status,))
|
raise JsonableError(_("Invalid status: %s") % (status,))
|
||||||
|
|||||||
@@ -64,11 +64,10 @@ def report_send_times(request: HttpRequest, user_profile: UserProfile,
|
|||||||
|
|
||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def report_narrow_times(request, user_profile,
|
def report_narrow_times(request: HttpRequest, user_profile: UserProfile,
|
||||||
initial_core=REQ(converter=to_non_negative_int),
|
initial_core: int=REQ(converter=to_non_negative_int),
|
||||||
initial_free=REQ(converter=to_non_negative_int),
|
initial_free: int=REQ(converter=to_non_negative_int),
|
||||||
network=REQ(converter=to_non_negative_int)):
|
network: int=REQ(converter=to_non_negative_int)) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, int, int, int) -> HttpResponse
|
|
||||||
request._log_data["extra"] = "[%sms/%sms/%sms]" % (initial_core, initial_free, network)
|
request._log_data["extra"] = "[%sms/%sms/%sms]" % (initial_core, initial_free, network)
|
||||||
base_key = statsd_key(user_profile.realm.string_id, clean_periods=True)
|
base_key = statsd_key(user_profile.realm.string_id, clean_periods=True)
|
||||||
statsd.timing("narrow.initial_core.%s" % (base_key,), initial_core)
|
statsd.timing("narrow.initial_core.%s" % (base_key,), initial_core)
|
||||||
@@ -78,10 +77,9 @@ def report_narrow_times(request, user_profile,
|
|||||||
|
|
||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def report_unnarrow_times(request, user_profile,
|
def report_unnarrow_times(request: HttpRequest, user_profile: UserProfile,
|
||||||
initial_core=REQ(converter=to_non_negative_int),
|
initial_core: int=REQ(converter=to_non_negative_int),
|
||||||
initial_free=REQ(converter=to_non_negative_int)):
|
initial_free: int=REQ(converter=to_non_negative_int)) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, int, int) -> HttpResponse
|
|
||||||
request._log_data["extra"] = "[%sms/%sms]" % (initial_core, initial_free)
|
request._log_data["extra"] = "[%sms/%sms]" % (initial_core, initial_free)
|
||||||
base_key = statsd_key(user_profile.realm.string_id, clean_periods=True)
|
base_key = statsd_key(user_profile.realm.string_id, clean_periods=True)
|
||||||
statsd.timing("unnarrow.initial_core.%s" % (base_key,), initial_core)
|
statsd.timing("unnarrow.initial_core.%s" % (base_key,), initial_core)
|
||||||
@@ -90,11 +88,11 @@ def report_unnarrow_times(request, user_profile,
|
|||||||
|
|
||||||
@human_users_only
|
@human_users_only
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def report_error(request, user_profile, message=REQ(), stacktrace=REQ(),
|
def report_error(request: HttpRequest, user_profile: UserProfile, message: Text=REQ(),
|
||||||
ui_message=REQ(validator=check_bool), user_agent=REQ(),
|
stacktrace: Text=REQ(), ui_message: bool=REQ(validator=check_bool),
|
||||||
href=REQ(), log=REQ(),
|
user_agent: Text=REQ(), href: Text=REQ(), log: Text=REQ(),
|
||||||
more_info=REQ(validator=check_dict([]), default=None)):
|
more_info: Optional[Dict[str, Any]]=REQ(validator=check_dict([]), default=None)
|
||||||
# type: (HttpRequest, UserProfile, Text, Text, bool, Text, Text, Text, Optional[Dict[str, Any]]) -> HttpResponse
|
) -> HttpResponse:
|
||||||
"""Accepts an error report and stores in a queue for processing. The
|
"""Accepts an error report and stores in a queue for processing. The
|
||||||
actual error reports are later handled by do_report_error (below)"""
|
actual error reports are later handled by do_report_error (below)"""
|
||||||
if not settings.BROWSER_ERROR_REPORTING:
|
if not settings.BROWSER_ERROR_REPORTING:
|
||||||
|
|||||||
@@ -18,20 +18,19 @@ from zerver.models import UserProfile, UserGroup, UserGroupMembership
|
|||||||
from zerver.views.streams import compose_views, FuncKwargPair
|
from zerver.views.streams import compose_views, FuncKwargPair
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def add_user_group(request, user_profile,
|
def add_user_group(request: HttpRequest, user_profile: UserProfile,
|
||||||
name=REQ(),
|
name: Text=REQ(),
|
||||||
members=REQ(validator=check_list(check_int), default=[]),
|
members: List[int]=REQ(validator=check_list(check_int), default=[]),
|
||||||
description=REQ()):
|
description: Text=REQ()) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, Text, List[int], Text) -> HttpResponse
|
|
||||||
user_profiles = user_ids_to_users(members, user_profile.realm)
|
user_profiles = user_ids_to_users(members, user_profile.realm)
|
||||||
check_add_user_group(user_profile.realm, name, user_profiles, description)
|
check_add_user_group(user_profile.realm, name, user_profiles, description)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def edit_user_group(request, user_profile,
|
def edit_user_group(request: HttpRequest, user_profile: UserProfile,
|
||||||
user_group_id=REQ(validator=check_int),
|
user_group_id: int=REQ(validator=check_int),
|
||||||
name=REQ(default=""), description=REQ(default="")):
|
name: Text=REQ(default=""), description: Text=REQ(default="")
|
||||||
# type: (HttpRequest, UserProfile, int, Text, Text) -> HttpResponse
|
) -> HttpResponse:
|
||||||
if not (name or description):
|
if not (name or description):
|
||||||
return json_error(_("No new data supplied"))
|
return json_error(_("No new data supplied"))
|
||||||
|
|
||||||
@@ -55,11 +54,11 @@ def delete_user_group(request: HttpRequest, user_profile: UserProfile,
|
|||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def update_user_group_backend(request, user_profile,
|
def update_user_group_backend(request: HttpRequest, user_profile: UserProfile,
|
||||||
user_group_id=REQ(validator=check_int),
|
user_group_id: int=REQ(validator=check_int),
|
||||||
delete=REQ(validator=check_list(check_int), default=[]),
|
delete: List[int]=REQ(validator=check_list(check_int), default=[]),
|
||||||
add=REQ(validator=check_list(check_int), default=[])):
|
add: List[int]=REQ(validator=check_list(check_int), default=[])
|
||||||
# type: (HttpRequest, UserProfile, int, List[int], List[int]) -> HttpResponse
|
) -> HttpResponse:
|
||||||
if not add and not delete:
|
if not add and not delete:
|
||||||
return json_error(_('Nothing to do. Specify at least one of "add" or "delete".'))
|
return json_error(_('Nothing to do. Specify at least one of "add" or "delete".'))
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,8 @@ kerberos_alter_egos = {
|
|||||||
|
|
||||||
@authenticated_json_view
|
@authenticated_json_view
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def webathena_kerberos_login(request, user_profile,
|
def webathena_kerberos_login(request: HttpRequest, user_profile: UserProfile,
|
||||||
cred=REQ(default=None)):
|
cred: Text=REQ(default=None)) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
|
||||||
global kerberos_alter_egos
|
global kerberos_alter_egos
|
||||||
if cred is None:
|
if cred is None:
|
||||||
return json_error(_("Could not find Kerberos credential"))
|
return json_error(_("Could not find Kerberos credential"))
|
||||||
|
|||||||
Reference in New Issue
Block a user