From 1cd017288d13c41eb5580c0f2dac5ccb0a129e4e Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 27 Oct 2017 15:07:31 -0700 Subject: [PATCH] views: Fix imports of REQ/has_request_variables from the wrong place. These were never in zerver/decorator.py, and so it makes sense to import them zerver/lib/request.py, mostly for ease of finding things. --- analytics/views.py | 7 ++++--- docs/writing-views.md | 4 ++-- zerver/tests/test_decorators.py | 3 ++- zerver/views/alert_words.py | 2 +- zerver/views/attachments.py | 2 +- zerver/views/custom_profile_fields.py | 4 ++-- zerver/views/hotspots.py | 3 ++- zerver/views/integrations.py | 2 +- zerver/views/realm_domains.py | 3 ++- zerver/views/realm_filters.py | 3 ++- zerver/views/report.py | 4 ++-- zerver/views/tutorial.py | 2 +- zerver/views/users.py | 5 +++-- zilencer/views.py | 4 ++-- 14 files changed, 27 insertions(+), 21 deletions(-) diff --git a/analytics/views.py b/analytics/views.py index 1f688b25f3..13696b5de9 100644 --- a/analytics/views.py +++ b/analytics/views.py @@ -16,9 +16,10 @@ from analytics.lib.time_utils import time_range from analytics.models import BaseCount, InstallationCount, RealmCount, \ UserCount, StreamCount, last_successful_fill -from zerver.decorator import has_request_variables, REQ, require_server_admin, \ - zulip_login_required, to_non_negative_int, to_utc_datetime -from zerver.lib.request import JsonableError +from zerver.decorator import require_server_admin, zulip_login_required, \ + to_non_negative_int, to_utc_datetime +from zerver.lib.exceptions import JsonableError +from zerver.lib.request import has_request_variables, REQ from zerver.lib.response import json_success from zerver.lib.timestamp import ceiling_to_hour, ceiling_to_day, \ timestamp_to_datetime, convert_to_UTC diff --git a/docs/writing-views.md b/docs/writing-views.md index 90b6ba3f1c..c817093bd2 100644 --- a/docs/writing-views.md +++ b/docs/writing-views.md @@ -150,8 +150,8 @@ arguments for. Here's an example: ``` py -from zerver.decorator import has_request_variables, REQ, JsonableError, \ - require_realm_admin +from zerver.decorator import require_realm_admin +from zerver.lib.request import has_request_variables, REQ @require_realm_admin @has_request_variables diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index e6f8091004..800bcca558 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -13,6 +13,7 @@ from django.conf import settings from zerver.forms import OurAuthenticationForm from zerver.lib.actions import do_deactivate_realm, do_deactivate_user, \ do_reactivate_user, do_reactivate_realm +from zerver.lib.exceptions import JsonableError from zerver.lib.initial_password import initial_password from zerver.lib.test_helpers import ( HostRequestMock, @@ -25,7 +26,7 @@ from zerver.lib.response import json_response from zerver.lib.user_agent import parse_user_agent from zerver.lib.request import \ REQ, has_request_variables, RequestVariableMissingError, \ - RequestVariableConversionError, JsonableError + RequestVariableConversionError from zerver.decorator import ( api_key_only_webhook_view, authenticated_json_post_view, authenticated_json_view, diff --git a/zerver/views/alert_words.py b/zerver/views/alert_words.py index dec5812642..6b9a225df6 100644 --- a/zerver/views/alert_words.py +++ b/zerver/views/alert_words.py @@ -4,7 +4,7 @@ from django.http import HttpResponse, HttpRequest from typing import List, Text from zerver.models import UserProfile -from zerver.decorator import has_request_variables, REQ +from zerver.lib.request import has_request_variables, REQ from zerver.lib.response import json_success from zerver.lib.validator import check_list, check_string diff --git a/zerver/views/attachments.py b/zerver/views/attachments.py index c4f0d598d6..241daed444 100644 --- a/zerver/views/attachments.py +++ b/zerver/views/attachments.py @@ -1,9 +1,9 @@ from django.http import HttpRequest, HttpResponse -from zerver.decorator import REQ from zerver.models import UserProfile from zerver.lib.validator import check_int from zerver.lib.response import json_success +from zerver.lib.request import REQ from zerver.lib.attachments import user_attachments, remove_attachment, \ access_attachment_by_id diff --git a/zerver/views/custom_profile_fields.py b/zerver/views/custom_profile_fields.py index 9a89f1ec43..cdb5d1c8ce 100644 --- a/zerver/views/custom_profile_fields.py +++ b/zerver/views/custom_profile_fields.py @@ -7,8 +7,8 @@ from django.db import IntegrityError, connection from django.http import HttpRequest, HttpResponse from django.utils.translation import ugettext as _ -from zerver.decorator import has_request_variables, REQ, require_realm_admin, \ - human_users_only +from zerver.decorator import require_realm_admin, human_users_only +from zerver.lib.request import has_request_variables, REQ from zerver.lib.actions import (try_add_realm_custom_profile_field, do_remove_realm_custom_profile_field, try_update_realm_custom_profile_field, diff --git a/zerver/views/hotspots.py b/zerver/views/hotspots.py index c4bc191464..7efa693850 100644 --- a/zerver/views/hotspots.py +++ b/zerver/views/hotspots.py @@ -1,9 +1,10 @@ from django.http import HttpRequest, HttpResponse from django.utils.translation import ugettext as _ -from zerver.decorator import has_request_variables, REQ, human_users_only +from zerver.decorator import human_users_only from zerver.lib.actions import do_mark_hotspot_as_read from zerver.lib.hotspots import ALL_HOTSPOTS +from zerver.lib.request import has_request_variables, REQ from zerver.lib.response import json_error, json_success from zerver.lib.validator import check_string from zerver.models import UserProfile diff --git a/zerver/views/integrations.py b/zerver/views/integrations.py index 51e052f906..0ae4854670 100644 --- a/zerver/views/integrations.py +++ b/zerver/views/integrations.py @@ -9,9 +9,9 @@ from django.shortcuts import render import os import ujson -from zerver.decorator import has_request_variables, REQ from zerver.lib import bugdown from zerver.lib.integrations import CATEGORIES, INTEGRATIONS, HUBOT_LOZENGES +from zerver.lib.request import has_request_variables, REQ from zerver.lib.subdomains import get_subdomain from zerver.models import Realm from zerver.templatetags.app_filters import render_markdown_path diff --git a/zerver/views/realm_domains.py b/zerver/views/realm_domains.py index 4d87464075..83157c138d 100644 --- a/zerver/views/realm_domains.py +++ b/zerver/views/realm_domains.py @@ -3,10 +3,11 @@ from django.core.exceptions import ValidationError from django.http import HttpRequest, HttpResponse from django.utils.translation import ugettext as _ -from zerver.decorator import has_request_variables, require_realm_admin, REQ +from zerver.decorator import require_realm_admin from zerver.lib.actions import do_add_realm_domain, do_change_realm_domain, \ do_remove_realm_domain from zerver.lib.domains import validate_domain +from zerver.lib.request import has_request_variables, REQ from zerver.lib.response import json_error, json_success from zerver.lib.validator import check_bool, check_string from zerver.models import RealmDomain, UserProfile, get_realm_domains diff --git a/zerver/views/realm_filters.py b/zerver/views/realm_filters.py index f13d8fef83..e8641679a8 100644 --- a/zerver/views/realm_filters.py +++ b/zerver/views/realm_filters.py @@ -5,8 +5,9 @@ from django.http import HttpRequest, HttpResponse from django.views.decorators.csrf import csrf_exempt from django.utils.translation import ugettext as _ -from zerver.decorator import has_request_variables, REQ, require_realm_admin +from zerver.decorator import require_realm_admin from zerver.lib.actions import do_add_realm_filter, do_remove_realm_filter +from zerver.lib.request import has_request_variables, REQ from zerver.lib.response import json_success, json_error from zerver.lib.rest import rest_dispatch as _rest_dispatch from zerver.lib.validator import check_string diff --git a/zerver/views/report.py b/zerver/views/report.py index 849c784cbe..9c24c372ad 100644 --- a/zerver/views/report.py +++ b/zerver/views/report.py @@ -5,9 +5,9 @@ from typing import Any, Dict, Optional, Text from django.conf import settings from django.http import HttpRequest, HttpResponse -from zerver.decorator import authenticated_json_post_view, has_request_variables, REQ, \ - to_non_negative_int +from zerver.decorator import authenticated_json_post_view, to_non_negative_int from zerver.lib.bugdown import privacy_clean_markdown +from zerver.lib.request import has_request_variables, REQ from zerver.lib.response import json_success from zerver.lib.queue import queue_json_publish from zerver.lib.unminify import SourceMap diff --git a/zerver/views/tutorial.py b/zerver/views/tutorial.py index 8cd25e7306..ff2cd0fd3c 100644 --- a/zerver/views/tutorial.py +++ b/zerver/views/tutorial.py @@ -1,7 +1,7 @@ from django.http import HttpRequest, HttpResponse -from zerver.decorator import has_request_variables, REQ +from zerver.lib.request import has_request_variables, REQ from zerver.lib.response import json_success from zerver.lib.validator import check_string from zerver.models import UserProfile diff --git a/zerver/views/users.py b/zerver/views/users.py index 85340a4ea3..a175be5bf9 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -10,15 +10,16 @@ from django.shortcuts import redirect, render from django.conf import settings from six.moves import map -from zerver.decorator import has_request_variables, REQ, JsonableError, \ - require_realm_admin, zulip_login_required +from zerver.decorator import require_realm_admin, zulip_login_required from zerver.forms import CreateUserForm from zerver.lib.actions import do_change_avatar_fields, do_change_bot_owner, \ do_change_is_admin, do_change_default_all_public_streams, \ do_change_default_events_register_stream, do_change_default_sending_stream, \ do_create_user, do_deactivate_user, do_reactivate_user, do_regenerate_api_key from zerver.lib.avatar import avatar_url, get_gravatar_url, get_avatar_field +from zerver.lib.exceptions import JsonableError from zerver.lib.integrations import EMBEDDED_BOTS +from zerver.lib.request import has_request_variables, REQ from zerver.lib.response import json_error, json_success from zerver.lib.streams import access_stream_by_name from zerver.lib.upload import upload_avatar_image diff --git a/zilencer/views.py b/zilencer/views.py index 1bd354d624..ed80b7f93c 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -5,11 +5,11 @@ from django.http import HttpResponse, HttpRequest from zilencer.models import RemotePushDeviceToken, RemoteZulipServer -from zerver.decorator import has_request_variables, REQ +from zerver.lib.exceptions import JsonableError from zerver.lib.push_notifications import send_android_push_notification, \ send_apple_push_notification -from zerver.lib.request import JsonableError from zerver.lib.response import json_error, json_success +from zerver.lib.request import has_request_variables, REQ from zerver.lib.validator import check_dict, check_int from zerver.models import UserProfile, PushDeviceToken, Realm from zerver.views.push_notifications import validate_token