views/archive.py: Make 'StreamDoesNotExist' return a error msg page.

This commit is contained in:
Aditya Bansal 2018-05-02 23:38:10 +05:30 committed by Tim Abbott
parent 583f50179c
commit c38b70566c
2 changed files with 14 additions and 7 deletions

View File

@ -9,7 +9,7 @@ class GlobalPublicStreamTest(ZulipTestCase):
# Here we use a relatively big number as stream id assumming such an id
# won't exist in the test DB.
result = self.client_get("/archive/streams/100000000/topic/TopicGlobal")
self.assert_json_error(result, 'Invalid stream id')
self.assert_in_success_response(["This stream does not exist."], result)
def test_non_web_public_stream(self) -> None:
test_stream = self.make_stream('Test Public Archives')

View File

@ -9,31 +9,38 @@ from zerver.models import Message, UserProfile
from zerver.lib.avatar import get_gravatar_url
from zerver.lib.timestamp import datetime_to_timestamp
from zerver.lib.exceptions import JsonableError
def archive(request: HttpRequest,
stream_id: int,
topic_name: str) -> HttpResponse:
stream = get_stream_by_id(stream_id)
def get_response(rendered_message_list: List[str], is_web_public: bool) -> HttpResponse:
def get_response(rendered_message_list: List[str],
is_web_public: bool,
stream_name: str) -> HttpResponse:
return render(
request,
'zerver/archive/index.html',
context={
'is_web_public': is_web_public,
'message_list': rendered_message_list,
'stream': stream.name,
'stream': stream_name,
'topic': topic_name,
}
)
try:
stream = get_stream_by_id(stream_id)
except JsonableError:
return get_response([], False, '')
if not stream.is_web_public:
return get_response([], False)
return get_response([], False, '')
all_messages = list(Message.objects.select_related(
'sender').filter(recipient__type_id=stream_id, subject=topic_name).order_by('pub_date'))
if not all_messages:
return get_response([], True)
return get_response([], True, stream.name)
rendered_message_list = []
prev_sender = None
@ -60,4 +67,4 @@ def archive(request: HttpRequest,
}
rendered_msg = loader.render_to_string('zerver/archive/single_message.html', context)
rendered_message_list.append(rendered_msg)
return get_response(rendered_message_list, True)
return get_response(rendered_message_list, True, stream.name)