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